我正在使用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");
}
}
答案 0 :(得分: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
}
}