[cucumber-jvm] SharedDriver Example (using PICO container DI) is not closing the browser for me.

1,439 views
Skip to first unread message

Kunal Mehta

unread,
Dec 2, 2014, 10:24:49 PM12/2/14
to cu...@googlegroups.com

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")));
   
}
}



On execution of below feature, i get below console output.

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 celcius


Feature: 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 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.

aslak hellesoy

unread,
Dec 3, 2014, 2:22:28 AM12/3/14
to Cucumber Users
On Wed, Dec 3, 2014 at 3:24 AM, Kunal Mehta <kunalm...@gmail.com> wrote:

My apologies, if I have missed or not followed the rules, I can assure to improve though. This is my first post.

Great first post - welcome! 

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.

Can you add some debug statements to the close thread's run method? JVM shutdown hooks are whimsical creatures - I've never completely understood how they work and in what situations they are unreliable - I just know they can be.

Maybe we need the oft asked-for AfterAll hook anyway...
Unless your app is already using a DI framework I suggest you stick with PicoContainer since it doesn't require any configuration. What are you looking for in a DI framework?
 


--
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.

Seb Rose

unread,
Dec 3, 2014, 3:11:11 AM12/3/14
to cu...@googlegroups.com
 
On Wed, 3 Dec 2014, at 03:24 AM, Kunal Mehta wrote:

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(){
 
@Override
 
publicvoid 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);
 
}
 
@Override
 
 
publicvoid 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();
 
}
 
@Before
 
 
publicvoid 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{
        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 =newWebDriverWait(webDriver,1);
//  wait.until(ExpectedConditions.elementToBeClickable(By.id("celcius")));
}
}
 
 
 
On execution of below feature, i get below console output.
 
Feature:Temperature conversion
 
 
Scenario:0Celcius to Fahrenheit
Given I am on the front page
When I enter 0 celcius
Then I should see 32.0 fahrenheit
 
 
Scenario:100Celcius to Fahrenheit
Given I am on the front page
When I enter 100 celcius
Then I should see 212.0 fahrenheit
 
 
Scenario:100Fahrenheit to Celcius
Given I am on the front page
When I enter 100 fahrenheit
Then I should see 37.8 celcius
Feature: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: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 step
second step
third step
i 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 step
second step
third step
i 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: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)
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
 
In my experience this is often caused by a mismatch of Selenium and Firefox versions. The simplest solution is often to use the latest version of both of them. And once I get a working combination I turn off automatic Firefox upgrades ;)
 
Selenium 2.44.0 is the latest, but Mozilla says the latest version of Firefox is 34.0.5. Can you check your Firefox version?
 
 
 
If anybody can please direct me to other possible alternatives to Dependency Injection, I ll highly appreciate. Please suggest.
 
 
Why? Is this a separate question?
 
 
Seb
 
 
 
--
The Cucumber for Java Book - Seb Rose, Matt Wynne & Aslak Hellesøy
Now available from the Pragmatic Press - https://pragprog.com/book/srjcuc/the-cucumber-for-java-book
 

Kunal Mehta

unread,
Dec 4, 2014, 2:03:46 AM12/4/14
to cu...@googlegroups.com
Thanks Aslak for the prompt reply.
I have modified the code as shown below

 @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();
    }


below is my output

3 Scenarios (3 passed)
9 Steps (9 passed)
0m5.702s

i am going to attempt to close browser
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
sorry 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 definition
3) 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.




...

Kunal Mehta

unread,
Dec 4, 2014, 2:16:05 AM12/4/14
to cu...@googlegroups.com
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".  I just wanted to evaluate , if there are other approaches to solve this requirement of using single Browser instance getting used across whole feature.
Thanks Kunal
...
...
...

Aslak Hellesøy

unread,
Dec 4, 2014, 2:48:12 AM12/4/14
to cu...@googlegroups.com
Ok, so it seems to be a WebDriver problem and not Cucumber related? 
Also, sole purpose of me using DI was that it was being suggested in example. 
You have to use DI if you want to share objects/state between stepdefs. In your case you need the browser injected into your stepdefs.
No offence to the pico container, but it being another framework need not to be necessarily clubbed with Cucumber.

It's not really a framework, just a tiny library. 
I think I belong to pro beforesuite and aftersuite community as well.

Is that a community now? :-)
just wondering ,if below hack can work using available hooks: 
1) declare static variable 'driver' with an instance of browser in 'RunCukesTest.class'.
I usually avoid static variables because it doesn't work in multithreaded environments and breaks encapsulation. Try it out, but be careful.
2) use 'driver' in all the step definition
3) 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.
I'd rather use an After hook to close it if some global counter reaches zero. Increment in Before, decrement in After
    Alternatively last step of last scenario to be executed can be used to do some misc. closing ceremony work.
Yuck yuck yuck yuck. What happened to scenarios-as-docs for the whole team (including product owners and BAs)
Groups can be used on last step to close the browser.

What's groups?

Aslak 
--

Seb Rose

unread,
Dec 4, 2014, 3:42:45 AM12/4/14
to cu...@googlegroups.com
On Thu, 4 Dec 2014, at 07:16 AM, Kunal Mehta wrote:
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".  
 
The Selenium changelog for the last release 2.44.0 http://selenium.googlecode.com/git/java/CHANGELOG says:
* Updating Native events to support Firefox 24, 31, 32 and 33
 
So, maybe you could try Firefox 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.
 
I certainly use a shared driver across my features and I share it using DI. There are examples in the Cucumber-JVM project on Github, or.... <book-plug> you could take a look at the long example in our book, available at  https://pragprog.com/book/srjcuc/the-cucumber-for-java-book ;) </book-plug>
 
 
Cheers
Seb
 

Kunal Mehta

unread,
Dec 4, 2014, 6:53:05 AM12/4/14
to cu...@googlegroups.com
Good Morning Aslak,
thanks for the response.

I am able to close the browser instance by using Webdriver only. With community I meant, I support the idea. if you can get it , it will be an instant hit.
Meanwhile I am still stuck with DI implementation , Please suggest further.

with reference to previous points I attempted below code. please ignore reference to  'group', I meant hooks.
Feature: Example
   @finals
   Scenario: another example scenario
    Given This is mandatory step to close the browser
BDD scenarios will remain unimpacted, as there will no hook like @finals link to them. All other scenario can run normally. @finals duty will be only to close the browser once all the BDD scenarios have been executed. Ofcourse feature file name to something which would make it run at last.

What I am not sure is what all implementation need to go in @Before , just so that static browser instance is cleared of cache and cookies from previous scenario run..
TBH, I can live without test not running parallely but least I ll be able to move on from where I am stuck right now. any suggestion in right direction will help.

public 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();
}

}


...

Kunal Mehta

unread,
Dec 4, 2014, 7:10:00 AM12/4/14
to cu...@googlegroups.com
Hello Seb,
Thanks for quick response.

Attempted with 33.0 now, no success yet.
I bought the book few days back for this very reason. As the 'Bank' example starts much earlier in the book, I thought  I will go through that in peace. right now, just implementing what is already available on git repo.
Thanks for publishing this book.
Reply all
Reply to author
Forward
0 new messages