2

I am using Cucumber Page Object model to execute my tests. Here is my POM file:-

<dependencies>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>1.2.0</version>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>1.2.0</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>2.44.0</version>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.11</version>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.17</version>
    </dependency>
    <dependency>
        <groupId>io.github.bonigarcia</groupId>
        <artifactId>webdrivermanager</artifactId>
        <version>3.0.0</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
        <version>3.7</version>
    </dependency>
</dependencies>

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.1</version>
                <configuration>
                    <testFailureIgnore>true</testFailureIgnore>
                </configuration>
            </plugin>
            <plugin>
                <groupId>net.masterthought</groupId>
                <artifactId>maven-cucumber-reporting</artifactId>
                <version>3.15.0</version>
                <executions>
                    <execution>
                        <id>execution</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <projectName>KRUIS UI Selenium Regression</projectName>
                            <outputDirectory>${project.build.directory}/cucumber-JVM-reports</outputDirectory>
                            <cucumberOutput>${project.build.directory}/cucumber-reports/Cucumber.json</cucumberOutput>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
    </plugins>
</build>

My issue is when certain tests fail , selenium exception is reported twice. for eg.

org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"id","selector":"name"}
(Session info: chrome=71.0.3578.98)
  (Driver info: chromedriver=72.0.3626.7 (efcef9a3ecda02b2132af215116a03852d08b9cb),platform=Windows NT 10.0.17134 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:19:58.91Z'
System info: host: 'LAPTOP-BEN', ip: '10.0.75.1', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_181'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, acceptSslCerts: false, applicationCacheEnabled: false, browserConnectionEnabled: false, browserName: chrome, chrome: {chromedriverVersion: 72.0.3626.7 (efcef9a3ecda02..., userDataDir: C:\Users\Shweta\AppData\Loc...}, cssSelectorsEnabled: true, databaseEnabled: false, goog:chromeOptions: {debuggerAddress: localhost:58607}, handlesAlerts: true, hasTouchScreen: false, javascriptEnabled: true, locationContextEnabled: true, mobileEmulationEnabled: false, nativeEvents: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, proxy: Proxy(), rotatable: false, setWindowRect: true, takesHeapSnapshot: true, takesScreenshot: true, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unexpectedAlertBehaviour: ignore, unhandledPromptBehavior: ignore, version: 71.0.3578.98, webStorageEnabled: true}
Session ID: 708ec7bfeda8ac9a70bc6a5490a39691
*** Element info: {Using=id, value=name}
  at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
  at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
  at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
  at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
  at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)
  at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
  at org.openqa.selenium.remote.http.JsonHttpResponseCodec.reconstructValue(JsonHttpResponseCodec.java:40)
  at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:80)
  at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:44)
  at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
  at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
  at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:548)
  at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:322)
  at org.openqa.selenium.remote.RemoteWebDriver.findElementById(RemoteWebDriver.java:368)
  at org.openqa.selenium.By$ById.findElement(By.java:188)
  at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:314)
  at org.openqa.selenium.support.pagefactory.DefaultElementLocator.findElement(DefaultElementLocator.java:69)
  at org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler.invoke(LocatingElementHandler.java:38)
  at com.sun.proxy.$Proxy15.click(Unknown Source)
  at pageobjects.Organisation_PageObjects.create_and_save_org_detail(Organisation_PageObjects.java:64)
  at step_definitions.Org_Steps.edit_org(Org_Steps.java:40)
  at ✽.Then I edited the organisation having 5 characters(C:/Users/Shweta/Git Projects/KRUIS-UI-Selenium-Tests/src/test/resources/features/CRUD Organisations.feature:12)

Skipped step

Skipped step
driver ChromeDriver: chrome on XP (708ec7bfeda8ac9a70bc6a5490a39691)

Failed scenarios:
C:/Users/Shweta/Git Projects/KRUIS-UI-Selenium-Tests/src/test/resources/features/CRUD Organisations.feature:8 # Scenario: CRUD Organisation details

