问题描述
我是量角器的新手.任何人都可以指导我使用量角器进行数据驱动测试.下面是代码、配置文件和 testdata.json 文件.
'use strict';var testData = require('../example/Test Data/Test.json');描述('登录页面',函数(){var loginData = require('../example/Test Data/Test.json');testData.forEach(函数(数据){它(数据.描述",功能(数据){browser.get("http://127.0.0.1:8080/#/login");element(by.model("username")).sendKeys(data.username);element(by.model("password")).sendKeys(data.passwordField);element(by.buttonText("Authenticate")).click();});});});
配置文件:
//一个示例配置文件.出口.config = {直接连接:真,//seleniumAddress: 'http://localhost:4444/wd/hub',//传递给 webdriver 实例的能力.能力:{'浏览器名称':'铬'},//要使用的框架.推荐茉莉花.框架:茉莉花",//规范模式是相对于当前工作目录的//量角器被调用.规格:['Testpage.js'],//传递给 Jasmine 的选项.茉莉花节点选项:{默认超时间隔:30000}};
Json 文件:
[{用户名":管理员",密码字段":管理员"},{用户名":admin1",密码字段":admin2"}]问题是它没有在所有输入框中写入数据,而是写入 undefined .请帮忙
我假设它是一个对象数组,你可以迭代每个数组元素并直接访问它的内容,你不需要testdata.forEach()
,你可以试试这样的 -
'使用严格';var testData = require('../example/Test Data/Test.json');描述('登录页面',函数(){它(数据.描述",函数(){browser.get("http://127.0.0.1:8080/#/login");element(by.model("username")).sendKeys(testData[0].username);element(by.model("password")).sendKeys(testData[0].passwordField);element(by.buttonText("Authenticate")).click();});});});
我还没有测试过上面的代码,你应该使用页面对象而不是直接在你的测试中使用它们!
I am new to protractor. Can anyone please guide me for data driven testing using protractor. Below is the code, config file and testdata.json file.
'use strict';
var testData = require('../example/Test Data/Test.json');
describe('LoginPage', function() {
var loginData = require('../example/Test Data/Test.json');
testData.forEach(function (data) {
it("data.description", function (data) {
browser.get("http://127.0.0.1:8080/#/login");
element(by.model("username")).sendKeys(data.username);
element(by.model("password")).sendKeys(data.passwordField);
element(by.buttonText("Authenticate")).click();
});
});
});
Config file:
// An example configuration file.
exports.config = {
directConnect: true,
//seleniumAddress: 'http://localhost:4444/wd/hub',
// Capabilities to be passed to the webdriver instance.
capabilities: {
'browserName': 'chrome'
},
// Framework to use. Jasmine is recommended.
framework: 'jasmine',
// Spec patterns are relative to the current working directory when
// protractor is called.
specs: ['Testpage.js'],
// Options to be passed to Jasmine.
jasmineNodeOpts: {
defaultTimeoutInterval: 30000
}
};
Json File:
[
{
"username": "admin",
"passwordField": "admin"
},
{
"username": "admin1",
"passwordField": "admin2"
}
]
Issue is that instead of taking data , it is writing undefined in all input boxes. Please Help
I am assuming its an Array of objects, you can iterate each array element and directly access its contents and you don't need testdata.forEach()
, you could try something like this -
'use strict';
var testData = require('../example/Test Data/Test.json');
describe('LoginPage', function() {
it("data.description", function () {
browser.get("http://127.0.0.1:8080/#/login");
element(by.model("username")).sendKeys(testData[0].username);
element(by.model("password")).sendKeys(testData[0].passwordField);
element(by.buttonText("Authenticate")).click();
});
});
});
I haven't tested the above code and you should use Page Objects rather than directly using them in your tests!
这篇关于Protractor 中的数据驱动测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!