Cucumber-JVM - execution issue

49 views
Skip to first unread message

Den Dem

unread,
Jul 21, 2017, 8:12:26 AM7/21/17
to Cukes
Hello,

I am facing issue as when I try to execute feature file with several scenarios, for some reason after executing 1st scenario, browser does not close in order to run next scenario. 
It just sits on last step, but tries to execute rest of scenarios

However, if to run, single scenario, this works as expected.

I do not use @After hook as I am passing info in Runtime.addShutdownHook with BrowserCleanup class 

Added screenshots of framework structure with Browser setup and Webdriver with BrowserCleanup class as well as log from execution. 



WebdriverFactory.png
BrowserFactory.png
structure.png
mvn.txt

Justin Radcliffe

unread,
Jul 21, 2017, 8:41:31 AM7/21/17
to Cukes
I don't see a shot of your Hooks file but here's what mine looks like :

I think you'll want to put the shutdown hook within your @Before or @After but that only when the jvm is shutdown. So I do the following to make sure I dont leave the browser up at the end of all my test.
 
  @Before
   
public void loginToGaa(Scenario scenario) {
        almLogin
();
       
       
if (!TagInfo.runThroughApi(scenario) && !isLoginCompleted()) {
           
Runtime.getRuntime().addShutdownHook(new Thread() {
               
public void run() {
                    LOGGER
.debug("LOGGING OUT.");
                   
new WindowsExecutionUtility().killChromeAndChromeDriver();
               
}
           
});

           
new WindowsExecutionUtility().killChromeAndChromeDriver();
            LOGGER
.debug("LOGGING IN");
            gAAKeywords
.OPEN_GAA("autURL");
            gAAKeywords
.LOGIN_TO_GAA("UserName", "Password");


           
PrepareReport.addReportPass(MessageConstants.LOGIN_TO_GAA);
            setLoginCompleted
(true);
       
}
   
}


if you want to have a new broswer at the end of each test, you should add it in the @After

@After
    public void wrapTest(Scenario scenario) {

        try {
            Driver.webdriver.quit();
        } catch (Exception | Error e) {
            LOGGER.error("wrapTest : "+e.getLocalizedMessage());
        }

    }

Den Dem

unread,
Jul 21, 2017, 8:54:55 AM7/21/17
to Cukes
Hi Justin,
Yes, I added Hook screenshot. Please advise, so what you are saying it is better to put addShutdown in @Beforehook and also add into @After driver.quit?
hooks.png

Den Dem

unread,
Jul 21, 2017, 9:08:23 AM7/21/17
to Cukes
@Justin,
I tried to move addShutdown hook into @Before and for @After
Driver.webdriver.quit();

Tried to run, so after first scenario browser closed, but new instance of the browser did not started for next scenario.

Justin Radcliffe

unread,
Jul 21, 2017, 9:18:43 AM7/21/17
to Cukes
You'll have to add WebdriverFactory.createWebdriver(); in your @Before method and then it will create a new driver every run as well.

Den Dem

unread,
Jul 21, 2017, 9:34:53 AM7/21/17
to Cukes
Yes, I added that in the @Before, execution goes after 1st scenario and closes browser and initiated another instance, but url is not being passed and browser instance sits and then for each scenario another instance of browser opens without closing previous one with blank url.

Den Dem

unread,
Jul 21, 2017, 10:21:27 AM7/21/17
to Cukes
I forgot to mention as I have Driver class

public class Driver {

public static WebDriver webdriver;

public synchronized static WebDriver getCurrentDriver() {

if (webdriver == null) {
webdriver = WebdriverFactory.createWebdriver();
webdriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
webdriver.manage().timeouts().pageLoadTimeout(100, TimeUnit.SECONDS);
}
return webdriver;
}

tha is used in 

action classes

public class Expedia_Action extends Config {


static WebDriver driver = Driver.getCurrentDriver();

static WebDriverWait wait = new WebDriverWait(driver, 10);

public static void searchForFlight(String flightOrigin, String flightDestination) throws InterruptedException {
driver.get(expedia_baseUrl);

it has 
 webdriver = WebdriverFactory.createWebdriver();

so I do nto think I need to add same into @Before hook as it is initiated or no?

Justin Radcliffe

unread,
Jul 21, 2017, 11:34:37 AM7/21/17
to cu...@googlegroups.com
However you are able to get the url and broswer, you can move that to the Before hook.

--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to a topic in the Google Groups "Cukes" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/cukes/FeZ9EZSqfTk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to cukes+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Den Dem

unread,
Jul 21, 2017, 1:02:00 PM7/21/17
to Cukes, justinr...@gmail.com
I able to get for 1st scenario only, rest are having blank urls. Passing url is first step within scenario
To unsubscribe from this group and all its topics, send an email to cukes+un...@googlegroups.com.

Justin Radcliffe

unread,
Jul 21, 2017, 3:17:10 PM7/21/17
to Den Dem, Cukes
Got it, I think you just have to change how you setup your login method and how you pull the URL from your constant/property.

Hopefully the point of closing and getting a new driver each scenario is at least resolved.

Den Dem

unread,
Jul 21, 2017, 7:59:08 PM7/21/17
to Cukes, demd...@gmail.com, justinr...@gmail.com
I thought so, would you have a good template for such?
Reply all
Reply to author
Forward
0 new messages