second test of test suite fails (browser doesn't opens)

948 views Asked by At

I use selenium webdriver with junit. I run my tests in IE with ant in Jenkins. I want to run several test as testsuite.

So I have created class TestSuite:

@RunWith(Suite.class)
@SuiteClasses({ Test1.class, Test2.class,
    Test3.class })
public class TestSuite {
}

In build.xml I have added:

<target name="TestSuite">
    <mkdir dir="${dir}" />
    <junit fork="yes" printsummary="withOutAndErr">
        <formatter usefile="false" type="plain" />
        <formatter type="xml" />
        <batchtest todir="${dir}">
            <fileset dir="bin">
                <include name="**/TestSuite.class" />
            </fileset>
        </batchtest>
        <classpath refid="classpath" />
    </junit>
</target>

But then I run test suite, Test1 is run successfully, and Test2 fails, browser is not even launched. I have method Before and After each test. In Before I clear cache and in After I run:

driver.quit();
driver = null;
killUnhandledProcess("IEDriverServer.exe");
killUnhandledProcess("iexplore.exe");

How can I run the whole suite without fails?

Error log:

Testcase: test1 took 4,993 sec
[junit]     Caused an ERROR
[junit] Session ID is null
[junit] Driver info: driver.version: RemoteWebDriver
[junit] org.openqa.selenium.remote.SessionNotFoundException: Session ID is null
[junit] Driver info: driver.version: RemoteWebDriver
[junit]     at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:276)
[junit]     at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:66)
[junit]     at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:527)
[junit]     at org.openqa.selenium.remote.RemoteWebDriver.get(RemoteWebDriver.java:276)...

I have 2 packages - one for tests itself. Each test is in the separate class and all those clasees extends base class. In base class I have Before and After methods. The second package contains classes for page object. In this package the main class is Home page and on this page WebDriver is initialized:

protected WebDriver driver = DriverStart.getDriver();

Implementation of driver is in the separate class (singleton)

1

There are 1 answers

5
Steve Weaver Crawford On

Try moving your @After code into an @AfterClass method, that way it should run all methods before disposing of the driver object.

You may want to use the @After method to go back to a homepage/logout as necessary with your application under test