Skip to content

WebDriver 5: I.seeInField fails in Firefox: Cannot read property 'indexOf' of null #1558

Closed

Description

@mirao

It doesn't fail with WebDriver 4.
If you have WebDriver 5 and:

  • Selenium server <= 3.8.1 started with the option -enablePassThrough false, then test passes.
  • latest Selenium server, then test fails.

So possible workaround for Firefox is downgrade of WebDriver to ver. 4 or downgrade to Selenium server 3.8.1 (the last version which provides -enablePassThrough false).

Chrome isn't affected in any configuration.

What are you trying to achieve?

I.seeInField("#search_input_react", "WebDriver")

What do you get instead?

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

$ codeceptjs run My_test.js --profile firefox --verbose
2019-03-11T19:15:51.487Z DEBUG @wdio/config: @wdio/sync not found, running tests asynchronous
CodeceptJS v2.0.7
Using test root "/home/mira/workspace/mycodeceptjs/tests/seeinfield"
Helpers: WebDriver
Plugins: screenshotOnFail

My --
    [1] Starting recording promises
    Emitted | suite.before ([object Object])
  One
    Emitted | test.before ([object Object])
    Emitted | test.start ([object Object])
    Emitted | step.before (I am on page "https://codecept.io/quickstart")
    Emitted | step.after (I am on page "https://codecept.io/quickstart")
    Emitted | step.before (I fill field "#search_input_react", "WebDriver")
    Emitted | step.after (I fill field "#search_input_react", "WebDriver")
    Emitted | step.before (I see in field "#search_input_react", "WebDriver")
    Emitted | step.after (I see in field "#search_input_react", "WebDriver")
    Emitted | step.start (I am on page "https://codecept.io/quickstart")
    I am on page "https://codecept.io/quickstart"
    Emitted | step.passed (I am on page "https://codecept.io/quickstart")
    Emitted | step.finish (I am on page "https://codecept.io/quickstart")
    Emitted | step.start (I fill field "#search_input_react", "WebDriver")
    I fill field "#search_input_react", "WebDriver"
    Emitted | step.passed (I fill field "#search_input_react", "WebDriver")
    Emitted | step.finish (I fill field "#search_input_react", "WebDriver")
    Emitted | step.start (I see in field "#search_input_react", "WebDriver")
    I see in field "#search_input_react", "WebDriver"
    [1] Error | TypeError: Cannot read property 'indexOf' of null
    Emitted | step.failed (I see in field "#search_input_react", "WebDriver")
    Emitted | step.finish (I see in field "#search_input_react", "WebDriver")
    [1] Error | TypeError: Cannot read property 'indexOf' of null
    [1] Starting <teardown> session
    Emitted | test.failed ([object Object])
    Emitted | test.finish ([object Object])
    [1] <teardown> Stopping recording promises
 › <screenshotOnFail> Test failed, saving screenshot
 › Screenshot has been saved to /home/mira/workspace/mycodeceptjs/tests/seeinfield/output/One.failed.png
  ✖ FAILED in 8903ms

    [2] Starting recording promises
    Emitted | test.after ([object Object])
    Emitted | suite.after ([object Object])

-- FAILURES:

  1) My
       One:
     Cannot read property 'indexOf' of null
  
  Scenario Steps:
  
  - I.seeInField("#search_input_react", "WebDriver") at Test.Scenario (My_test.js:6:7)
  - I.fillField("#search_input_react", "WebDriver") at Test.Scenario (My_test.js:5:7)
  - I.amOnPage("https://codecept.io/quickstart") at Test.Scenario (My_test.js:4:7)
  
  TypeError: Cannot read property 'indexOf' of null
      at Object.comparator (/home/mira/workspace/mycodeceptjs/node_modules/codeceptjs/lib/assert/include.js:16:23)
      at InclusionAssertion.assert (/home/mira/workspace/mycodeceptjs/node_modules/codeceptjs/lib/assert.js:36:36)
      at browser.getElementAttribute.then.res (/home/mira/workspace/mycodeceptjs/node_modules/codeceptjs/lib/helper/WebDriver.js:2159:151)
      at process._tickCallback (internal/process/next_tick.js:68:7)


  FAIL  | 0 passed, 1 failed   // 14s
    Emitted | global.result ([object Object])
    Emitted | global.after ([object Object])

