量角器,检查当前 Url 是否等于字符串 url
Protractor, checking if current Url is equal to string url
我正在尝试检查单击提交按钮后页面的当前 url 是否更改为右侧 url。
我尝试用我在网上找到的许多方法来做这件事,但没有任何效果。有时问题是无法对 "url object" 和 "string" 进行相等处理,有时是其他问题。一件事肯定是,当我启动测试时出现错误。你能帮助我吗?谢谢。
这是我的stepdefinition.js
expect(browser.getCurrentUrl()).to.equal("https://myurl.com/eng/homepage.html");
这是我的错误:
E/launcher - expected { Object (flow_, stack_, ...) } to equal 'https://myurl.com/eng/homepage.html'
[15:34:28] E/launcher - AssertionError:预期 { Object (flow_, stack_, ...) } 等于 'https://myurl.com/eng/homepage.html'
尝试做:
expect(browser.getCurrentUrl()).toEqual("https://myurl.com/eng/homepage.html");
browser.getCurrentUrl() returns 一个承诺。您需要使用 .then() 解决它,如下所示:
选项 1) 仅使用 chai
// protractor conf.js
onPrepare: function() {
var chai = require('chai'),
chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);
global.expect = chai.expect;
// make `expect`as global, so you can use it anywhere is your code
}
browser.getCurrentUrl().then(function(currentUrl){
expect(currentUrl).to.equal("https://myurl.com/eng/homepage.html");
})
选项 2) 同时使用 chai
和 chai-as-promised
:
// protractor conf.js
onPrepare: function() {
var chai = require('chai'),
chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);
global.expect = chai.expect;
// make `expect`as global, so you can use it anywhere is your code
}
expect(browser.getCurrentUrl()).to.eventually
.equal("https://myurl.com/eng/homepage.html");
我正在尝试检查单击提交按钮后页面的当前 url 是否更改为右侧 url。 我尝试用我在网上找到的许多方法来做这件事,但没有任何效果。有时问题是无法对 "url object" 和 "string" 进行相等处理,有时是其他问题。一件事肯定是,当我启动测试时出现错误。你能帮助我吗?谢谢。
这是我的stepdefinition.js
expect(browser.getCurrentUrl()).to.equal("https://myurl.com/eng/homepage.html");
这是我的错误:
E/launcher - expected { Object (flow_, stack_, ...) } to equal 'https://myurl.com/eng/homepage.html'
[15:34:28] E/launcher - AssertionError:预期 { Object (flow_, stack_, ...) } 等于 'https://myurl.com/eng/homepage.html'
尝试做:
expect(browser.getCurrentUrl()).toEqual("https://myurl.com/eng/homepage.html");
browser.getCurrentUrl() returns 一个承诺。您需要使用 .then() 解决它,如下所示:
选项 1) 仅使用 chai
// protractor conf.js
onPrepare: function() {
var chai = require('chai'),
chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);
global.expect = chai.expect;
// make `expect`as global, so you can use it anywhere is your code
}
browser.getCurrentUrl().then(function(currentUrl){
expect(currentUrl).to.equal("https://myurl.com/eng/homepage.html");
})
选项 2) 同时使用 chai
和 chai-as-promised
:
// protractor conf.js
onPrepare: function() {
var chai = require('chai'),
chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);
global.expect = chai.expect;
// make `expect`as global, so you can use it anywhere is your code
}
expect(browser.getCurrentUrl()).to.eventually
.equal("https://myurl.com/eng/homepage.html");