Create new browser instance for every test execution

For projects with Selenium as the driver, Twist by default executes all the scenarios in a single browser instance. The configurations for this setting is present in the applicationContext-suite.xml

However, executing all scenarios through a single browser instance might not be desirable in all cases. Follow the steps below to use a new browser instance in each Scenario.

  • Open the applicationContext-suite.xml and applicationContext-scenario.xml file. These file can be accessed by searching using CTRL+SHIFT+R (or CMD+SHIFT+R on mac) or by navigating to the project's source directory in the Package Explorer View.
  • Move all the selenium related bean configurations from applicationContext-suite.xml to applicationContext-scenario.xml

    Now, the applicationContext-scenario.xml should look like this:

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://www.springframework.org/schema/beans org/springframework/beans/factory/xml/spring-beans-2.5.xsd">
    
      <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE"/>
        <property name="locations">
          <value>classpath:twist.properties</value>
        </property>
      </bean>
    <!--
       The SeleniumRCDriver manages both the Selenium proxy and client
     -->
     <bean id="seleniumDriverFactory" class="com.thoughtworks.twist.driver.selenium.SeleniumRCDriver" init-method="start" destroy-method="stop" lazy-init="true">
         <property name="serverOptions" value="${selenium.server.options}"/>
         <property name="browserLauncher" value="${selenium.browserLauncher}"/>
         <property name="browserURL" value="${selenium.browserURL}"/>
     </bean>
      <!--
       The actual Twist Selenium extension.
     -->
      <bean id="selenium"
        factory-bean="seleniumDriverFactory"
        factory-method="getTwistSelenium"
        lazy-init="true">
        <constructor-arg value="${twist.selenium.enableImplicitWait}" />
        <property name="highlight" value="${twist.selenium.highlight}"/>
       </bean>
    </beans>  
      
  • Save file applicationContext-scenario.xml and execute scenarios.