TestNG.xml > only Executing First TestNG Test
I have copied the exact same working project, setup etc on a new device(PC) but when executing the same testng.xml it seems to execute only the first #Test across all test cases.
Running the test on my existing system works correctly.
For example #Test(priority = 1) only seems to be executing across all my 100+ TestNG Test classes.
Example Test File:
#Test(priority = 1)
public void LoadPage() throws Exception {
basePage.loadPage();
//Logs whether the Url and page Title is correct
DOMConfigurator.configure("log4j.xml");
Log.info("#PASS ---> Expected Site URL: " + basePage.page_url + " | Found the following Site URL: " + basePage.getPageUrl());
Log.info("#PASS ---> Expected Page Title: " + basePage.page_title + " | Found the following title: " + basePage.getPageTitle());
}
#Test(priority = 2)
public void hutLocaliseAndSelectOrderType() throws Exception {
phHomepage.enterHutPostcode();
hutLocalisePage.selectOrderType();
}
#Test(priority = 3)
public void SignIntoAccount() throws Exception {
basePage.pageJSLoadAndClick(pageHeader.button_SignIn);
//Sign into Account
signInPage.signIntoAccount();
//Validate whether Sign Out button is visible, once successfully signed into account
pageHeader.signOutButtonIsDisplayed();
}
**Listed in BasePage.java class**
public void loadPage() throws Exception{
driver.get(page_url);
Assert.assertEquals(driver.getCurrentUrl(), getPageUrl());
Assert.assertEquals(driver.getTitle(), getPageTitle());
}
<suite name="PH_Automation_Scripts_by_GBruno" verbose="2">
<test name="PH Automation Tests: Pizza Combinations" parallel="false">
<packages>
<package name="PhFramework.pizzas.*" />
</packages>
</test>
If i alter the above testng.xml to execute one test at a time the test executes fine.
#Phil_P85 - This is your testng xml file.
<suite name="PH_Automation_Scripts_by_GBruno" verbose="2">
<test name="PH Automation Tests: Pizza Combinations" parallel="false">
<packages>
<package name="PhFramework.pizzas.*" />
</packages>
</test>
Can you describe 'PhFramework.pizzas.*' ? If 'pizzas' is your package, can you try doing just '' see if it works.
Related
I am automating an application using Selenium WebDriver with Java,TestNG and Maven and there is a login page present in Application under test.
Now, I am testing 2 things while automating the login functionality:
Login Page Title
Login Page Functionality
Now from above 2 methods, only first method is working(Login Page Title), and second method is not executing (Login Page Functionality), although there is no error in the TestNG while compiling and running the application.
public class LoginTest extends TestBase {
Login loginpage;
HomePage homePage;
public LoginTest() {
super(); // method to load the System Property
}
#BeforeMethod
public void setUp() throws IOException {
initialization(); // method to initiate and launch the browser
loginpage = new Login();
}
#Test(priority = 1)
public HomePage LogiTest() throws IOException {
return homePage = loginpage.login(prop.getProperty("username"), prop.getProperty("password"));
}
#Test(priority = 2)
public void ValidateLoginPageTitleTest() {
String title = loginpage.ValidateLoginPageTitle();
Assert.assertEquals("Application", title);
System.out.println(title);
}
#AfterMethod
public void tearDown() {
driver.quit();
}
}
Now from above two test methods, only ValidateLoginPageTitleTest is executing while running the TestNG Suite.
Second method LogiTest is not getting picked by TestNG.
Now TestNG is showing below message on console after running the test.
Total tests run: 1, Failures: 0, Skips: 0
===============================================
PFB TestNG.xml for reference
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="automation testing scn">
<listeners>
<listener
class-name="PackageName.ExtentReportListener"></listener>
</listeners>
<test thread-count="5" name="Test">
<classes>
<class name="packageName.LoginTest" />
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
Methods with tag #Test should be of type void to be recognized as a test by TestNG.
LogiTest() returns a HomePage item so it isn't being recognized as a runnable test by TestNG.
As an other observation, by definition, every test should have an assertion and LogiTest() is missing one. Perhaps LogiTest should be rewritten as a test or just dismissed as one.
Executing Multiple classes with testng.xml suite, Where If any single class or test got fail it will skip only that particular test and go ahead for next test suite, for Firefox and Chrome. But, in case of Microsoft edge it can't handle Fail Test suite. And it creates Fail/Skip script for rest all.
Reference of .XMl suite:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="tests" verbose="1">
<test name="Login-Registration Test" preserve-order="true">
<classes>
<class name="myAccount.login" />
<class name="myAccount.registration" />
</classes>
</test>
<!-- Test -->
</suite> <!-- Suite -->
Here its example of 2 classes, Where it will execute Login Test suite and after that Registration as suite. But, if Login gets fail it will not execute Registration Suite for Edge. Which is working for Firefox and Chrome.
I am invoking browsers with WebDriver:
// driver = new ChromeDriver();
// driver = new FirefoxDriver();
driver = new EdgeDriver();
Calling #AfterMethod annotation after each #Test, with ITestResult
#AfterMethod
public void calltestStatus(ITestResult result) throws IOException
{
testStatus(result);
count++;
driver.manage().deleteAllCookies();
}
And here is ITestResult definition,
public void testStatus(ITestResult result) throws IOException
{
if (result.getStatus() == ITestResult.FAILURE) {
testResult = "Test Fail :" + result.getName();
testResult = "Details of Fail Testcase:" + result.getThrowable();
extentReport.flush();
} else if (result.getStatus() == ITestResult.SUCCESS) {
testResult = "Test Pass :" + result.getName();
} else if (result.getStatus() == ITestResult.SKIP) {
testResult = "Test Skip :" + result.getName();
} else {
testResult = "Test Undefined :" + result.getName() + "<br>Status : " + result.getStatus();
testResult = "Details of undefined Testcase:" + result.getThrowable();
}
}
TestNG or Selenium is working differently for Edge ?
This is the limitation of Edge Browser, Where it can invoke only single instance for Web Driver Testing.
Its relevant to my case, When it got fail and invoke for another instance to open Edge Browser of another Suite, But Edge driver is not supported so far. So it got Skip and fail for rest all.
https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/13618786/
I want to run cucumber feature file from java code.
currently we are running form JUnit Runner
package com.compareglobalgroup.testscript;
import cucumber.api.CucumberOptions;
import cucumber.api.testng.AbstractTestNGCucumberTests;
#CucumberOptions(features = { "src/test/resources/feature/BB" }, glue = { "com.compareglobalgroup.stepdefs.BB",
"com.compareglobalgroup.cucumber.hooks" }, plugin = {
"json:cucumberreport/json/cucumberreport.json" }, tags = { ""
+ "#Test" })
public class TestRunnerBB extends AbstractTestNGCucumberTests {
}
I don't want to use this instead I want to run this using java program because I want to pass tags at run time from command line or jenkins.
Call the static main method of Main class in the package cucumber.api.cli that corresponds to running cucumber from the command line.
public static void main(String[] args) throws Throwable {
Main.main(new String[]{"-g", "classpath to step definition file", "Full path to feature file"});
// My stepdefinition is inside java package at cucumber.sample.test
// My feature file is inside src/test/resources/features/featurefile.feature
}
For additional parameters like tags or plugin use "-t","#Tags". Important the feature file path has to be the last option.
BTW - In the your example you are running with a TestNG cucumber runner.
I would recommend qaf-gherkin where you don't need to use junit or other runner. All you need to specify step provider package and feature file(s) or dir to run. For example:
<test name="Gherkin-QAF-Test">
<parameter name="step.provider.pkg" value="com.qmetry.qaf.automation.impl.step.qaf" />
<parameter name="scenario.file.loc" value="resources/features" />
<classes>
<class name="com.qmetry.qaf.automation.step.client.gherkin.GherkinScenarioFactory" />
</classes>
</test>
You can walk through qaf-step-by-step-tutorial
I have configured a node and two different nodes. The both node machine runs on windows and only IE. So i want to run my test script on these two nodes at the same time(parallely). But when i am trying this scripts are running one after another not simultaneously. please find below my code.
java -jar selenium-server-standalone-2.28.0.jar -role hub -port 8080
java -Dwebdriver.ie.driver=IEDriverServer.exe -jar selenium-server-standalone-2.28.0.jar -role node -hub http://172.29.70.143:8080/grid/register - browser "browserName=ie,maxInstances=10,platform=WINDOWS" -port 8080
public class Sample {
WebDriver driver;
String baseUrl, nodeUrl;
#BeforeTest
public void setUp() throws MalformedURLException {
baseUrl = "https://10.87.137.219/selfRegistration_sit/";
nodeUrl = "http://172.29.70.143:8080/wd/hub";
DesiredCapabilities capability = DesiredCapabilities.internetExplorer();
capability
.setCapability(
InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,
true);
capability.setBrowserName("ie");
capability.setPlatform(Platform.WINDOWS);
driver = new RemoteWebDriver(new URL(nodeUrl), capability);
capability
.setCapability(
InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,
true);
driver.manage().window().maximize();
driver.manage().deleteAllCookies();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
}
#Test
public void test() throws Exception {
driver.navigate().to(baseUrl);
driver.navigate().to(
"javascript:document.getElementById('overridelink').click()");
// System.out.println("Certifi");
// System.out.println("After certifi");
// click on register Non VIL
driver.findElement(By.id("ctl00_ContentPlaceHolder1_img_reg")).click();
// enter supervisor name
driver.findElement(By.name("ctl00$ContentPlaceHolder1$txtEmployeeID"))
.sendKeys("90001451");
// click on search
driver.findElement(By.name("ctl00$ContentPlaceHolder1$IbtnGetDetTab3"))
.click();
Thread.sleep(2000);
// //click on select
List<WebElement> List=driver.findElements(
By.xpath("//a[contains(#href,'javascript:__doPostBack(')]"));
List.get(1).click();
driver.findElement(By.name("ctl00$ContentPlaceHolder1$txtName"))
.sendKeys("Mani");
// select circle
new Select(driver.findElement(By
.name("ctl00$ContentPlaceHolder1$drpCircle")))
.selectByVisibleText("GUJARAT");
// location
driver.findElement(By.name("ctl00$ContentPlaceHolder1$txtLocation"))
.sendKeys("Location");
// departmenr
driver.findElement(By.name("ctl00$ContentPlaceHolder1$txtDept"))
.sendKeys("Department");
// mobilenumber
driver.findElement(By.name("ctl00$ContentPlaceHolder1$txtMobile"))
.sendKeys("8983152157");
// sub departmnet
driver.findElement(By.name("ctl00$ContentPlaceHolder1$txtSubdept"))
.sendKeys("Sub Department");
// email
driver.findElement(By.name("ctl00$ContentPlaceHolder1$txtOwnerEamil"))
.sendKeys("Email");
// domain
new Select(driver.findElement(By
.name("ctl00$ContentPlaceHolder1$drpmailids")))
.selectByVisibleText("VODA.COM");
// designation
driver.findElement(By.name("ctl00$ContentPlaceHolder1$txtDesignation"))
.sendKeys("Designation");
// org name
driver.findElement(By.name("ctl00$ContentPlaceHolder1$txtVendorname"))
.sendKeys("Organistaion");
// POI type
new Select(driver.findElement(By
.name("ctl00$ContentPlaceHolder1$ddlPOI_TYPE")))
.selectByVisibleText("PAN Card");
// POI value
driver.findElement(By.name("ctl00$ContentPlaceHolder1$txtPOI_Value"))
.sendKeys("PAN123413");
// //physical
driver.findElement(By.id("ctl00_ContentPlaceHolder1_rbAccess_0"))
.click();
// vf user
driver.findElement(By.id("ctl00_ContentPlaceHolder1_rbEmpVf_1"))
.click();
// click on proceed
driver.findElement(By.name("ctl00$ContentPlaceHolder1$IbtnSubmit"))
.click();
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="tests" thread-count="2">
<test name="IETest">
<parameter name="browser" value="ie" />
<classes>
<class name="testScripts.Sample" />
</classes>
</test>
</suite>
You have parallel="tests" in your testng xml configuration file and it has only one test tag in it. Have multiple tests tags pointing to single test method in code to run parallel tests or change parallel="tests" to parallel="methods" and keep at least two methods in your class so that it will run two test methods in parallel.
I am using testNG and Appium to run mobile automation.Following are my codes:
package my.app.package;
public class TestDataProvider {
#DataProvider(parallel=false)
public static Object[][] GenericDataProviderWithNoCustomCapabilities() {
return new Object[][] {
{"", "Nexus_5_API_21_x86", "19", "C:\\Users\\me\\Desktop\\app.apk", "http://127.0.0.1:4723/wd/hub", ScreenOrientation.PORTRAIT},
{"", "Nexus_5_API_21_x86", "20", "C:\\Users\\me\\Desktop\\app.apk", "http://127.0.0.1:4723/wd/hub", ScreenOrientation.LANDSCAPE}
};
}
}
In the test suite class:
public class SanityTestAndroid {
private ScreenOrientation orientation;
#Factory(dataProviderClass = my.app.package.TestDataProvider.class, dataProvider="GenericDataProviderWithNoCustomCapabilities")
public SanityTestAndroid(String version, String avd, String platformVersion, String appPath, String targetPath, ScreenOrientation orientation) throws Exception {
AndroidDriverFactory.create(version, avd, platformVersion, appPath, targetPath);
this.orientation = orientation;
}
#Test()
public void testLoginInLandscape() throws Exception {
if (orientation == ScreenOrientation.LANDSCAPE) {
...}
...}
And testNG.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="android automation" parallel="false">
<test name="com.tribehr.qa.tests">
<classes>
<class name="my.app.package.test.SanityTestAndroid "/>
</classes>
</test>
</suite>
I have set all testNG parallel to false (as far as I know), but when running the test I still see it being run parallelly. I am not sure why, and what can I do to make it run twice in a queue (as two dataset are given).
TestNG is executing tests sequentially by default. If they are executing concurrently, you must have a setting to do so.
You need to add group-by-instances="true" attribute to your test element in suite *.xml. In other case it doesn't work the way you expect.
if your driver is initialized in #beforeTest method then drivers will open for all test at a time and then the tests of all classes will run sequentially