我试图launch_url在我的测试中使用该属性,并在将浏览器发送到该URL之前附加相对路径.
我知道browser.init();将浏览器发送到该地址,launch_url但我想知道是否可以在执行重定向之前将一些字符串附加到检索到的URL.
假设我launch_url是www.xxx.com,我想做的事情如下:
this.test = function (client) {
client.init("/a/b/c"); // >> should result in the browser going to www.xxx.com/a/b/c
};
Run Code Online (Sandbox Code Playgroud)
任何的想法?
谢谢
如果您在nightwatch.json文件中指定了"launch_url",则可以在传递给测试的"client"对象上访问它.例如:
module.exports = {
'Demo test Google' : function (client) {
client
.url(client.launch_url)
.waitForElementVisible('body', 1000)
.setValue('input[type=text]', 'nightwatch')
.waitForElementVisible('button[name=btnG]', 1000)
.click('button[name=btnG]')
.pause(1000)
.assert.containsText('#main', 'Night Watch')
.end();
}
};
Run Code Online (Sandbox Code Playgroud)
因此,对于您的示例代码:
this.test = function (client) {
client.url(client.launch_url + "/a/b/c"); // >> should result in the browser going to www.xxx.com/a/b/c
};
Run Code Online (Sandbox Code Playgroud)
另一种方法是创建一个配置文件,其中包含一些基本项目;然后能够通过您使用的自定义 init 方法附加该配置文件。
IE:
var configDefaults = module.exports = {
baseUrl: 'http://www.example.com/',
local: false,
};
Run Code Online (Sandbox Code Playgroud)
然后在您的自定义命令中编写如下内容:
"use strict";
var config = require('./config')
exports.command = function(urlModifier) {
var _self = this;
_self
.url(config.baseUrl+urlModifier)
.waitForElementVisible('body', 4000)
if( typeof callback === "function"){
callback.call(_self);
}
return this;
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5856 次 |
| 最近记录: |