我正在通过以下代码运行测试并收到错误消息:
Failed: cannot find module '../page/home_page.js
主页是:
describe("login to website",function(){
var employeeId;
var employeeBday;
beforeEach(function(){
browser.get("https://pre-www5.main.co.il/#/");
});
it("should succees login",function(){
employeeId = "54729108";
employeeBday = "25/03/1957";
var home_page = require('../page/home_page.js')
home_page.enterUsernameField(employeeId);
home_page.enterBirthdateField(employeeBday);
var pick_present_page = home_page.clickContinue();
element(by.xpath("//*[@id='planAndDev']/div/div/div/div/matanot/form/div[2]/h4")).getText().then(function(text)
{
expect(text).toContain("foo")
});
});
});

使用home_page类:
require ('../page/pick_present_page.js')
var home_page = function(){
this.enterUsernameField=function(employeeId){
element(by.xpath("//*[@id='planAndDev']/div/div/div/div/form/fieldset/div[1]/input")).sendKeys(employeeId);
};
this.enterBirthdateField=function(EmployeebDay){
element(by.xpath("//*[@id='planAndDev']/div/div/div/div/form/fieldset/div[2]/my-date-picker/div/div/input")).sendKeys(EmployeebDay);
};
this.clickContinue=function(){
element(by.xpath("//*[@id='planAndDev']/div/div/div/div/form/nav/div/button")).click();
return require('./pick_present_page');
};
module.exports = new home_page();
};

位于C:\JS_Project
的项目文件夹
这些页面位于C:\JS_Project\page
看起来我在使用相对路径的方式做错了。
答案 0 :(得分:2)
您应该建立SpecFile的相对路径,而不是从配置文件。
所以如果你的项目有:
项目
你应该从“../ page / home_page.js”
获取页面主要
'use strict;'
let HomePage = require('../page/home_page.js');
describe("login to website",function(){
let employeeId;
let employeeBday;
let home = new HomePage();
beforeEach(function(){
browser.get("https://pre-www5.main.co.il/#/");
});
it("should login successfully",function(){
employeeId = "54729108";
employeeBday = "25/03/1957";
home.enterUsernameField(employeeId);
home.enterBirthdateField(employeeBday);
var pick_present_page = home.clickContinue();
element(by.xpath("//*[@id='planAndDev']/div/div/div/div/matanot/form/div[2]/h4")).getText().then(function(text)
{
expect(text).toContain("foo")
});
});
});
Home_Page
'use strict;'
require ('../page/pick_present_page.js');
var HomePage = function(){
let employeeField = element(by.xpath("//*[@id='planAndDev']/div/div/div/div/form/fieldset/div[1]/input"));
let employeeBDayField = element(by.xpath("//*[@id='planAndDev']/div/div/div/div/form/fieldset/div[2]/my-date-picker/div/div/input"));
let continueButton = element(by.xpath("//*[@id='planAndDev']/div/div/div/div/form/nav/div/button"));
this.enterUsernameField=function(employeeId){
employeeField.sendKeys(employeeId);
};
this.enterBirthdateField=function(EmployeebDay){
employeeBDayField.sendKeys(EmployeebDay);
};
this.clickContinue=function(){
continueButton.click();
return require('./pick_present_page');
};
};
module.exports = HomePage;