1

For example, tried to locale a web page element by ID and it was not there - why Cucumber repeats the Java output (in addition to - expected - its own scenario/feature/steps failure text) and can I prevent that?


    Testing started at 4:51 PM ...
    Nov 28, 2018 4:51:48 PM org.openqa.selenium.remote.ProtocolHandshake createSession
    INFO: Detected dialect: OSS
    ================== Beginning ===================================
    org.openqa.selenium.NoSuchElementException:
    >>>ERROR. There is no Translation status column

    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: 'T1650', ip: '10.68.1.61', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_144'
    Driver info: driver.version: unknown
      at pageObjects.VerificationPage.findStatusIcon(VerificationPage.java:40)
      at stepDefinitions.VerificationPageSteps.user_verifies_translation_status(VerificationPageSteps.java:24)
      at *.Then BitBucket user verifies Translation Status(C:/Verification/src/test/resources/features/Verification_Test.feature:11)
    ******************** Ending ***********************************
    Failed scenarios:
    c:/Verification/src/test/resources/features/Verification_Test.feature:8 # Scenario: User checks a repository

    1 Scenarios (1 failed)
    3 Steps (1 failed, 2 passed)
    0m20.931s

    org.openqa.selenium.NoSuchElementException: 

    >>>ERROR. There is no Translation status column

    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: 'T1650', ip: '10.68.1.61', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_144'
    Driver info: driver.version: unknown
      at pageObjects.VerificationPage.findStatusIcon(VerificationPage.java:40)
      at stepDefinitions.VerificationPageSteps.user_verifies_translation_status(VerificationPageSteps.java:24)
      at *.Then BitBucket user verifies Translation Status(C:/Verification/src/test/resources/features/Verification_Test.feature:11)

    Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8

    Process finished with exit code 1/

step definition (looks for a special column in Branches page of Bitbucket (stash)):


public class TranslationVerificationPageSteps {
    private TestContext testContext;
    private TranslationVerificationPage translationVerificationPage;

    public TranslationVerificationPageSteps(TestContext context) {
        testContext = context;
        translationVerificationPage = testContext.getPageObjectManager().getTranslationVerificationPage();
    }

    @Then("^BitBucket user verifies Translation Status$")
    public void user_verifies_translation_status(){
        translationVerificationPage.findTranslationStatusIcon();
    }
}

Implementation (just to show that I tried other ways - the majority of those commented out variants also produce that effect - Java/Selenium exception text is shown twice - or Java error text is not shown at all):


try {
            translationColumn = driver.findElement(By.id("translation-status-branch-list-col"));
        } catch (NoSuchElementException e) {

            throw new NoSuchElementException("\n\n>>>ERROR. There is no Translation status column\n");


    // variant 2
    //Assert.fail("\n\n>>>ERROR. Test failed: no Translation status column\n\n");

// variant 3
  // throw new AssertionError("\n\n>>>ERROR. Test failed: no Translation status column\n\n");

  }

// variant 4
//            try {
//                Assert.assertNotNull(translationColumn);
//
//            } catch (AssertionError foo) {
//                System.out.println("\n\nTest failed: no Translation status column\n\n");
//                //e.printStackTrace();
//                //System.out.println(e.getMessage());
//
//            }
  • Please add step definition code – Alexey R. Nov 30 '18 at 10:56
  • Added step definition to my question above – Paul G Dec 1 '18 at 19:44
  • There is no point in trapping an exception to just rethrow it, since you are changing the exception message, if you catch it then wrap it in a new custom exception, otherwise ignore it and let your test framework, cucumber in this case report it. – Martin Spamer Dec 2 '18 at 13:09
  • I did rethrow because catch (NoSuchElementException e) did not cause (expected) abrupted failure of my test – Paul G Dec 3 '18 at 16:29
1

I did some debugging and it looks like I can answer my own question - though, IMHO, it's a bug in Cucumber:

1) First, it's Java/Selenium failure text - it's the text (given in Question's "code" part) between
================== Beginning ===
and
================== Ending =

2) Now, Cucumber starts to process the failure and prints out the information -

in this.printSummary() method (Runtime.class):

a) prints out failed Step/Feature information - which is good and expected

b) prints out - again :-( - same Java/Selenium failure text that has been already printed.


public void run() throws IOException {
        List features = this.runtimeOptions.cucumberFeatures(this.resourceLoader);
        Formatter formatter = this.runtimeOptions.formatter(this.classLoader);
        Reporter reporter = this.runtimeOptions.reporter(this.classLoader);
        StepDefinitionReporter stepDefinitionReporter = this.runtimeOptions.stepDefinitionReporter(this.classLoader);
        this.glue.reportStepDefinitions(stepDefinitionReporter);
        Iterator var5 = features.iterator();

        while(var5.hasNext()) {
            CucumberFeature cucumberFeature = (CucumberFeature)var5.next();
            cucumberFeature.run(formatter, reporter, this);
        }

        formatter.done();
        formatter.close();

        this.printSummary();
    }

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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