Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling same test class in two test tags of TestNG configuration is not working correctly #953

Open
gszczutkowski opened this issue Sep 12, 2019 · 0 comments
Labels

Comments

@gszczutkowski
Copy link
Contributor

It is not possible run in parallel tests from the same test class when the class is defined in separate test tags of configuration file. Here is the example of testng configuration file:

<suite name="Parallel tests" parallel="tests" thread-count="2">
    <test name="Home Page Tests">
        <parameter name="test-name" value="Home page"/>
        <groups>
            <run>
                <include name="A"/>
            </run>
        </groups>
        <classes>
            <class name="com.testcraftsmanship.utils.SomeFluentTest"/>
        </classes>
    </test>
    <test name="Sequential Tests">
        <parameter name="test-name" value="Home page"/>
        <groups>
            <run>
                <exclude name="A"/>
            </run>
        </groups>
        <classes>
            <class name="com.testcraftsmanship.utils.SomeFluentTest"/>
        </classes>
    </test>
</suite>

Test for veryfying this scenario can be:

public class SomeFluentTest extends FluentTestNg {

    @Test(groups = "A")
    public void shortTest() {
        goTo("https://google.com");
        newInstance(GooglePage.class)
                .getInputField()
                .click();
        waitMillis(3000);
        newInstance(GooglePage.class)
                .getInputField()
                .click();
    }

    @Test(groups = "B")
    public void longTest() {
        goTo("https://google.com");
        newInstance(GooglePage.class)
                .getInputField()
                .click();
        waitMillis(10000);
        newInstance(GooglePage.class)
                .getInputField()
                .click();
    }

    private void waitMillis(int millis) {
        try {
            Thread.sleep(millis);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

}

class GooglePage extends FluentPage {
    @FindBy(css = "input[title='Search']")
    private FluentWebElement inputField;

    FluentWebElement getInputField(){
        await().until(inputField).clickable();
        return inputField;
    }
}

Actual outcome:
When the first of those two tests is finished then webdriver for the second one is also closed. Exception is thrown: org.openqa.selenium.NoSuchSessionException: Session ID is null. Using WebDriver after calling quit()?

Workaround for this case is to move the test methods from A group to separate test class but It is not very elegant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants