gpt4 book ai didi

javascript - 如何在 Protractor 自动化中使用 Javascript 命名空间?

转载 作者:行者123 更新时间:2023-11-28 18:16:37 24 4
gpt4 key购买 nike

我有 3 个文件,即conf.js、actionwords.js、project_test.js。 Actionwords.js和project_test.js是从hiptest工具生成的文件。所以我需要使用这个结构来自动化测试用例。当我运行 cmd 时,出现错误。

我跑了:

protractor conf.js

消息: 失败:无法读取未定义的属性“theApplicationURL”

堆栈: 类型错误:无法读取未定义的属性“theApplicationURL”

//conf.js

exports.config = {
framework: 'jasmine2',
directConnect: true,
seleniumAddress: 'http://localhost:4444/wd/hub',
specs:['path to/project_test.js'],
capabilities: { 'browserName': 'chrome' }
};

//actionwords.js

var Actionwords = {
theApplicationURL: function () {
browser.get('localhost');
browser.driver.manage().window().maximize();
browser.sleep(5000);
},
};

//project_test.js

describe('Test', function () {
beforeEach(function () {
this.actionwords = Object.create(Actionwords);
});

it('Login_Test (uid:fe6d6670-a864-4d0f-a867-3faf9f51ff8d)', function () {
// Given the application URL
this.actionwords.theApplicationURL();
});
});

有人可以帮我吗?

最佳答案

这样修改:

var actionwords = {
theApplicationURL: function () {
browser.get('localhost');
browser.driver.manage().window().maximize();
browser.sleep(5000);
},
};

module.exports = actionwords;

测试:

var actionwords = require("actionwords.js")

describe('Test', function () {
it('Login_Test (uid:fe6d6670-a864-4d0f-a867-3faf9f51ff8d)', function () {
// Given the application URL
actionwords.theApplicationURL();
});
});

评论的 react :

您可以在 beforeEach 中将其分配给此范围:

var actionwords = require("actionwords.js")

describe('Test', function () {
beforeEach(function () {
this.actionwords = actionwords;
});
it('Login_Test (uid:fe6d6670-a864-4d0f-a867-3faf9f51ff8d)', function () {
// Given the application URL
this.actionwords.theApplicationURL();
});
});

关于javascript - 如何在 Protractor 自动化中使用 Javascript 命名空间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40670357/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com