mardi 28 août 2018

TestNg parallel tests/classes when using base test class

I'm trying to run tests in parallel by using TestNg. I have 3 classes (two test classes which extend BaseTest class)

The BaseTest class has only "setup" stuff and "teardown", nothing else.

When i try to run tests in parallel like this, one class with tests runs and for other class only a browser is opened (but test isn't executed)

But!! when i cut code from BaseTest class and put it directly to each of my test classes (and thus not extending BaseClass) then the code works and tests run in parallel

why?? I'm not doing any code change at all... and when i wish to run tests not in parallel(just one by one), then using extend of BaseTest class works just fine

in testing.xml tried to put parallel="methods" "tests","true"...

below are my classes and testing.xml


public class BaseTest {

    public static WebDriver driver;
    public static WebDriverWait wait;

    @BeforeClass
    public static void setup() {
        System.setProperty("webdriver.gecko.driver", System.getProperty("user.dir") + "\\src\\files\\geckodriver.exe");

        driver = new FirefoxDriver();

        wait = new WebDriverWait(driver, 10);

        driver.manage().window().maximize();
    }

    @AfterClass
    public static void teardown() {
        driver.quit();
    }
}

-----------------------
public class HomePageHotelsSearchTest extends BaseTest {

    @Test
    public void giveNameProperly() throws IOException {
        HomePage homePage = new HomePage(driver, wait);

        homePage.openUrl("https://www.phptravels.net/");

        homePage.openHotelsSearchTab();
        homePage.inputCityInHotelsSearch("London");
        homePage.selectCityFromSearchResult(0);
        homePage.inputCheckInDateInHotelsSearch("23/08/2018");
        homePage.inputCheckOutDateInHotelsSearch("27/08/2018");
        homePage.openPeopleAmountTabInHotelsSearch();
        homePage.addAdultsInHotelsSearch(1);
        homePage.startSearchingHotels();
        homePage.elementClickable(By.linkText("Grand Plaza Apartments"));

        String firstResult = homePage.readText(By.linkText("Grand Plaza Apartments"));
        Assert.assertEquals("Grand Plaza Apartments", firstResult);

        //Reporter.log("Test owned!", true);

    }

}

-----------------------
public class LoginTest extends BaseTest {

    @Test
    public void loginTest() throws InterruptedException, IOException {
        HomePage homePage = new HomePage(driver, wait);

        homePage.openUrl("https://www.phptravels.net/");


        LoginPage loginPage = homePage.goToLoginPage();
        loginPage.waitForPageToLoad("Login");
        loginPage.inputEmail("user@phptravels.com");
        loginPage.inputPassword("demouser");

        loginPage.login();

        loginPage.waitForPageToLoad("My Account");

        String myAccountPageTitle = driver.getTitle();
        Assert.assertEquals(myAccountPageTitle, "My Account");

        //Reporter.log("Test owned!", true);


    }

}

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE suite SYSTEM "http://beust.com/testng/testng-1.0.dtd" >
    <suite name="Suite" thread-count="2" parallel="true">
        <test name="test1">
            <classes>
                <class name="tests.LoginTest" />
                <class name="tests.HomePageHotelsSearchTest"/>
            </classes>
        </test>
    </suite>

Aucun commentaire:

Enregistrer un commentaire