nightwatch.js - Элемент не может быть найден - PullRequest
0 голосов
/ 01 октября 2019

У меня проблема с обнаруженными объектами.

мой env:

  1. Элемент списка
  2. chromedriver and chrome - 77
  3. selenium-server-standalone-3.141.59.jar
  4. node.js - 10.16.3
  5. java jdk - 1.8.0.221

test: demo.js

module.exports = {
  'Demo test Ecosia.org': function (browser) {
    browser
      .url('https://www.ecosia.org/')
      .assert.titleContains('Ecosia')
      .assert.visible('input[type=search]')
      .setValue('input[type=search]', 'nightwatch')
      .assert.visible('button[type=submit]')
      .click('button[type=submit]')
      .assert.containsText('.mainline-results', 'Nightwatch.js')
      .end();
  }
};

nightwatch.json

{
  "src_folders" : ["tests"],
  "output_folder" : "reports",
  "page_objects_path": "./pages",
  "selenium" : {
    "start_process" : true,
    "server_path" : "lib/drivers/selenium-server-standalone-3.141.59.jar",
    "log_path" : "",
    "port" : 4444,
    "cli_args" : {
      "webdriver.chrome.driver" : "lib/drivers/chromedriver.exe"
    }
  },
  "test_settings" : {
      "default" : {
       "launch_url" : "http://localhost",
       "selenium_port" : 4444,
       "selenium_host" : "localhost",
       "silent" : true,
       "screenshots" : {
        "enabled" : true,
        "path" : "screenshots",
        "on_failure" : true
       },
       "desiredCapabilities" : {
        "browserName" : "chrome",
        "marionette" : "true",
        "javascriptEnabled": true,
        "acceptSslCerts": true
       },
       "acceptSslCerts" : false,
       "use_xpath" : true
    }
    }
  }

package.json

{
  "name": "vs_studio",
  "version": "1.0.0",
  "description": "to learn automation testing",
  "main": "nightwatch.js",
  "scripts": {
    "test": ""
  },
  "author": "Michal",
  "license": "ISC",
  "dependencies": {
    "nightwatch": "^1.2.4"
  },
  "devDependencies": {
    "chromedriver": "^77.0.0",
    "geckodriver": "^1.18.0"
  }
}

ниже результата выполнения теста:


[Demo] Test Suite
=================
Running:  Demo test Ecosia.org

√ Testing if the page title contains "Ecosia"  - 17 ms.
   NoSuchElementError: An error occurred while running .isVisible() command on <input[type=search]>:
       at process._tickCallback (internal/process/next_tick.js:68:7)
× Testing if element <input[type=search]> is visible. Element could not be located in 1000 ms. - expected "true" but got: "null"
    at Object.Demo test Ecosia.org (C:\Users\mincberm\Documents\VS_Studio\tests\demo.js:6:15)
    at process._tickCallback (internal/process/next_tick.js:68:7)


FAILED: 1 assertions failed, 1 errors and  1 passed (7.352s)
_________________________________________________

TEST FAILURE: 1 error during execution 1 assertions failed, 1 passed. 14.576s

 × demo
 – Demo test Ecosia.org (7.352s)
   Testing if element <input[type=search]> is visible. Element could not be located in 1000 ms. - expected "true" but got: "null"
       at Object.Demo test Ecosia.org (C:\Users\mincberm\Documents\VS_Studio\tests\demo.js:6:15)
       at process._tickCallback (internal/process/next_tick.js:68:7)

  NoSuchElementError: An error occurred while running .isVisible() command on <input[type=search]>:
       at process._tickCallback (internal/process/next_tick.js:68:7)

я пытаюсь выполнить тестна Chrome (версии 71, 74, 75 и 77) и на нескольких версиях Firefox и у меня есть тот же провлем

Ответы [ 2 ]

0 голосов
/ 02 октября 2019

Я изменяю код:

module.exports = {
  'Demo test Ecosia.org': function (browser) {
    browser
      .url('https://www.ecosia.org/')
      .assert.titleContains('Ecosia')
      .waitForElementPresent('input[type=search]', 20000)
      .assert.visible('input[type=search]')
      .setValue('input[type=search]', 'nightwatch')
      .assert.visible('button[type=submit]')
      .click('button[type=submit]')
      .assert.containsText('.mainline-results', 'Nightwatch.js')
      .end();
  }
};

, и у меня все еще проблема:

[Demo] Test Suite
=================
Running:  Demo test Ecosia.org

√ Testing if the page title contains "Ecosia"  - 32 ms.
× Timed out while waiting for element <input[type=search]> to be present for 20000 milliseconds. - expected "found" but got: "not found"
    at Object.Demo test Ecosia.org (C:\Users\mincberm\Documents\VS_Studio\tests\demo.js:6:8)
    at process._tickCallback (internal/process/next_tick.js:68:7)


FAILED: 1 assertions failed and  1 passed (22.329s)
_________________________________________________

TEST FAILURE:  1 assertions failed, 1 passed. 28.396s

 × demo
 – Demo test Ecosia.org (22.329s)
   Timed out while waiting for element <input[type=search]> to be present for 20000 milliseconds. - expected "found" but got: "not found"
       at Object.Demo test Ecosia.org (C:\Users\mincberm\Documents\VS_Studio\tests\demo.js:6:8)
       at process._tickCallback (internal/process/next_tick.js:68:7)

0 голосов
/ 02 октября 2019

Я не верю, что у Nightwatch есть какая-либо waitForPageLoaded, поэтому вы захотите использовать .waitForElementPresent и использовать элемент из того, что консоль сообщает вам, что загружается в последний раз. В противном случае вы будете утверждать до завершения загрузки страницы, и у вас часто будут эти проблемы.

...