serenity-bdd / serenity-core

Serenity BDD is a test automation library designed to make writing automated acceptance tests easier, and more fun.
http://serenity-bdd.info
Other
721 stars 517 forks source link

Serenity BDD test running twice #3357

Open kavimukh opened 11 months ago

kavimukh commented 11 months ago

Hello,

I have following

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.1.2</version>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>3.1.2</version>
                <configuration>
                    <includes>
                        <include>**/*Test.java</include>
                        <include>**/Test*.java</include>
                        <include>**/*TestSuite.java</include>
                        <include>**/When*.java</include>
                    </includes>
                    <systemPropertyVariables>
                        <webdriver.base.url>${webdriver.base.url}</webdriver.base.url>
                    </systemPropertyVariables>
                    <parallel>classes</parallel>
                    <parallel>methods</parallel>
                    <useUnlimitedThreads>true</useUnlimitedThreads>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>net.serenity-bdd.maven.plugins</groupId>
                <artifactId>serenity-maven-plugin</artifactId>
                <version>${serenity.version}</version>
                <configuration>
                    <tags>${tags}</tags>
                </configuration>
                <executions>
                    <execution>
                        <id>serenity-reports</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>aggregate</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

== Feature file @RunWith(CucumberWithSerenity.class) @CucumberOptions( plugin = {"pretty"}, features = "src/test/resources/features/geo-IP-modal/" ) public class GeoTestSuite { }

==== When I try to run mvn clean verify -Denvironment=chrome_webdriver -Dtags=@mytesttag it run all test 2 times

if I remove @RunWith(CucumberWithSerenity.class) from Feature file then it's running once.

wakaleo commented 11 months ago

What version are you using?

kavimukh commented 11 months ago

@wakaleo 4.0.14 Thanks

wakaleo commented 11 months ago

I can't see anything special in the code you have provided. If it is executing multiple times it is most likely an error in the Maven configuration, or possibly a duplicated runner class.

kavimukh commented 11 months ago

@wakaleo if I remove RunWith(CucumberWithSerenity.class) then it's running once. Apart from that if I run by using this command

I am using this version of Serenity - 4.0.14

mvn clean verify -Dtest=DesktopTestSuite -Denvironment=chrome_webdriver at that time I am getting following error

08:05:57.440 [main] WARN n.s.m.b.PropertyBasedDriverCapabilityRecord - Failed to store browser configuration for {goog:chromeOptions={args=[--remote-allow-origins=*, --start-maximized, --test-type, --no-sandbox, --ignore-certificate-errors, --disable-popup-blocking, --disable-default-apps, --disable-extensions-file-access-check, --incognito, --disable-infobars,--disable-gpu], extensions=[]}, acceptInsecureCerts=false, browserName=chrome} java.io.FileNotFoundException: /Users/harry/myproject-automation/web-automation-testing/target/site/serenity/browser-chrome.properties (No such file or directory) at java.base/java.io.FileOutputStream.open0(Native Method) at java.base/java.io.FileOutputStream.open(FileOutputStream.java:293) at java.base/java.io.FileOutputStream.(FileOutputStream.java:235)

wakaleo commented 11 months ago

What does your class look like when you remove the RunWith?

kavimukh commented 11 months ago

This is my feature file

This is suite file

https://github.com/RunWith(CucumberWithSerenity.class)
@CucumberOptions(
plugin = {"pretty"},
features = "src/test/resources/features/geo-IP-modal/"
)
public class GeoTestSuite {
}

Scenario Outline: Validate Geo IP Modal QB Online Page
    Given Page <URL> is loaded

===

 @Given("Page {word} is loaded")
    public void pageURLIsLoaded(String pageURL) throws MalformedURLException {
        System.out.println("Navigating to => "+pageURL);
        commonActions.navigateTo(pageURL);
    }

===

 public void navigateTo(String goToURL) throws MalformedURLException {
        getDriver().navigate().to(goToURL);
        untilPageReadyState(getDriver(), Duration.ofSeconds(3));
    }

===

This is my serenity.conf file

  chrome_webdriver {
    webdriver {
      driver = chrome
    }
    headless.mode = false
     #
     # Chrome options can be defined using the chrome.switches property
     #
     chrome.switches = """--remote-allow-origins=*;--start-maximized;--test-type;--no-sandbox;--ignore-certificate-errors;--disable-popup-blocking;--disable-default-apps;--disable-extensions-file-access-check;--incognito;--disable-infobars,--disable-gpu"""
   }

When I execute given tag it work but when I give suite name getting error and executing all test suite. mvn clean verify -Denvironment=chrome_webdriver -Dtags=@mytesttag

wakaleo commented 11 months ago

You may have a duplicated runner somewhere in your code base.

mbarua1 commented 8 months ago

I am also having same issue now fyi @wakaleo . did you find any resolution @kavimukh. every test running twice

wakaleo commented 8 months ago

I am also having same issue now fyi @wakaleo . did you find any resolution @kavimukh. every test running twice

It will be related to your Maven or test runner setup. Serenity does not manage test executions - that is done by the testing frameworks (Cucumber or JUnit).

mbarua1 commented 8 months ago

Thanks john! @wakaleo This is my mvn clean verify -Denvironment=“@@@@“ -Dcucumber.filter.tags="@test" serenity:aggregate

mbarua1 commented 8 months ago

@wakaleo - In one feature file I do have two test, i wanted to run only one test through IDE (eclipse), run as 1 cucumber feature , giving a tag @test1 and also used same tag in runner class @test1. for case of 1 cucumber feature both tests were running but in report it says one test ran. And through runner class for @test1, it is running all test cases in my project directory. please advise me what dependencies or plug in need to install image !

wakaleo commented 8 months ago

Please ask any general questions that are not related to the original post in the Discussions section.

mbarua1 commented 8 months ago

@here- Finally all issues got resolved, parallel in four node, no test running twice. Had to browse a lot and making a combination of different solution, using different version of all jars, with Serenity 4.0.18, Junit5. Thank you everyone for sharing all ideas