Create new browser instance for every test execution
For projects with Selenium2 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" xmlns:lang="http://www.springframework.org/schema/lang" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation= "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.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> <bean id="webDriverFactory" class="com.thoughtworks.twist.driver.webdriver.WebDriverFactory" init-method="start" destroy-method="stop" lazy-init="true"> <property name="enableNativeEvents" value="${webdriver.browser.nativeEvents}"/> <property name="javascriptEnabled" value="${webdriver.browser.javascriptEnabled}"/> <property name="htmlUnitBrowserVersion" value="${webdriver.browser.version}"/> <property name="scriptPath" value="${webdriver.browser.script}"/> <property name="profilePath" value="${webdriver.browser.profile}"/> <property name="mobileServerAddress" value="${webdriver.mobile.server}"/> <property name="chromeServer" value="${webdriver.chrome.driver}"/> </bean> <bean id="browser" factory-bean="webDriverFactory" factory-method="getBrowser" lazy-init="true" destroy-method="quit" scope="singleton"> <constructor-arg value="${webdriver.browser}" /> </bean> - Save file applicationContext-scenario.xml and execute scenarios.