我试图用夜班测试当用户在已经在其他浏览器中登录时登录时,它会自动将您从第一个会话中注销。
但我不知道如何创建新的浏览器实例。
这就是我的代码的样子:
//有关编写Nightwatch测试的信息,请参阅 // http://nightwatchjs.org/guide#usage
module.exports = {
'Landing Page': function (browser) {
// automatically uses dev Server port from /config.index.js
// default: http://localhost:8080
// see nightwatch.conf.js
const devServer = browser.globals.devServerURL;
browser
.url(devServer)
.waitForElementVisible('#app', 5000)
.assert.urlContains('login')
.assert.title('Customer Relation Manager')
.assert.elementPresent('.login')
.assert.containsText('.login-header', 'Log into CRM')
},
'A User not logged in will be redirected to login page': function (browser) {
browser
.url('http://localhost:8080/cust')
.pause(1000)
.assert.urlContains('login')
},
'A User can login': function (browser) {
browser
.setValue('input[type=text]', '********')
.setValue('input[type=password]', '*******')
.click('#submit')
.pause(1000)
.assert.urlContains('dashboard')
.assert.containsText(".header-logo", "CRM V3")
},
'A User who is logged in cannot access the Login page again': function (browser) {
browser
.url('http://localhost:8080/login')
.pause(1000)
.assert.urlContains('dashboard')
// .end();
},
'A user can refresh the page and redirect to the same page': function (browser) {
browser
.refresh()
.pause(1000)
.assert.urlContains('dashboard')
},
'A User can logout': function (browser) {
browser
.click('.header-user-info')
.pause(1000)
.assert.urlContains('login')
.assert.containsText('.login-header', 'Log into CRM')
.end();
}
}
答案 0 :(得分:0)
在测试中添加一个beforeEach挂钩,然后向其中添加Deletecookies。因此,对于每个测试,都会启动一个新的浏览器实例。
beforeEach: function (browser) {
browser.maximizeWindow();
browser.deleteCookies();
},