Provide test source code if related

Scenario("One", (I) => {
    I.amOnPage("https://codecept.io/quickstart");
    I.fillField("#search_input_react", "WebDriver");
    I.seeInField("#search_input_react", "WebDriver");
});

Details

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

Activity

  1. kobenguyent commented on Mar 15, 2019

    @kobenguyent
    Collaborator
    Scenario('Test @1', (I) => {
        I.amOnPage("https://www.w3schools.com/html/html_forms.asp");
        I.seeInField('input[name="firstname"]', "WebDriver1");
    });
    

    I think this function works fine with element that has value attribute. In your example, there is no such value attribute. Try my example. Anyway we should handle this better :)

    Test --
      Test @1
        I am on page "https://codecept.io/quickstart"
        I fill field "#search_input_react", "WebDriver1"
        I see in field "#search_input_react", "WebDriver1"
      ✖ FAILED in 7150ms
    
    
    -- FAILURES:
    
      1) Test
           Test @1:
         Element #search_input_react has no value attribute
      
    
  2. mirao commented on Mar 15, 2019

    @mirao
    ContributorAuthor

    @peterngtr You're right, your test case works. Thank you

    I hit the issue because I want to test that on my login page there is no string in username and password fields after logout or after loading of login page: I.seeInField(username_input, "");
    And as there is no value attribute in those elements, the test fails (only with new Selenium server).

    It's not a big issue for me, because I stay running older Selenium server (some other issues block upgrade of Selenium in my environment).

  3. mirao commented on Mar 15, 2019

    @mirao
    ContributorAuthor

    I hit the issue because I want to test that on my login page there is no string in username and password fields after logout or after loading of login page: I.seeInField(username_input, "");

    Well, now I can see that I test an empty value in text input wrong way. Docs says that "seeInField() checks that the given input field or textarea equals to given value."
    But I found out that it actually tests only if the argument is a substring of the actual value. Therefore I.seeInField(username_input, ""); always passes which is wrong.

    This variant should do what I want:

    const value = await I.grabValueFrom("#search_input_react");
    require("assert").strictEqual(value.toString(), "");

    It works well for the case when a string is filled into the input (then the test fails) and also for the case when nothing is typed into the input (then test passes)

  4. schmunk42 commented on Jun 5, 2019

    @schmunk42
    Contributor

    We had a similar issue, while manipulating values of inputs with JavaScript with json-editor, our tests failed since upgrading to Firefox Selenium 3.x (https://travis-ci.org/json-editor/json-editor/builds/541217140#L596)

    From looking through the CodedeptJS source code I think I.seeInField really looks at the HTML-source and since there's no value attribute it fails.
    In contrast to grabValueFrom or waitForValue which selects the element from the DOM and then retrieves value from it (via JavaScript)

    Example:

        I.waitForValue("[name='root[0][location][city]']", 'Stuttgart');
        // this does not work --> I.seeInField("[name='root[0][location][city]']", 'Stuttgart');
    

    json-editor/json-editor@144393e

  5. mirao commented on Dec 6, 2019

    @mirao
    ContributorAuthor

    It works for me with CodeceptJS 2.3.6 and WebDriverIO@5.16.13

    • Browsers

      • Google Chrome 78.0.3904.108
      • Mozilla Firefox 70.0.1
    • Selenium:

      • Server: 3.141.59
      • Chrome webdriver: 78.0.3904.105
      • Firefox webdriver: 0.26.0
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