0

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)

khris
  • 4,809
  • 21
  • 64
  • 94

1 Answers1

0

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

  • is there a reason you have to do the driver = null part & kill the processes (I presume with some other 3rd party process, not WebDriver)? Is .quit() not enough? – Steve Weaver Crawford Dec 17 '13 at 21:26
  • I changed this part: driver.quit(); driver = null; killUnhandledProcess("IEDriverServer.exe"); killUnhandledProcess("iexplore.exe"); on just driver.close();. Still doesn't work. The IE closes after first test and doesn't statrs again – khris Dec 18 '13 at 11:16
  • Where abouts are you making the driver = new InternetExplorerDriver() call? It will need to be one of the first things you do in the @BeforeClass method – Steve Weaver Crawford Dec 18 '13 at 20:43
  • It seems that you're not initialising the driver object at the beginning of each test class. If the main class in your second package is HomePage, and that's the only place a driver object is being initialised, then that has to be the first step of each test. Do Test1 and Test2 start off in the same fashion? Post the full stack trace if you can, I can't tell if this exception is happening at the end of Test1 or the beginning of Test2 – Steve Weaver Crawford Dec 19 '13 at 21:21
  • could you please look to the http://stackoverflow.com/questions/20786671/how-to-make-driver-value-null-after-first-test-in-suite-is-run. I try to give more details and information – khris Dec 26 '13 at 14:45