【问题标题】:Why is my test not loading my page object file? (Nightwatch.js)为什么我的测试没有加载我的页面对象文件? (守夜人.js)
【发布时间】:2017-12-24 22:20:27
【问题描述】:

这是我用来运行测试的代码

this is my config file. 
{
  "src_folders" : ["tests"],
  "output_folder" : "reports",
  "custom_commands_path" : "",
  "custom_assertions_path" : "",
  "page_objects_path" : "./pages/affirm.js",
  "globals_path" : "./data/data_for_requestinfo.js",

  "selenium" : {
   "start_process" : true,
    "server_path" : "/Users/davidcastro/Automation/bin/selenium-server-
standalone-3.4.0.jar",
    "log_path" : "",
    "port" : 4444,
    "cli_args" : {
      "webdriver.chrome.driver" : 
    "/Users/davidcastro/Automation/Drivers/chromedriver",
      "webdriver.gecko.driver" : 
 "/Users/davidcastro/Automation/Drivers/geckodriver",
  "webdriver.edge.driver" : ""
    }
  },

  "test_settings" : {
    "default" : {
      "launch_url" : "https://www.affirmpronebiopsy.com/",
      "selenium_port"  : 4444,
      "selenium_host"  : "localhost",
      "silent": true,
      "screenshots" : {
        "enabled" : false,
        "path" : ""
      },
      "desiredCapabilities": {
        "browserName": "firefox",
        "marionette": true
      }

    },
     "brevera" : {
      "launch_url" : "https://prod.breverabiopsy.com/",
      "desiredCapabilities": {
        "browserName": "chrome",
        "javascriptEnabled": true,
        "acceptSslCerts": true
      }
    },

    "chrome" : {
     "desiredCapabilities": {
       "browserName": "chrome"
      }
   },

    "edge" : {
      "desiredCapabilities": {
        "browserName": "MicrosoftEdge"
       }
      }
   }
}



This is my page file

module.exports = {
  elements: {
     name: {
      selector: "input[type=text]"
    },
   email: {
      selector: 'input[type=email]'
    },
    country:{
      selector: 'select[id=edit-country]'
    },
    submit: {
      selector: 'input[id=edit-submit]'
    }
  }
};

这是我的测试文件

 module.exports = {
 'Request info ' : function (client) {
 var data = client.globals;
  var myPageObject = client.page.affirm(); 

client
   .url(client.launch_url + '/request-info')
   .waitForElementPresent('body', 1000)
   .setValue("@name", [data.name, client.Keys.ENTER])
   .pause(1000)
   .setValue('@email', [data.email])
   .pause(1000)
   .setValue('@country', [data.country])
   .pause(1000)
   .click('@submit')
   .pause(1000)
   .assert.containsText('main', 'Thank you for your interest!')
   .saveScreenshot('./screenshots/search-result.png')
   .pause(1000)
   .end();

} };

我尝试将配置文件中的路径多次更改为:./pages, 并将我在测试中调用它的方式更改为: var page=client.page() 并运行我的测试,但没有我在页面文件中命名的字段,所以我得到了错误。

使用上面提到的配置我得到这个错误:The error

我在这里做错了什么吗?

【问题讨论】:

    标签: javascript selenium automation nightwatch.js pageobjects


    【解决方案1】:

    如果您的nightwatch.conf.js 文件与datapages 位于同一目录中,请尝试写入不带初始“.”的路径在前。例如:

    "page_objects_path" : "/pages/affirm.js"
    

    【讨论】:

    • 我已经试过了,我仍然得到上面提到的错误。
    【解决方案2】:

    页面对象路径应该是目录,而不是文件

    "page_objects_path" : "./pages"
    

    【讨论】:

      猜你喜欢
      • 2022-07-05
      • 2021-11-27
      • 1970-01-01
      • 2020-09-11
      • 1970-01-01
      • 1970-01-01
      • 2013-06-16
      • 2018-08-15
      • 2013-02-28
      相关资源
      最近更新 更多