Reputation: 435
I have two test cases:
FYI - IF I RUN THESE TWO TEST CASES INDIVIDUALLY, BOTH WORK.
java.lang.AssertionError: java.lang.AssertionError: expected [false] but found [true]
These are my two test cases:
1
// locate an element field to get default impressions
WebElement defaultImpressions = driver.findElement(By
.name("campaignImpScheduled"));
defaultImpressions.clear();
// send non-numeric characters
defaultImpressions.sendKeys(scheduledImpNumbersNonNumericCharacters);
// verify that the Update button is clicked
verifyDisplay("Update Button ===> is clicked", By.id("updateCamSchBtn"));
// click the Update button
driver.findElement(By.id("updateCamSchBtn")).click();
// verify text in the alert message
verifyDisplay("You have made following changes :"
+ " ===> alert box appears", By.id("over"));
// check the checkbox "Don't Prompt Me Again"
driver.findElement(By.cssSelector("#setcookie")).click();
// verify that the checkbox is checked
verifyDisplay("The checkbox is ===> checked", By.id("setcookie"));
// verify that the continue button is clicked
verifyDisplay("Continue Button ===> is clicked",
By.id("continueButton"));
// click on the continue button
driver.findElement(By.id("continueButton")).click();
// get an element of the error message alert window
driver.findElement(By.id("errorM"));
// verify the alert message
verifyDisplay(
"'"
+ scheduledImpNumbersNonNumericCharacters
+ "'"
+ " ===> is an invalid value for field: 'Scheduled Impressions'.",
By.xpath("//div[@class='processerror']//div[@class='closeicon']"));
// verify that the alert message window is closed
verifyDisplay(
"The alert message window ===> is CLOSED",
By.xpath("//div[@class='processerror']//div[@class='closeicon']"));
// close the error window
driver.findElement(
By.xpath("//div[@class='processerror']//div[@class='closeicon']"))
.click();
2
// locate an element for the scheduled clicks field
WebElement schClicks = driver.findElement(By
.xpath(".//*[@id='searchid2']"));
// clear the default value
schClicks.clear();
// send numerical values
schClicks.sendKeys(scheduledClicksNumbersNonNumericCharacters);
// verify that the Update button is clicked
verifyDisplay("Update Button ===> is clicked", By.id("updateCamSchBtn"));
// click the Update button
driver.findElement(By.id("updateCamSchBtn")).click();
// verify text in the alert message
verifyDisplay("You have made following changes :"
+ " ===> alert box appears", By.id("over"));
// check the checkbox "Don't Prompt Me Again"
driver.findElement(By.cssSelector("#setcookie")).click();
// verify that the checkbox is checked
verifyDisplay("The checkbox is ===> checked", By.id("setcookie"));
// verify that the continue button is clicked
verifyDisplay("Continue Button ===> is clicked",
By.id("continueButton"));
// click on the continue button
driver.findElement(By.id("continueButton")).click();
// get an element of the error message alert window
driver.findElement(By.id("errorM"));
// verify the alert message
verifyDisplay(
"'"
+ scheduledClicksNumbersNonNumericCharacters
+ "'"
+ " ===> is an invalid value for field: 'Scheduled Impressions'.",
By.xpath("//div[@class='processerror']//div[@class='closeicon']"));
// verify that the alert message window is closed
verifyDisplay(
"The alert message window ===> is CLOSED",
By.xpath("//div[@class='processerror']//div[@class='closeicon']"));
// close the error window
driver.findElement(
By.xpath("//div[@class='processerror']//div[@class='closeicon']"))
.click();
The complet trace:
java.lang.AssertionError: java.lang.AssertionError: expected [false] but found [true]
at org.testng.Assert.fail(Assert.java:94)
at com.an.oas.TestBase.verifyDisplay(TestBase.java:255)
at com.an.oas.campaign.CampaignSchedulingAndBilling.schClicksEnterNumbersAndNonNumericCharacters(CampaignSchedulingAndBilling.java:274)
at com.an.oas.campaign.test.CampaignSchedulingAndBillingTest.enterScheduledClicksWithNumericsAndNonNumericCharacters(CampaignSchedulingAndBillingTest.java:89)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1220)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
Upvotes: 0
Views: 356
Reputation: 1895
The problem may occurs if after the first test some "ghost" window is exists in the system. Then the second test will try to close this "ghost" instead the one you expected. This explain why the tests are work separately. Please verify that after the tests no hidden windows remain in the system.
Upvotes: 1