我正在通过下面的代码进行测试,并显示错误消息:

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
看起来我在使用相对路径的方式上做错了。

最佳答案

您应该设置SpecFile的相对路径,而不是配置文件的相对路径。

因此,如果您的项目有:

项目





home_page.js
pick_present_page.js

conf.js
眼镜


主要



您应该从“ ../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")
        });

    });
});


主页

   '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;

关于javascript - 找不到模块-相对路径,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45049720/

10-10 08:10