是否有任何方法從量角器的beforeEach()中的茉莉花數據提供器中獲取方法名稱或數據值;就像我們在selenium中用testNg-beforeMethod()所做的那樣?在量角器的beforeEach()中使用參數
之前TestNG的protrcator的方法 - beforeMethod(最終對象[]數據,最終方法方法)
同樣我想在beforeEach()。
是否有任何方法從量角器的beforeEach()中的茉莉花數據提供器中獲取方法名稱或數據值;就像我們在selenium中用testNg-beforeMethod()所做的那樣?在量角器的beforeEach()中使用參數
之前TestNG的protrcator的方法 - beforeMethod(最終對象[]數據,最終方法方法)
同樣我想在beforeEach()。
試試這個辦法,因爲@alexce建議
Protractor Multiple Size Browsers
describe("Testing multiple browser sizes", function() {
var sizes = [
{x: 800, y: 600},
{x: 300, y: 200}
];
sizes.map(function(size) {
it("should pass the test on browser size: x='" + size.x + "', y='" + size.y + "'", function() {
browser.driver.manage().window().setSize(size.x, size.y);
# test logic
});
}
});
你也許並不需要茉莉數據提供商,正好連接符合規範的名稱,你需要什麼。
我建議的一件事是在一個單獨的模塊中定義你的數據值,然後導入到你的spec文件。
// Your data in its own module
'use strict'
module.exports = {
browserSizes : {
'Browser 1': {x: 800, y: 600},
'Browser 2': {x: 300, y: 200}
}
}
然後將其包含在beforeEach像這樣:
var setBrowser = require('path_to_your_module');
var using = require('jasmine-data-provider');
describe('a cool test', function() {
using(setBrowser.browserSizes, function(data, description) {
beforeEach(function() {
browser.driver.manage().window().setSize(data.x, data.y);
});
... more code here ...
}
}
這樣,所有你需要做的就是增加新的瀏覽器尺寸的模塊文件,你可以訪問它。無論您需要它你的spec文件。我寫了一篇關於如何在這裏使用這種方式茉莉花數據提供的教程,如果你想看看具體
http://moduscreate.com/protractor-and-jasmine-data-provider-write-once-test-many/
希望這有助於!
你能提供一個茉莉花數據提供者的例子嗎? – Xotabu4
https://www.npmjs.com/package/jasmine-data-provider – saurabh04