Skip to content

WebDriver 5: seeTextEquals passes for any string if element is empty #1561

Closed

Description

@mirao

It works as expected with WebDriver 4 and doesn't work with WebDriver 5.

What are you trying to achieve?

I want to test if the exact text "Authentication failed." appears in the p subelement of

<div class="ui error message">
  <div class="content">
    <p></p>
  </div>
</div>

Let's say now there is no value in p.
So I.seeTextEquals("Authentication failed.", ".error.message"); should fail.

What do you get instead?

Provide console output if related. Use --verbose mode for more details.

This test passes:

Emitted | step.start (I see text equals "Authentication failed.", ".error.message")
    I see text equals "Authentication failed.", ".error.message"
    › [SmartWait (20000ms)] Locating .error.message in 20000
    Emitted | step.passed (I see text equals "Authentication failed.", ".error.message")
    Emitted | step.finish (I see text equals "Authentication failed.", ".error.message")

Provide test source code if related

    I.seeTextEquals("Authentication failed.", ".error.message");

Details

  • CodeceptJS version: 2.0.7
  • NodeJS Version: 10.15.1
  • Operating System: Ubuntu 18.10
  • WebDriver: 5.7.2
  • Configuration file:
exports.config = {
    tests: "./*_test.js",
    output: "./output",
    helpers: {
        WebDriver: {
            url: "http://localhost",
            browser: process.profile || "chrome",
            waitForTimeout: 20000,
            smartWait: 20000
        }
    },
    include: {
        I: "./steps_file.js"
    },
    bootstrap: null,
    mocha: {},
    name: "demo"
};

Activity

  1. mirao commented on Mar 13, 2019

    @mirao
    ContributorAuthor

    Correct behavior is with WebDriver 4:

    Emitted | step.start (I see text equals "Authentication failed.", ".error.message")
        I see text equals "Authentication failed.", ".error.message"
        › [SmartWait (20000ms)] Locating .error.message in 20000
        [1] Error | Error: expected element .error.message "Authentication failed." to equal ""
        Emitted | step.failed (I see text equals "Authentication failed.", ".error.message")
        Emitted | step.finish (I see text equals "Authentication failed.", ".error.message")
        [1] Error | Error: expected element .error.message "Authentication failed." to equal ""
  2. kobenguyent commented on Mar 14, 2019

    @kobenguyent
    Collaborator

    Found the issue and fixed it -> #1564

    Test --
    abc,
      ✖ Test @test in 12252ms
    
    -- FAILURES:
    
      1) Test
           Test @test:
         expected element [id="site-logo"] "abc" to equal ""
    
      Scenario Steps:
    
      - I.seeTextEquals("abc", "[id="site-logo"]") at Test.Scenario (tests/smokeCheck/linkedin.js:20:5)
      - I.amOnPage("https://codecept.discourse.group/") at Test.Scenario (tests/smokeCheck/linkedin.js:19:5)
    
    
    
      Run with --verbose flag to see NodeJS stacktrace
    
    
      FAIL  | 0 passed, 1 failed   // 13s
    
  3. mirao commented on Mar 22, 2019

    @mirao
    ContributorAuthor

    @peterngtr, I've upgraded CodeceptJS to 2.0.8 and my test started failing. I.seeTextEquals doesn't work with empty string.
    An example how to reproduce it:

    -- FAILURES:
    
      1) My
           One:
         expected element #ember7 "" to equal ""
      
      Scenario Steps:
      
      - I.seeTextEquals("", "#ember7") at Test.Scenario (My_test.js:7:7)
      - I.amOnPage("https://codecept.discourse.group/") at Test.Scenario (My_test.js:6:7)
    

    It fails with webdriverio@5 and passes with webdriverio@4

  4. kobenguyent commented on Mar 23, 2019

    @kobenguyent
    Collaborator

    Well, I’ll take a look @mirao

  5. kobenguyent commented on Mar 23, 2019

    @kobenguyent
    Collaborator

    @mirao sorry, the last patch didn't work properly. I found the root cause, the problem is when codeceptjs try to get the text from the locator, it returns the array

    const selected = await forEachAsync(res, async el => this.browser.getElementText(getElementId(el)));
    

    In this case, the locator has no text it returns an empty array. However the the text you want to compare is a string. And the equals method is

    const comparator = function (a, b) {
          return a === b;
        };
    

    and by this, it returns false, even though both are empty but one is string, one is array.

    Last but not least, fix is here -> #1576

  6. mirao commented on Apr 1, 2019

    @mirao
    ContributorAuthor

    OK, thanks for your effort. I guess it will be released in 2.0.9, am I right?

  7. kobenguyent commented on Apr 1, 2019

    @kobenguyent
    Collaborator

    I guess so if it’s merged soon by @DavertMik

  8. mirao commented on Dec 7, 2019

    @mirao
    ContributorAuthor

    It works well with CodeceptJS 2.3.6, WebDriverIO 5.16.13

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions