My apologies, if I have missed or not followed the rules, I can assure to improve though. This is my first post. I am experimenting with Cucumber scenarios to share same Browser instance among the whole feature.
There were several references available on the web, amongst all I started with https://github.com/cucumber/cucumber-jvm/tree/master/examples/java-webbit-websockets-selenium due to obvious reasons.
The 3 scenarios are executed(3 passed) normally but finally the browser instance is not closed and an exception is observed.
public class SharedDriver extends EventFiringWebDriver {
private static final WebDriver REAL_DRIVER = new FirefoxDriver();
private static final Thread CLOSE_THREAD = new Thread() {
@Override
public void run() {
REAL_DRIVER.close();
}
};
static {
Runtime.getRuntime().addShutdownHook(CLOSE_THREAD);
System.out.println("i have reached here -first thing-one time only");
}
public SharedDriver() {
super(REAL_DRIVER);
}
@Override
public void close() {
if (Thread.currentThread() != CLOSE_THREAD) {
System.out.println("i have reached here 3");
throw new UnsupportedOperationException("You shouldn't close this WebDriver. It's shared and will close when the JVM exits.");
}
super.close();
}
@Before
public void deleteAllCookies() {
manage().deleteAllCookies();
}
@After
public void embedScreenshot(Scenario scenario) {
try {
System.out.println("i have reached here -after every scenario");
byte[] screenshot = getScreenshotAs(OutputType.BYTES);
scenario.embed(screenshot, "image/png");
} catch (WebDriverException somePlatformsDontSupportScreenshots) {
System.out.println("i have reached here in after scenario exception");
System.err.println(somePlatformsDontSupportScreenshots.getMessage());
}
}
}public class TemperatureStepdefs {
private final WebDriver webDriver;
public TemperatureStepdefs(SharedDriver webDriver) {
this.webDriver = webDriver;
}
@When("^I enter (.+) (celcius|fahrenheit)$")
public void i_enter_temperature(double value, String unit) {
// webDriver.findElement(By.id(unit)).sendKeys(String.valueOf(value));
System.out.println("second step");
}
@Then("^I should see (.+) (celcius|fahrenheit)$")
public void i_should_see_temperature(double value, String unit) {
// assertEquals(String.valueOf(value), webDriver.findElement(By.id(unit)).getAttribute("value"));
System.out.println("third step");
}
}
public class NavigationStepdefs {
private final WebDriver webDriver;
public NavigationStepdefs(SharedDriver webDriver) {
this.webDriver = webDriver;
}
@Given("^I am on the front page$")
public void i_am_on_the_front_page() throws InterruptedException {
webDriver.get("https://www.google.com");
System.out.println("first step");
// The input fields won't be enabled until the WebSocket has established
// a connection. Wait for this to happen.
WebDriverWait wait = new WebDriverWait(webDriver, 1);
// wait.until(ExpectedConditions.elementToBeClickable(By.id("celcius")));
}
}
Feature: Temperature conversion
Scenario: 0 Celcius to Fahrenheit
Given I am on the front page
When I enter 0 celcius
Then I should see 32.0 fahrenheit
Scenario: 100 Celcius to Fahrenheit
Given I am on the front page
When I enter 100 celcius
Then I should see 212.0 fahrenheit
Scenario: 100 Fahrenheit to Celcius
Given I am on the front page
When I enter 100 fahrenheit
Then I should see 37.8 celciusFeature: Temperature conversion
i have reached here -first thing-one time only
first step
second step
third step
i have reached here -after every scenario
Scenario: 0 Celcius to Fahrenheit # C:/KM/workspace/CucumberTestNGPOTrial/src/test/features/com/sample/temperature_conversion.feature:3
Given I am on the front page # NavigationStepdefs.i_am_on_the_front_page()
When I enter 0 celcius # TemperatureStepdefs.i_enter_temperature(double,String)
Then I should see 32.0 fahrenheit # TemperatureStepdefs.i_should_see_temperature(double,String)
first step
second step
third step
i have reached here -after every scenario
Scenario: 100 Celcius to Fahrenheit # C:/KM/workspace/CucumberTestNGPOTrial/src/test/features/com/sample/temperature_conversion.feature:8
Given I am on the front page # NavigationStepdefs.i_am_on_the_front_page()
When I enter 100 celcius # TemperatureStepdefs.i_enter_temperature(double,String)
Then I should see 212.0 fahrenheit # TemperatureStepdefs.i_should_see_temperature(double,String)
first step
second step
third step
i have reached here -after every scenario
Scenario: 100 Fahrenheit to Celcius # C:/KM/workspace/CucumberTestNGPOTrial/src/test/features/com/sample/temperature_conversion.feature:13
Given I am on the front page # NavigationStepdefs.i_am_on_the_front_page()
When I enter 100 fahrenheit # TemperatureStepdefs.i_enter_temperature(double,String)
Then I should see 37.8 celcius # TemperatureStepdefs.i_should_see_temperature(double,String)
3 Scenarios (3 passed)
9 Steps (9 passed)
0m6.185s
Exception in thread "Thread-8" org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died.
Build info: version: '2.44.0', revision: '76d78cf', time: '2014-10-23 20:02:37'
System info: host: 'DEVPC015', ip: '192.168.56.1', os.name: 'Windows Server 2012 R2', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_25'
Driver info: driver.version: RemoteWebDriver
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:593)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:614)
at org.openqa.selenium.remote.RemoteWebDriver.close(RemoteWebDriver.java:463)
at com.sample.SharedDriver$1.run(SharedDriver.java:37)
Caused by: org.apache.http.NoHttpResponseException: 127.0.0.1:7055 failed to respond
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:143)
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:57)
at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:260)
at org.apache.http.impl.DefaultBHttpClientConnection.receiveResponseHeader(DefaultBHttpClientConnection.java:161)
at org.apache.http.impl.conn.CPoolProxy.receiveResponseHeader(CPoolProxy.java:153)
at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:271)
at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:123)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:254)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:195)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:86)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:72)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:57)
at org.openqa.selenium.remote.HttpCommandExecutor.fallBackExecute(HttpCommandExecutor.java:233)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:184)
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.execute(NewProfileExtensionConnection.java:165)
at org.openqa.selenium.firefox.FirefoxDriver$LazyCommandExecutor.execute(FirefoxDriver.java:362)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:572)
... 3 moreMy apologies, if I have missed or not followed the rules, I can assure to improve though. This is my first post.
I am experimenting with Cucumber scenarios to share same Browser instance among the whole feature.
There were several references available on the web, amongst all I started with https://github.com/cucumber/cucumber-jvm/tree/master/examples/java-webbit-websockets-selenium due to obvious reasons.
The 3 scenarios are executed(3 passed) normally but finally the browser instance is not closed and an exception is observed.
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
My apologies, if I have missed or not followed the rules, I can assure to improve though. This is my first post. I am experimenting with Cucumber scenarios to share same Browser instance among the whole feature.
There were several references available on the web, amongst all I started with https://github.com/cucumber/cucumber-jvm/tree/master/examples/java-webbit-websockets-selenium due to obvious reasons.
The 3 scenarios are executed(3 passed) normally but finally the browser instance is not closed and an exception is observed.
privatestaticfinalWebDriver REAL_DRIVER =newFirefoxDriver();privatestaticfinalThread CLOSE_THREAD =newThread(){@Overridepublicvoid run(){
REAL_DRIVER.close();}};static{Runtime.getRuntime().addShutdownHook(CLOSE_THREAD);System.out.println("i have reached here -first thing-one time only");}publicSharedDriver(){super(REAL_DRIVER);}@Overridepublicvoid close(){
if(Thread.currentThread()!= CLOSE_THREAD){
System.out.println("i have reached here 3");
thrownewUnsupportedOperationException("You shouldn't close this WebDriver. It's shared and will close when the JVM exits.");
}super.close();}@Beforepublicvoid deleteAllCookies(){manage().deleteAllCookies();}@After
publicvoid embedScreenshot(Scenario scenario){
try{System.out.println("i have reached here -after every scenario");byte[] screenshot = getScreenshotAs(OutputType.BYTES);scenario.embed(screenshot,"image/png");
}catch(WebDriverException somePlatformsDontSupportScreenshots){
System.out.println("i have reached here in after scenario exception");System.err.println(somePlatformsDontSupportScreenshots.getMessage());}}
publicclassSharedDriverextendsEventFiringWebDriver{
publicclassTemperatureStepdefs{privatefinalWebDriver webDriver;publicTemperatureStepdefs(SharedDriver webDriver){
this.webDriver = webDriver;}@When("^I enter (.+) (celcius|fahrenheit)$")
publicvoid i_enter_temperature(double value,String unit){
// webDriver.findElement(By.id(unit)).sendKeys(String.valueOf(value));System.out.println("second step");}@Then("^I should see (.+) (celcius|fahrenheit)$")
publicvoid i_should_see_temperature(double value,String unit){
// assertEquals(String.valueOf(value), webDriver.findElement(By.id(unit)).getAttribute("value"));System.out.println("third step");}}
publicclassNavigationStepdefs{privatefinalWebDriver webDriver;publicNavigationStepdefs(SharedDriver webDriver){
this.webDriver = webDriver;}@Given("^I am on the front page$")publicvoid i_am_on_the_front_page()throwsInterruptedException{System.out.println("first step");// The input fields won't be enabled until the WebSocket has established// a connection. Wait for this to happen.WebDriverWait wait =newWebDriverWait(webDriver,1);// wait.until(ExpectedConditions.elementToBeClickable(By.id("celcius")));}}
On execution of below feature, i get below console output.
Feature:Temperature conversionScenario:0Celcius to Fahrenheit
Given I am on the front pageWhen I enter 0 celciusThen I should see 32.0 fahrenheit
Scenario:100Celcius to Fahrenheit
Given I am on the front pageWhen I enter 100 celciusThen I should see 212.0 fahrenheit
Scenario:100Fahrenheit to Celcius
Given I am on the front pageWhen I enter 100 fahrenheitThen I should see 37.8 celcius
Feature:Temperature conversioni have reached here -first thing-one time onlyfirst stepsecond stepthird stepi have reached here -after every scenario
Scenario:0Celcius to Fahrenheit# C:/KM/workspace/CucumberTestNGPOTrial/src/test/features/com/sample/temperature_conversion.feature:3
Given I am on the front page # NavigationStepdefs.i_am_on_the_front_page()When I enter 0 celcius # TemperatureStepdefs.i_enter_temperature(double,String)Then I should see 32.0 fahrenheit # TemperatureStepdefs.i_should_see_temperature(double,String)first stepsecond stepthird stepi have reached here -after every scenario
Scenario:100Celcius to Fahrenheit# C:/KM/workspace/CucumberTestNGPOTrial/src/test/features/com/sample/temperature_conversion.feature:8
Given I am on the front page # NavigationStepdefs.i_am_on_the_front_page()When I enter 100 celcius # TemperatureStepdefs.i_enter_temperature(double,String)Then I should see 212.0 fahrenheit # TemperatureStepdefs.i_should_see_temperature(double,String)first stepsecond stepthird stepi have reached here -after every scenario
Scenario:100Fahrenheit to Celcius# C:/KM/workspace/CucumberTestNGPOTrial/src/test/features/com/sample/temperature_conversion.feature:13
Given I am on the front page # NavigationStepdefs.i_am_on_the_front_page()When I enter 100 fahrenheit # TemperatureStepdefs.i_enter_temperature(double,String)Then I should see 37.8 celcius # TemperatureStepdefs.i_should_see_temperature(double,String)3Scenarios(3 passed)9Steps(9 passed)0m6.185s
Exceptionin thread "Thread-8" org.openqa.selenium.remote.UnreachableBrowserException:Error communicating with the remote browser.It may have died.
Build info: version:'2.44.0', revision:'76d78cf', time:'2014-10-23 20:02:37'System info: host:'DEVPC015', ip:'192.168.56.1', os.name:'Windows Server 2012 R2', os.arch:'amd64', os.version:'6.3', java.version:'1.8.0_25'Driver info: driver.version:RemoteWebDriverat org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:593)at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:614)at org.openqa.selenium.remote.RemoteWebDriver.close(RemoteWebDriver.java:463)at com.sample.SharedDriver$1.run(SharedDriver.java:37)
Causedby: org.apache.http.NoHttpResponseException:127.0.0.1:7055 failed to respond
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:143)at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:57)at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:260)at org.apache.http.impl.DefaultBHttpClientConnection.receiveResponseHeader(DefaultBHttpClientConnection.java:161)at org.apache.http.impl.conn.CPoolProxy.receiveResponseHeader(CPoolProxy.java:153)at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:271)at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:123)at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:254)at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:195)at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:86)at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108)at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:72)at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:57)at org.openqa.selenium.remote.HttpCommandExecutor.fallBackExecute(HttpCommandExecutor.java:233)at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:184)at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.execute(NewProfileExtensionConnection.java:165)at org.openqa.selenium.firefox.FirefoxDriver$LazyCommandExecutor.execute(FirefoxDriver.java:362)at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:572)
...3 more
Also I am not using pom.xml , instead importing jars manually. Browser Firefox-39 ,Selenium server standalone 2.44.0, cucumber-picocontainer 1.1.8 picocontainer 2.7 cucumber-testng 1.1.8 gherkin 2.12.2 cucummber core 1.1.8 cucumber html 0.2.3 cucumber-java 1.1.8
If anybody can please direct me to other possible alternatives to Dependency Injection, I ll highly appreciate. Please suggest.
@Override public void run() { System.out.println("i am going to attempt to close browser"); try { REAL_DRIVER.close(); } catch (WebDriverException e) { System.out.println(e.getMessage()); System.out.println("sorry couldn't"); } } @Override public void close() { System.out.println("i landed in this method"); if (Thread.currentThread() != CLOSE_THREAD) { System.out.println("i have reached here 3"); throw new UnsupportedOperationException("You shouldn't close this WebDriver. It's shared and will close when the JVM exits."); } super.close(); }3 Scenarios (3 passed)9 Steps (9 passed)0m5.702s
i am going to attempt to close browserError communicating with the remote browser. It may have died.Build info: version: '2.44.0', revision: '76d78cf', time: '2014-10-23 20:02:37'System info: host: 'DEVPC015', ip: '192.168.56.1', os.name: 'Windows Server 2012 R2', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_25'Driver info: driver.version: RemoteWebDriversorry couldn't...
...
...
...
Also, sole purpose of me using DI was that it was being suggested in example.
No offence to the pico container, but it being another framework need not to be necessarily clubbed with Cucumber.
I think I belong to pro beforesuite and aftersuite community as well.
just wondering ,if below hack can work using available hooks:1) declare static variable 'driver' with an instance of browser in 'RunCukesTest.class'.
2) use 'driver' in all the step definition3) have @Before hook to clear the cookies , cache , history, load profile, before every runnable scenario of any feature.4) create separate feature with 1 scenario(mandatory to run) , which accepts code to close the browser or any the relevant server.
Alternatively last step of last scenario to be executed can be used to do some misc. closing ceremony work.
Groups can be used on last step to close the browser.
--
Hi Seb, the firefox version is 34.0. Its shown on browser in About Us tab, Sorry for previous typo in previous email. firefox says"firefox is upto date".
* Updating Native events to support Firefox 24, 31, 32 and 33
I just wanted to evaluate , if there are other approaches to solve this requirement of using single Browser instance getting used across whole feature.
Feature: Example @finals Scenario: another example scenario Given This is mandatory step to close the browserpublic class RunCukesByCompositionTest extends RunCukesByCompositionBase {
/** * Create one test method that will be invoked by TestNG and invoke the * Cucumber runner within that method. */ @Test(groups = "examples-testng", description = "Example of using TestNGCucumberRunner to invoke Cucumber") public void runCukes() { new TestNGCucumberRunner(getClass()).runCukes(); } static WebDriver driver = new FirefoxDriver(); }public class GlobalStepDefs {
@Before public static void before() { System.out.println("stepdefs deleting cookies"); RunCukesByCompositionTest.driver.manage().deleteAllCookies(); // delete cache or reload new profile.? }
}public class finalstepdef {
@Given("^This is mandatory step to close the browser$") public void this_is_mandatory_step_to_close_the_browser() throws Throwable { System.out.println("Misc stuff"); //do some misc stuff. } @After("@finals") public void this_is__step_to_close_the_browser() throws Throwable { RunCukesByCompositionTest.driver.quit(); }
}...