Closing the browser after for each story

1,046 views
Skip to first unread message

Николай Стрельцов

unread,
Jun 3, 2016, 12:44:46 PM6/3/16
to Serenity BDD Users Group
24 Jul 2015 commit https://github.com/serenity-bdd/serenity-jbehave/commit/28222990f9375ce7d0939c77d32f7ae44a8aea82
Now it does not work runSerenity().inASingleSession(), the browser closes after each story

Now we use Thucydides there is no such problem. But we want to go Serenity. The bug unSerenity().inASingleSession() does not allow us this.

Please fix.

John Ferguson SmartSmart

unread,
Jun 3, 2016, 1:05:18 PM6/3/16
to Serenity BDD Users Group, Николай Стрельцов
Originally, I believe it failed to close the browser at the end of the test suite. Do you see this behaviour with your Thucydides tests?

___________________________________________________
John Smart | Wakaleo Consulting  |  +44 7398 832273
Making smart teams collaborate better

http://johnfergusonsmart.com  | rea...@johnfergusonsmart.com
___________________________________________________

--
You received this message because you are subscribed to the Google Groups "Serenity BDD Users Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to thucydides-use...@googlegroups.com.
To post to this group, send email to thucydid...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Harry King

unread,
Jun 4, 2016, 12:32:26 PM6/4/16
to Serenity BDD Users Group
An alternate approach would be to add an @AfterStory annotation in your Test Suite which triggers a method containing getDriver.quit();

Николай Стрельцов

unread,
Jun 7, 2016, 5:20:47 AM6/7/16
to Serenity BDD Users Group, nikolas...@gmail.com
Thucydides behave properly. Incorrect work serenity
This is the same problem https://groups.google.com/forum/#!topic/thucydides-users/GI1uZG2d8Ug


пятница, 3 июня 2016 г., 20:05:18 UTC+3 пользователь John Smart написал:
Message has been deleted

Николай Стрельцов

unread,
Jun 8, 2016, 7:27:35 AM6/8/16
to Serenity BDD Users Group
Ok, example
StoriesRunner.class
public class StoriesRunner extends SerenityStories{


    
public StoriesRunner() {
        runSerenity
().inASingleSession();
    
}


    
@Override
    
public List<String> storyPaths() {
        
return new StoryFinder().findPaths(codeLocationFromClass(this.getClass()).getFile(), asList("**/example1.story", "**/example2.story"), null);
    
}


    
public static WebDriver getWebDriver() {
        
return ThucydidesWebDriverSupport.getDriver();
    
}
}
Steps
public class MainSteps extends ScenarioSteps{
    
@Step
    
public void stepExample(){
        
StoriesRunner.getWebDriver().get("http://www.google.com");
    
}


    
@When("example step")
    
public void behaveExample(){
        stepExample
();
    
}
}
Stories
example1
Meta:


Scenario: example1
When example step
example2
Meta:


Scenario: example2
When example step


pom.xml run section
<build>
        
<resources>
            
<resource>
                
<directory>${basedir}/src/main/java</directory>
                
<excludes>
                    
<exclude>**/*.java</exclude>
                
</excludes>
                
<filtering>false</filtering>
            
</resource>
            
<resource>
                
<directory>${basedir}/src/main/resources</directory>
                
<filtering>false</filtering>
            
</resource>
            
<resource>
                
<directory>${basedir}/src/test/java</directory>
                
<filtering>false</filtering>
            
</resource>
            
<resource>
                
<directory>${basedir}/src/test/resources</directory>
                
<filtering>false</filtering>
            
</resource>
        
</resources>
        
<plugins>
            
<plugin>
                
<groupId>org.jbehave</groupId>
                
<artifactId>jbehave-maven-plugin</artifactId>
                
<version>3.8</version>
                
<executions>
                    
<execution>
                        
<id>run-stories</id>
                        
<phase>integration-test</phase>
                        
<configuration>
                            
<includes>
                                
<include>**/StoriesRunner.java</include>
                            
</includes>
                            
<executorsClass>org.jbehave.core.embedder.executors.SameThreadExecutors</executorsClass>
                            
<systemProperties>
                                
<property>
                                    
<name>file.encoding</name>
                                    
<value>${project.build.sourceEncoding}</value>
                                
</property>
                            
</systemProperties>
                            
<metaFilters>
                                
<metaFilter>-skip</metaFilter>
                            
</metaFilters>
                            
<ignoreFailureInStories>true</ignoreFailureInStories>
                            
<ignoreFailureInView>true</ignoreFailureInView>
                        
</configuration>
                        
<goals>
                            
<goal>run-stories-as-embeddables</goal>
                        
</goals>
                    
</execution>
                
</executions>
                
<dependencies>
                    
<dependency>
                        
<groupId>com.google.guava</groupId>
                        
<artifactId>guava</artifactId>
                        
<version>17.0</version>
                    
</dependency>
                    
<dependency>
                        
<groupId>log4j</groupId>
                        
<artifactId>log4j</artifactId>
                        
<version>1.2.17</version>
                    
</dependency>
                
</dependencies>
            
</plugin>
        
</plugins>
    
</build>

mvn command from run
mvn clean install

After story example1.story browser closes. But it is worth runSerenity().inASingleSession();

Please bug fix.

Николай Стрельцов

unread,
Jun 8, 2016, 8:22:04 AM6/8/16
to Serenity BDD Users Group
SerenityReporter.class
public void afterStory(boolean given) {
        logger
.debug("afterStory " + given);
        shouldNestScenarios
(false);
       
if (given) {
            givenStoryMonitor
.exitingGivenStory();
            givenStoryDone
(currentStory());
       
} else {
            closeBrowsersForThisStory
();
           
if (isAfterStory(currentStory())) {
                generateReports
();
           
} else if (!isFixture(currentStory()) && (!isAStoryLevelGiven(currentStory()))) {
               
StepEventBus.getEventBus().testSuiteFinished();
                clearListeners
();
           
}
       
}


        storyStack
.pop();
   
}
    private void closeBrowsersForThisStory() {
        if (drivers.containsKey(currentStory())) {
            drivers.get(currentStory()).close();
            drivers.get(currentStory()).quit();
            drivers.remove(currentStory());
        }
    }

ThucydidesReporter.class
public void afterStory(boolean given) {
        shouldNestScenarios
(false);
       
if (given) {
            givenStoryMonitor
.exitingGivenStory();
            givenStoryDone
(currentStory());
       
} else {
           
if (isAfterStory(currentStory())) {
                closeBrowsersForThisStory
();
                generateReports
();
           
} else if (!isFixture(currentStory()) && !given && (!isAStoryLevelGiven(currentStory()))) {
               
StepEventBus.getEventBus().testSuiteFinished();
                clearListeners
();
           
}
       
}
        storyStack
.pop();
   
}
    private void closeBrowsersForThisStory() {
        if (!systemConfiguration.getUseUniqueBrowser()) {
            ThucydidesWebDriverSupport.closeAllDrivers();
        }
    }

Reply all
Reply to author
Forward
0 new messages