我收到此错误:
NoSuchSessionError:此驱动程序实例没有有效的会话ID(您是否调用过WebDriver.quit()?),并且可能不再使用。
在测试中,我想在一个步骤文件中运行多个方案。我已经阅读了一些必须在步骤文件中重新初始化元素的问题/答案。
当我尝试运行代码时,我可以看到第一个场景已执行并通过。但是在第二种情况下,我无法继续登录页面并在loginPage.get_url();
我的功能文件:
Scenario: As an admin I should be able to go to reports
Given Admin is in dashboard page
When Admin goes to Income reports
Then Admin should be able to click Download excel
Scenario: As an admin I should be able to log out
Given Admin goes back to dashboard page
When Admin clicks the logout button
Then Admin is now on login page
这是我的步骤文件:
let chai = require('chai');
let chaiAsPromised= require('chai-as-promised');
chai.use(chaiAsPromised);
let expect = chai.expect;
const { Before, After } = require('cucumber');
var { setDefaultTimeout } = require('cucumber');
setDefaultTimeout(60 * 1200);
Given( 'Admin is in dashboard page', function () {
LoginPage.click_dashboard_button();
} );
When( 'Admin goes to Income reports', function () {
navPage.click_reports_dropdown();
browser.sleep(1000);
navPage.click_incomeReports();
} );
Then( 'Admin should be able to click Download excel', function () {
incomeReportsPage.click_downloadExcelButton();
browser.sleep(3000);
} );
Given( 'Admin go backs to dashboard page', function ( ) {
LoginPage.click_dashboard_button();
});
When( 'Admin clicks the logout button', function () {
LoginPage.click_logout_button();
});
Then( 'Admin is now on login page', function () {
browser.driver.getTitle().then( function ( value ) {
expect( value ).to.equal( "NAGM | Log in" );
});
});
这是我的页面对象文件:
exports.init = function init() {
browser.waitForAngularEnabled( false );
}
exports.get_url = function get_url() {
browser.get( "http://nagm.test.pl/login" );
}
exports.input_username = function input_username() {
usernameTextbox.clear();
usernameTextbox.sendKeys("admin@nagm.ct");
}
exports.input_password = function input_password() {
passwordTextbox.clear();
passwordTextbox.sendKeys("password");
}
exports.click_login_button = function click_login_button() {
loginButton.click();
}
exports.click_logout_button = function click_logout_button() {
logoutButton.click();
}
exports.click_dashboard_button = function click_dashboard_button() {
dashboardMenu.click();
}
我的hooks.js:
Before (function (){
browser.manage().window().maximize();
loginPage.init();
loginPage.get_url();
loginPage.input_username();
loginPage.input_password();
loginPage.click_login_button();
});