I am trying to merge multiple test cases from various classes into one extent report. All test cases are running successfully but it is not adding those test cases into my extent report. The version of my Extent Report is 2.41.2.It is showing the previous extent report only, No new report showing all the test cases is generated. I am successfully generating a single class report but not able to generate multiple classes extent report. Here is my code:
// First I have created a base class for Extent Report:
public static ExtentHtmlReporter htmlReporter;
public static ExtentReports extent;
public static ExtentTest test;
#BeforeSuite
public void setUp()
{
htmlReporter = new ExtentHtmlReporter(System.getProperty("user.dir") +"/test-output/MyOwnReport.html");
extent = new ExtentReports();
extent.attachReporter(htmlReporter);
extent.setSystemInfo("OS", "Mac Sierra");
extent.setSystemInfo("Host Name", "Krishna");
extent.setSystemInfo("Environment", "QA");
extent.setSystemInfo("User Name", "Krishna Sakinala");
htmlReporter.config().setChartVisibilityOnOpen(true);
htmlReporter.config().setDocumentTitle("AutomationTesting.in Demo Report");
htmlReporter.config().setReportName("My Own Report");
htmlReporter.config().setTestViewChartLocation(ChartLocation.TOP);
htmlReporter.config().setTheme(Theme.DARK);
}
#AfterSuite
public void tearDown()
{
extent.flush();
}
}
// Now Logintestcase Extending Base Extent report class:
public class LoginTestCase extends ExtentReportBaseClass {
static WebDriver driver;
Homepage login = new Homepage();
UtilityMethods util = new UtilityMethods();
String locUsernameElem;
String locPasswordelem;
String Sign_in;
String insertEmail;
String insertFirstName;
String createAccountButton;
// #Parameters("browser")
#BeforeClass
public void launchBrowser() {
driver = UtilityMethods.openBrowser(ConstantsValues.BROWSER_NAME);
UtilityMethods.launchWebsite(Utility.ConstantsValues.URL);
driver.manage().window().maximize();
}
#Test
public void registration() throws InterruptedException {
test = extent.createTest("registration", "This will check status for registration of the user.");
Sign_in = Utility.ConstantsValues.SIGN_IN;
insertEmail = Utility.ConstantsValues.EMAIL_ADDRESS;
createAccountButton = Utility.ConstantsValues.CREATE_ACOUNT;
// insertFirstName=ConstantsValues.USER_FIRSTNAME;
util.clickElement(Sign_in);
Thread.sleep(2000);
// driver.findElement(By.xpath("//input[#id='email_create']")).sendKeys("vivekkumar9652gmail.com");
util.sendData(insertEmail);
util.clickElement(ConstantsValues.CREATE_ACCOUNT);
util.clickElement(ConstantsValues.USER_TITLE);
util.sendDataById("customer_firstname", ConstantsValues.FIRST_NAME);
util.sendDataById("customer_lastname", ConstantsValues.LAST_NAME);
// util.sendData(ConstantsValues.LAST_NAME);
util.sendData(ConstantsValues.USER_PASSWORD);
util.clickElement(ConstantsValues.USER_NEWSLETTER);
Select day = new Select(driver.findElement(By.id("days")));
day.selectByValue("1");
Select month = new Select(driver.findElement(By.id("months")));
month.selectByValue("2");
Select year = new Select(driver.findElement(By.id("years")));
year.selectByValue("2014");
util.sendData(ConstantsValues.USER_COMPANY);
util.sendData(ConstantsValues.USER_STATE);
util.sendData(ConstantsValues.USER_ADDRESS1);
util.sendData(ConstantsValues.USER_MOBILENUMBER);
util.sendData(ConstantsValues.USER_ZIPCODE);
util.sendData(ConstantsValues.USER_ALIAS);
util.sendData(ConstantsValues.USER_CITY);
util.clickElement(ConstantsValues.SUBMITACCOUNT);
util.clickElement(ConstantsValues.USER_SIGN_OUT);
test.log(Status.PASS, MarkupHelper.createLabel("PASS", ExtentColor.GREEN));
}
#Test
public void userLogin() {
test = extent.createTest("userLogin", "This will check status for login of the user");
// util.clickElement(ConstantsValues.SIGN_IN);
util.sendData(ConstantsValues.LOGIN_USERNAME);
util.sendData(ConstantsValues.LOGIN_PASSWORD);
util.clickElement(ConstantsValues.USER_SIGNIN_Account);
//Assert.assertNotEquals("Krishna", "Krishna");
test.log(Status.PASS, MarkupHelper.createLabel("PASS", ExtentColor.RED));
}
}
//Now another class Extending BaseExtentReport Class:
public class PurchaseItemTestCase extends ExtentReportBaseClass {
WebDriver driver;
UtilityMethods util = new UtilityMethods();
// #Parameters("browser")
#BeforeClass
public void launchBrowser() throws InterruptedException {
System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe");
driver = new ChromeDriver();
driver = UtilityMethods.openBrowser(ConstantsValues.BROWSER_NAME);
UtilityMethods.launchWebsite(Utility.ConstantsValues.URL);
driver.manage().window().maximize();
}
#Test
public void chkPurchaseItem() throws InterruptedException {
test = extent.createTest("chkPurchaseItem", "This will check status for purchasing an item.");
driver.findElement(By.xpath("//img[#title='Faded Short Sleeve T-shirts']")).click();
driver.switchTo().defaultContent();
driver.switchTo().frame(driver.findElement(By.xpath("//iframe[contains(#id,'fancy')]")));
System.out.println("after frame");
Thread.sleep(4000);
driver.findElement(By.xpath("//button[#type='submit']//span[contains(.,'Add')]")).click();
Set handles = driver.getWindowHandles();
System.out.println(handles);
// Pass a window handle to the other window
for (String handle1 : driver.getWindowHandles()) {
System.out.println(handle1);
driver.switchTo().window(handle1);
Thread.sleep(3000);
driver.findElement(By.xpath("//a[#title='Proceed to checkout']//span[contains(.,'Proceed')]")).click();
Thread.sleep(3000);
driver.findElement(By.xpath(
"//a[#class='button btn btn-default standard-checkout button-medium']//span[contains(.,'Proceed')]//i[#class='icon-chevron-right right']"))
.click();
driver.findElement(By.id("email")).sendKeys("vivekkumar009#gmail.com");
driver.findElement(By.id("passwd")).sendKeys("vivek123");
Thread.sleep(3000);
// UtilityMethods.getdriver().findElement(By.id("SubmitLogin"));
driver.findElement(By.id("SubmitLogin")).click();
driver.findElement(By.name("processAddress")).click();
driver.findElement(By.id("cgv")).click();
driver.findElement(By.xpath("//button[#name=\"processCarrier\"]")).click();
driver.findElement(By.className("cheque")).click();
driver.findElement(By.xpath("//span[contains(text(),'I confirm my order')]")).click();
test.log(Status.PASS, MarkupHelper.createLabel("PASS", ExtentColor.GREEN));
}
}
}
Make your extent test as thread local variable.
Example:
Public ThreadLocal<ExtentTest> test;
Related
I have 3 pages to navigate page1, page2 and page3. I wanted to capture 3 separate HAR file. i tried the below code when it visit page1 its extracted page one performance data in har file and when i visited page2 its extracted page1 and page2 data but I wanted a separate one please help me to achieve this thanks.
Proxy and driver initialization class file
public class InitializeBrowserDriver {
public WebDriver driver;
public Properties importprop;
public BrowserMobProxy myproxy;
public Har har;
public WebDriver initializer() throws IOException {
importprop=new Properties();
FileInputStream filepath=new
FileInputStream(System.getProperty("user.dir")+"\\src\\main\\java\\datafile.properties");
importprop.load(filepath);
myproxy=new BrowserMobProxyServer();
myproxy.start(0);
Proxy seleniumproxy=new Proxy();
seleniumproxy.setHttpProxy("localhost:" +myproxy.getPort());
seleniumproxy.setSslProxy("localhost:" +myproxy.getPort());
DesiredCapabilities capability=new DesiredCapabilities();
capability.setCapability(CapabilityType.PROXY, seleniumproxy);
capability.acceptInsecureCerts();
capability.setCapability(CapabilityType.ACCEPT_INSECURE_CERTS, true);
EnumSet <CaptureType> capturenetworklog=CaptureType.getAllContentCaptureTypes();
capturenetworklog.addAll(CaptureType.getHeaderCaptureTypes());
capturenetworklog.addAll(CaptureType.getRequestCaptureTypes());
capturenetworklog.addAll(CaptureType.getResponseCaptureTypes());
capturenetworklog.addAll(CaptureType.getCookieCaptureTypes());
myproxy.setHarCaptureTypes(capturenetworklog);
myproxy.newHar("newhar");
WebDriverManager.chromedriver().setup();
ChromeOptions options = new ChromeOptions();
options.merge(capability);
driver=new ChromeDriver(options);
har=myproxy.getHar();
driver.manage().timeouts().implicitlyWait(4, TimeUnit.SECONDS);
return driver;
}
/*public String urlAccess()
{
String url=importprop.getProperty("baseurl");
return url;
}*/
}
Navigating to different pages using by extending above class:
public class NavigationToPage extends InitializeBrowserDriver {
private void fileWriter() throws IOException {
String title=driver.getTitle();
har=myproxy.getHar();
File myharfile=new File(System.getProperty("user.dir")+"/harfiles/"+title+".har");
har.writeTo(myharfile);
System.out.println(title+ "HAR file has been created successfully");
}
#BeforeClass
public void beforeMethods() throws IOException {
driver=initializer();
driver.get(importprop.getProperty("baseurl"));
driver.manage().window().maximize();
fileWriter();
}
#Test
public void toContactUs() throws IOException {
driver.findElement(By.xpath(importprop.getProperty("toContactUs"))).click();
fileWriter();
}
#Test
public void toSolutions() throws IOException {
WebDriverWait wait=new WebDriverWait(driver, 3);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(importprop.getProperty("toSolutions"))));
this.driver.findElement(By.xpath(importprop.getProperty("toSolutions"))).click();
fileWriter();
}
#AfterClass
public void quitBrowser() throws InterruptedException {
Thread.sleep(1000);
driver.quit();
myproxy.stop();
}
}
Try this solution: https://stackoverflow.com/a/57045946/5966983
For each Test / Navigation (In your case - after performing click ) create new HAR.
myproxy.newHar("page2");
myproxy.newHar("page3");
public class ExtentReports_Basecode {
static Random rand = new Random();
static long drand = (long)(rand.nextDouble()*10000000000L);
public WebDriver dr;
public static ExtentHtmlReporter htmlReporter;
public static ExtentReports extent;
public static ExtentTest test;
private static String filePath = "D://" + drand + "ExtentReports_Bindu.html";
#BeforeSuite
public void setup() {
htmlReporter = new ExtentHtmlReporter(filePath);
extent = new ExtentReports();
extent.attachReporter(htmlReporter);
extent.setSystemInfo("OS", "Windows10");
extent.setSystemInfo("Host Name", "Bindu");
extent.setSystemInfo("Environment", "rose");
extent.setSystemInfo("User Name", "1234_ws");
//htmlReporter.config().setChartVisibilityOnOpen(true);
htmlReporter.config().setDocumentTitle("AutomationTesting.in Demo Report");
htmlReporter.config().setReportName("Favourite Automation Report");
htmlReporter.config().setTheme(Theme.DARK);
}
#BeforeMethod
public void startTest(Method m)
{
test = extent.createTest(m.getName(),"This is the description of Test" + m.getName());
}
#AfterMethod
public static void getResult(ITestResult result){
if(result.getStatus()== ITestResult.FAILURE){
test.log(Status.FAIL,MarkupHelper.createLabel(result.getName() + "Test case FAILED due to below issues:",ExtentColor.RED));
test.fail(result.getThrowable());
}
else if(result.getStatus()== ITestResult.SUCCESS){
test.log(Status.PASS,MarkupHelper.createLabel(result.getName() + "Test Case PASSED",ExtentColor.GREEN));
}
else{
test.log(Status.SKIP,MarkupHelper.createLabel(result.getName() + "Test Case Skipped",ExtentColor.YELLOW));
test.skip(result.getThrowable());
}
}
#AfterSuite
public void teardown(){
extent.flush();
}
}
Script1:
public class sc1 extends ExtentReports_Basecode{
public WebDriver dr;
public Report report = null;
String inputSheetPath ="TestData/InputData/DataSheet.xls" ;
#BeforeTest
public void launchBrowser() {
System.out.println("launching Chrome browser");
dr = Driver.getChromeDriver();
}
#Test
private void sc1_95_Fav(){
System.out.println("sc1"); }
}
}
Script2:
public class sc2 extends ExtentReports_Basecode{
public WebDriver dr;
public Report report = null;
String inputSheetPath ="TestData/InputData/DataSheet.xls" ;
#BeforeTest
public void launchBrowser() {
System.out.println("launching Chrome browser");
dr = Driver.getChromeDriver();
}
#Test
private void sc2_83_Fav() {
}
}
}
TestNG XML:
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<!--<suite name="Parallel test Suite">-->
<suite name="My suite" parallel="classes" thread-count="10">
<test name="name">
<classes>
<!-- To Add Any Class start -->
<class name="OpenUI.Favourites.sc1"/>
<class name="OpenUI.Favourites.sc2"/>
<!--To Add Any Class End -->
</classes>
</test>
</suite>
in the extent report I m getting results in 2nd test case.. can someone pls suggest where am I missed out and how to see the output properly using extent report parallel testing using TestNG.
As shown in the image the results output of first Test is shown in the second Test, if any thing get failed the Failed output shown in Last Test not in actual failed Test
PS: its working fine when I run sequentially one by one using testNG.
Follow this pattern,Hope your problem will be solved
WebDriver driver;
ExtentHtmlReporter htmlReporter;
ExtentReports extent;
ExtentTest test;
#BeforeTest
public void setUp() {
// where we need to generate the report
htmlReporter = new ExtentHtmlReporter("Your report Path");
extent = new ExtentReports();
extent.attachReporter(htmlReporter);
// Set our document title, theme etc..
htmlReporter.config().setDocumentTitle("Rehomes");
htmlReporter.config().setReportName("Rehomes Production Testing");
htmlReporter.config().setTestViewChartLocation(ChartLocation.TOP);
htmlReporter.config().setTheme(Theme.DARK);
}
}
#Test
public void HomepageLogo() throws Exception {
test = extent.createTest("rentalhomesHomePage");
//Your Test
}
#AfterMethod
public void setTestResult(ITestResult result) throws IOException {
if (result.getStatus() == ITestResult.FAILURE) {
test.log(Status.FAIL, result.getName());
test.log(Status.FAIL,result.getThrowable());
//test.fail("Screen Shot : " + test.addScreenCaptureFromPath(screenShot));
} else if (result.getStatus() == ITestResult.SUCCESS) {
test.log(Status.PASS, result.getName());
//test.pass("Screen Shot : " + test.addScreenCaptureFromPath(screenShot));
} else if (result.getStatus() == ITestResult.SKIP) {
test.skip("Test Case : " + result.getName() + " has been skipped");
}
extent.flush();
driver.close();
}
}
Thanks for the reply, but unfortunately the above one dint work and is giving only one test generated as a report if tried in that way. can u suggest any other way to overcome this issue.?
I am using an excel sheet :
Excel snapshot
Need to iterate over the rows, one after another after taking the values from getCelldata(rownum, colnum) and validating the same from the same row.
But here I need to iterate only the row number.
Code sample:
#Test (priority=1, description = "Login Functionality")
public void login() {
driver.get(data.getProperty("base.url"));
obj_login = new login (driver);
ExcelBase.setExcelFileSheet("Capacitor_unit");
obj_login.enter_username(ExcelBase.getCellData(3,1));
obj_login.enter_password(ExcelBase.getCellData(3,2));
obj_login.select_login();
}
The next one should be (ExcelBase.getCellData(4,1)) and then (5,1) till data ends.
Full class code overview:
public class TC01_newDesign extends TestBase{
login obj_login;
createNewDesign obj_CreateNewDesign;
saveDesign obj_SaveDesign;
capacitorUnit obj_capacitorUnit;
logout obj_logout;
#Test (priority=1, description = "Login Functionality")
public void login() {
driver.get(data.getProperty("base.url"));
obj_login = new login (driver);
ExcelBase.setExcelFileSheet("Capacitor_unit");
..
obj_login.select_login();
}
#Test (priority=2, description = "Create new Design")
public void createNewDesign() {
log.info("Create New Design");
obj_CreateNewDesign = new createNewDesign (driver);
..
}
#Test (priority=3, description = "Capacitor Unit Design")
public void capacitorUnit() {
log.info("Capacitor Unit Design");
obj_capacitorUnit = new capacitorUnit (driver);
..
log.info("Assert actual searched string with expected string from Excel.");
assertStrings(obj_capacitorUnit.get_unitVoltage().replaceAll("\\s+",""),ExcelBase.getCellData(3,50));
..
}
#Test (priority=4, description = "Logout app")
public void logout() {
log.info("Logout from CapDes");
obj_logout = new logout (driver);
}
}
I am trying to run different classes parallarly though testNG to generate one single extent report for all classes. Also I am trying to generate logs for each classes which will be shown in the extent report. However when the extent report is generated I can see that the logs for a test case of one class is shown in the test case of other class. How to resolve this issue? Below is my code:
//// This is my base class for extent report:
#BeforeSuite
public static void setUp()
{
htmlReporter = new ExtentHtmlReporter(System.getProperty("user.dir") +"/test-output/MyOwnReport.html");
report = new ExtentReports();
report.attachReporter(htmlReporter);
report.setSystemInfo("OS", "Mac Sierra");
report.setSystemInfo("Host Name", "Testing Xpert");
report.setSystemInfo("Environment", "QA");
report.setSystemInfo("User Name", "Vivek");
htmlReporter.config().setChartVisibilityOnOpen(true);
htmlReporter.config().setDocumentTitle("AutomationTesting.in Demo Report");
htmlReporter.config().setReportName("My Own Report");
htmlReporter.config().setTestViewChartLocation(ChartLocation.TOP);
htmlReporter.config().setTheme(Theme.DARK);
}
//Creating a method getScreenshot and passing two parameters
//driver and screenshotName
public static String getScreenshot(WebDriver driver, String screenshotName) throws Exception {
//below line is just to append the date format with the screenshot name to avoid duplicate names
String dateName = new SimpleDateFormat("yyyyMMddhhmmss").format(new Date());
TakesScreenshot ts = (TakesScreenshot) driver;
File source = ts.getScreenshotAs(OutputType.FILE);
String destination = System.getProperty("user.dir") + "/test-output/"+screenshotName+dateName+".png";
File finalDestination = new File(destination);
FileHandler.copy(source, finalDestination);
//FileUtils.copyFile(source, finalDestination);
return destination;
}
#AfterMethod
public void getResult(ITestResult result) throws Exception
{
if(result.getStatus() == ITestResult.FAILURE)
{
test.log(Status.FAIL, "Test Case Failed is "+result.getName());
// test.log(Status.FAIL, "Test Case Failed is "+result.getThrowable());
String screenshotPath = ExtentReportBaseClass.getScreenshot(UtilityMethods.getdriver(), result.getName());
test.log(Status.FAIL, (Markup) test.addScreenCaptureFromPath(screenshotPath));
//test.log(Status.FAIL, MarkupHelper.createLabel(result.getName()+" Test case FAILED due to below issues:",test.addScreenCaptureFromPath(screenshotPath)));
test.fail(result.getThrowable());
}
else if(result.getStatus() == ITestResult.SUCCESS)
{
test.log(Status.PASS, "Test Case Passed is "+result.getName());
}
else
{
test.log(Status.SKIP, MarkupHelper.createLabel(result.getName()+" Test Case SKIPPED", ExtentColor.ORANGE));
test.skip(result.getThrowable());
}
}
#AfterSuite
public void tearDown()
{
report.flush();
}
There are my two classes which i am running. Method for generating logs are defined in the class.(test.log(test.getStatus(), "This will add item to the cart");)
public class PurchaseItemTestCase extends ExtentReportBaseClass{
#BeforeClass
public void launchBrowser() throws InterruptedException {
//System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe");
//driver = new ChromeDriver();
driver = util.openBrowser(ConstantsValues.BROWSER_NAME);
util.launchWebsite();
driver.manage().window().maximize();
//report = ExtentReportBaseClass.setUp();
}
#Test
public void chkPurchaseItem() throws InterruptedException {
//ExtentTest test;
test = report.createTest("chkPurchaseItem", "This will check status for purchasing an item.");
driver.findElement(By.xpath("//img[#title='Faded Short Sleeve T-shirts']")).click();
driver.switchTo().defaultContent();
driver.switchTo().frame(driver.findElement(By.xpath("//iframe[contains(#id,'fancy')]")));
System.out.println("after frame");
Thread.sleep(4000);
test.log(test.getStatus(), "This will add item to the cart");
driver.findElement(By.xpath("//button[#type='submit']//span[contains(.,'Add')]")).click();
Set handles = driver.getWindowHandles();
System.out.println(handles);
// Pass a window handle to the other window
for (String handle1 : driver.getWindowHandles()) {
System.out.println(handle1);
driver.switchTo().window(handle1);
Thread.sleep(3000);
driver.findElement(By.xpath("//a[#title='Proceed to checkout']//span[contains(.,'Proceed')]")).click();
Thread.sleep(3000);
driver.findElement(By.xpath(
"//a[#class='button btn btn-default standard-checkout button-medium']//span[contains(.,'Proceed')]//i[#class='icon-chevron-right right']"))
.click();
test.log(test.getStatus(), "We will login to the account");
driver.findElement(By.id("email")).sendKeys("vivekkumar009#gmail.com");
driver.findElement(By.id("passwd")).sendKeys("vivek123");
Thread.sleep(3000);
// UtilityMethods.getdriver().findElement(By.id("SubmitLogin"));
driver.findElement(By.id("SubmitLogin")).click();
test.log(test.getStatus(), "User will add address for shipment");
driver.findElement(By.name("processAddress")).click();
test.log(test.getStatus(), "User will agree to terms and condition ");
driver.findElement(By.id("cgv")).click();
driver.findElement(By.xpath("//button[#name=\"processCarrier\"]")).click();
driver.findElement(By.className("cheque")).click();
test.log(test.getStatus(), "User confirms order");
driver.findElement(By.xpath("//span[contains(text(),'I confirm my order')]")).click();
boolean chkElement = util.getdriver().findElement(By.className("home")).isDisplayed();
System.out.println(chkElement);
Assert.assertTrue(chkElement);
}
this is the 2nd class:
public class CategoryWisePurchase extends ExtentReportBaseClass {
#BeforeClass
public void launchApplicationBrowser() {
util.openBrowser(ConstantsValues.BROWSER_NAME);
util.launchWebsite();
}
#Test
public void CategoryWiseShopping() throws InterruptedException {
test = report.createTest("Category Wise Shopping", "This will check if the user is able to shop different products by selecting its category");
// Actions actions = new Actions(UtilityMethods.getdriver());
Actions action = new Actions(UtilityMethods.getdriver());
test.log(test.getStatus(), "User will select the category of a particular item");
WebElement mainMenu = UtilityMethods.getdriver().findElement(By.xpath("//a[#title='Women']"));
WebElement subMenu = UtilityMethods.getdriver().findElement(By.xpath("//a[#title='T-shirts']"));
action.moveToElement(mainMenu).build().perform();
Thread.sleep(2000);
action.moveToElement(subMenu).click().build().perform();
test.log(test.getStatus(), "Various products will be shown to the user of the selected category");
//reportLog("Various products will be shown to the user of the selected category");
boolean chkElement = UtilityMethods.getdriver().findElement(By.xpath("//form[#method='post']")).isDisplayed();
System.out.println(chkElement);
Assert.assertTrue(chkElement);
}
}
That will happen if the test is in your Base class. In parallel, the test will be used by all classes that inherit your Base class. Better to use a threadlocal here or an implementation similar to:
https://github.com/anshooarora/extentreports-java/blob/master/src/test/java/com/aventstack/extentreports/common/ExtentTestManager.java
Also, is you see the examples section of the docs, you already have a barebones ExtentTestNGReportBuilder example which you can use without creating any custom code like here.
I have a class with dependent methods using the TestNG annotation
dependsOnMethods
The test runs fine 100% of the time if I simply run it as a TestNG Test from the package.
When I include the test in a TestNG Suite, the methods run out of order. Yes, I am using:
<test name="Test" preserve-order="true">
in my .xml file.
Every other test in the suite respects the method ordering and run without issue. Is there any known information on why this might be occurring?
Code for the test case:
#Test(groups={ "Administration"})
public class RoleCrudTest extends AbstractIntegrationTest
{
protected static SeleniumActionHelper action;
#Test
public void inactiveRole() throws Exception
{
SeleniumHelper helper = new SeleniumHelper();
action = new SeleniumActionHelper(driver);
helper.login();
String roleUrl = navigateToUrl("role/roles.xhtml");
driver.get(roleUrl);
assertEquals("Role:", findElementBySelector("span.portletButtonHeader").getText());
WebElement roleName = findElementById("roleName");
assertFalse(roleName.isEnabled());
WebElement deptId = findElementById("deptid");
assertFalse(deptId.isEnabled());
}
#Test(dependsOnMethods = "inactiveRole")
public void createRole() throws Exception
{
WebElement addButton = findElementById("add");
addButton.click();
waitUntilAjaxRequestCompletes();
WebElement roleName = findElementById("roleName");
roleName.click();
roleName.sendKeys("AAAAAAAA");
WebElement deptId = findElementByXpath("(//button[#type='button'])[3]");
deptId.click();
WebElement dept = findElementByXpath("//div[#id='department_panel']/ul/li[2]");
dept.click();
WebElement checkbox = findElementByXpath("//li[#id='privileges:1']/div/span/div/div");
checkbox.click();
Thread.sleep(1000);
WebElement save = findElementById("save");
save.click();
assertEquals("Role saved successfully", findElementBySelector("div.ui-growl-message > p").getText());
}
#Test(dependsOnMethods = "createRole")
public void editUndo() throws Exception
{
Thread.sleep(1000);
WebElement tableSort = findElementByXpath("//th[#id='tableSection:rolesListWrapped:j_idt85']/div/span[2]");
tableSort.click();
Thread.sleep(1000);
WebElement createdRole = findElementByXpath("//tbody[#id='tableSection:rolesListWrapped_data']/tr[1]/td/div");
createdRole.click();
Thread.sleep(1000);
WebElement roleName = findElementById("roleName");
roleName.click();
roleName.clear();
roleName.sendKeys("edited");
WebElement deptId = findElementByXpath("(//button[#type='button'])[3]");
deptId.click();
WebElement dept = findElementByXpath("//div[#id='department_panel']/ul/li[3]");
dept.click();
WebElement checkbox = findElementByXpath("//li[#id='privileges:1']/div/span/div/div/span");
checkbox.click();
WebElement checkbox2 = findElementByXpath("//li[#id='privileges:0']/div/span/div/div");
checkbox2.click();
Thread.sleep(1000);
WebElement undo = findElementById("cancel");
undo.click();
String text = findElementById("roleName").getAttribute("value");
String oldtext = "AAAAAAAA";
assertTrue(text.equals(oldtext));
}
#Test(dependsOnMethods = "editUndo")
public void editRole() throws Exception
{
Thread.sleep(1000);
WebElement createdRole = findElementByXpath("//tbody[#id='tableSection:rolesListWrapped_data']/tr[1]/td/div");
createdRole.click();
Thread.sleep(1000);
WebElement roleName = findElementById("roleName");
roleName.click();
roleName.clear();
roleName.sendKeys("AAAAAAAAedited");
WebElement deptId = findElementByXpath("(//button[#type='button'])[3]");
deptId.click();
WebElement dept = findElementByXpath("//div[#id='department_panel']/ul/li[3]");
dept.click();
WebElement checkbox = findElementByXpath("//li[#id='privileges:1']/div/span/div/div/span");
checkbox.click();
WebElement checkbox2 = findElementByXpath("//li[#id='privileges:0']/div/span/div/div");
checkbox2.click();
Thread.sleep(1000);
WebElement save = findElementById("save");
save.click();
assertEquals("Role saved successfully", findElementBySelector("div.ui-growl-message > p").getText());
}
#Test(dependsOnMethods = "editRole")
public void deleteRole() throws Exception
{
Thread.sleep(1000);
WebElement deleteButton = findElementById("tableSection:delete");
deleteButton.click();
WebElement deleteConfirm = findElementById("confirmDelete:yes");
deleteConfirm.click();
Thread.sleep(500);
assertEquals("Role deleted successfully", findElementBySelector("div.ui-growl-message > p").getText());
waitUntilAjaxRequestCompletes();
}
}
dependsOnMethods is what you want, not preserve-order (actually, dependsOnGroups is recommended over dependsOnMethods, but both will work).
If you have a small test case showing the problem, please post it