Reputation: 79
I'm using eclipse to execute the suite but only the third test case (Test3) cannot be executed. After (Test2) executed, it will jump to the (Test4) and not (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>
This is the code for Test4. Basically this test is to delete the customer thus, Test3 will create the customer. Besides, the user password will be changed in Test3. So when TestNG jump to the Test4, the user cannot login because the password should be different.
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");
}
}
Upvotes: 0
Views: 86
Reputation: 4507
In your class CustomerDeletion
whole code is written in an anonymous block, because of which it is not getting executed when you are trying to run it through your testng.xml.
You should put the code in a method inside the class and then the code will be executed through the testng.xml
For Example:
@Test
public class CustomerDeletion {
//Make a method inside which you will be writing the whole code
public void customerDeletionMethod(){
//Copy Paste your code here
}
}
Upvotes: 1