提问者:小点点

并非套件中的所有测试都在TestNG中执行


我正在使用eclipse执行套件,但只有第三个测试用例(Test3)无法执行。(Test2)执行后,它将跳转到(Test4)而不是(Test3)。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="SeleniumTestSuite" verbose="1">
    <test name="Test1">
      <classes>
        <class name="sel1318_usercreation_author.UserCreation"></class>
      </classes>
    </test>
    <test name="Test2">
      <classes>
        <class name="sel1319_userprofileupdate_author.UserProfileUpdate"></class>
      </classes>
    </test>
    <test name="Test3">
      <classes>
        <class name="sel1320_customercreation_corporate.CustomerCreation"></class>
      </classes>
    </test>
    <test name="Test4">
      <classes>
        <class name="sel1321_customerdeletion_corporate.CustomerDeletion"></class>
      </classes>
    </test>
    <test name="Test5">
      <classes>
        <class name="sel1322_userinactive_author.UserInactive"></class>
      </classes>
    </test>
    <test name="Test6">
      <classes>
        <class name="sel1323_userdeletion_author.UserDeletion"></class>
      </classes>
    </test>
</suite>

这是Test4的代码。基本上这个测试是删除客户,因此Test3将创建客户。此外,用户密码将在Test3中更改。所以当TestNG跳转到Test4时,用户无法登录,因为密码应该不同。

package sel1321_customerdeletion_corporate;

import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.Assert;
import org.testng.annotations.Test;
@Test
public class CustomerDeletion {
{
		
	    System.setProperty("webdriver.gecko.driver","C:\\selenium\\geckodriver-v0.23.0-win64\\geckodriver.exe");
		
		WebDriver driver = new FirefoxDriver();
		
		driver.get("");	
		
		driver.manage().window().maximize(); 
		driver.switchTo().frame("containerFrame");
		
		//Login Author
		WebDriverWait wait = new WebDriverWait(driver, 20);
		wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//input[@name='userName']")));
		driver.findElement(By.xpath("//input[@name='userName']")).click();
		driver.findElement(By.xpath("//input[@name='userName']")).sendKeys("sele1");
		driver.findElement(By.xpath("//input[@name='password']")).click();
		driver.findElement(By.xpath("//input[@name='password']")).sendKeys("password1");
		driver.findElement(By.name("submitLogin")).click();
		
		//Delete Customer
		driver.findElement(By.id("menu5")).click();
		Actions hover = new Actions(driver);
		WebElement element = driver.findElement(By.xpath("//div[@id='hel19']/div"));
		hover.moveToElement(element).build().perform();
		driver.findElement(By.id("el2")).click();
		driver.findElement(By.name("customerName")).sendKeys("Selenium_Cust39");
		driver.findElement(By.id("AddNew24")).click();
		driver.findElement(By.linkText("SELENIUM_CUST39")).click();
		driver.findElement(By.linkText("Delete")).click();
		driver.findElement(By.id("AddNew24")).click();
		Alert alt = driver.switchTo().alert();
		alt.accept();
		driver.findElement(By.linkText("Logout")).click();
		driver.close();
		Assert.assertEquals("Pass", "Pass");
		
   }

}

共1个答案

匿名用户

在您的类CustomerDeletion中,整个代码都写在一个匿名块中,因此当您尝试通过testng. xml运行它时,它不会被执行。

您应该将代码放在类内部的方法中,然后代码将通过testng. xml执行

举个例子:

@Test
public class CustomerDeletion {
    //Make a method inside which you will be writing the whole code
   public void customerDeletionMethod(){
    //Copy Paste your code here
   }
}