1 Scenarios (1 failed)
9 Steps (1 failed, 2 skipped, 6 passed)
0m40.064s

org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"id","selector":"name"}
  (Session info: chrome=71.0.3578.98)
  (Driver info: chromedriver=72.0.3626.7 (efcef9a3ecda02b2132af215116a03852d08b9cb),platform=Windows NT 10.0.17134 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:19:58.91Z'
System info: host: 'LAPTOP-BEN', ip: '10.0.75.1', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_181'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, acceptSslCerts: false, applicationCacheEnabled: false, browserConnectionEnabled: false, browserName: chrome, chrome: {chromedriverVersion: 72.0.3626.7 (efcef9a3ecda02..., userDataDir: C:\Users\Shweta\AppData\Loc...}, cssSelectorsEnabled: true, databaseEnabled: false, goog:chromeOptions: {debuggerAddress: localhost:58607}, handlesAlerts: true, hasTouchScreen: false, javascriptEnabled: true, locationContextEnabled: true, mobileEmulationEnabled: false, nativeEvents: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, proxy: Proxy(), rotatable: false, setWindowRect: true, takesHeapSnapshot: true, takesScreenshot: true, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unexpectedAlertBehaviour: ignore, unhandledPromptBehavior: ignore, version: 71.0.3578.98, webStorageEnabled: true}
Session ID: 708ec7bfeda8ac9a70bc6a5490a39691
*** Element info: {Using=id, value=name}
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
    at org.openqa.selenium.remote.http.JsonHttpResponseCodec.reconstructValue(JsonHttpResponseCodec.java:40)
    at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:80)
    at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:44)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:548)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:322)
    at org.openqa.selenium.remote.RemoteWebDriver.findElementById(RemoteWebDriver.java:368)
    at org.openqa.selenium.By$ById.findElement(By.java:188)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:314)
    at org.openqa.selenium.support.pagefactory.DefaultElementLocator.findElement(DefaultElementLocator.java:69)
    at org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler.invoke(LocatingElementHandler.java:38)
    at com.sun.proxy.$Proxy15.click(Unknown Source)
    at pageobjects.Organisation_PageObjects.create_and_save_org_detail(Organisation_PageObjects.java:64)
    at step_definitions.Org_Steps.edit_org(Org_Steps.java:40)
    at ✽.Then I edited the organisation having 5 characters(C:/Users/Shweta/Git Projects/KRUIS-UI-Selenium-Tests/src/test/resources/features/CRUD Organisations.feature:12)

Process finished with exit code 1

I dont understand the reason of it and want to avoid this duplication.

0

1 Answer 1

2

This is the specific of frameworks which build up Cucumber. I believe you run your test with help of @RunWith(Cucumber.class). If you look into that class you will find the following:

public void run(RunNotifier notifier) {
    super.run(notifier);
    this.jUnitReporter.done();
    this.jUnitReporter.close();
    this.runtime.printSummary();
}

that just prints the summary of executed tests. If you drill further you will find that

public void printSummary() {
    (new SummaryPrinter(System.out)).print(this);
}

which means it is not even configurable. It just takes your System.out as the output. That was about "black" text.

The red text that you can see is just the errors that your code encounters in run time. So that you get the error twice. First time when you get it in run time and the second one when you get the execution summary.

I wouldn't take any actions and accept the things as is. However if you still need to have one error, you can copy Cucumber class code to something like CucumberNoSummary (do not forget to rename constructor respectively), in that new class, remove the line this.runtime.printSummary(); and run your tests with @RunWith(CucumberNoSummary.class). However I strongly not recommend to do that.

You also can migrate your execution to TestNg. This is a bit more tricky but produces nicer output.

1
  • 1
    Thank you @Alexey R for taking out time to dig into this. This was driving me insane. I will migrate to TestNg as I want to avoid this unnecessary duplication.
    – Sjain
    Commented Jan 16, 2019 at 8:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.