如何选择用量角器上弹出按钮 [英] How to select a button on popup using Protractor
问题描述
当用户导航到该页面,一个小的弹出窗口询问用户共享位置像在下面的屏幕截图。
When the user navigates to the page, a small popup window appears asking the user to "Share Location" like in the screen shot below.
所以,我不知道怎么用量角器来模拟用户点击共享位置按钮(显然,元素(by.buttonText(共享位置))点击();
不工作)。
So I wonder how can I use Protractor to simulate the user's click on the "Share Location" button (apparently, element(by.buttonText("Share Location")).click();
doesn't work).
此外,在这个截图的浏览器是Firefox和为不同的浏览器可能有不同的消息/风格我怎么能那么解决这个问题?
Also the browser in this screenshot is Firefox and as different browser may have different messages/styles how can I then tackle this issue?
推荐答案
的问题是,这个按钮是不是在DOM和你的不能用量角器/硒控制它的。你需要避免它摆在首位被打开,并让浏览器知道如何自动响应。
The problem is that this button is not in the DOM and you cannot control it with protractor/selenium. You need to avoid it being opened in the first place and let the browser know how to automatically respond.
在应用这个答案(未测试):
browser.executeScript("navigator.geolocation.getCurrentPosition = function(success) { success({coords: {latitude: 50.455755, longitude: 30.511565}}); }");
您还可以通过设置解决了 geo.prompt.testing
和 geo.prompt.testing.allow
到真正
中的 FirefoxProfile preferences 。样品量角器配置以 makeFirefoxProfile()
辅助函数:
You can also solve it by setting the geo.prompt.testing
and geo.prompt.testing.allow
to true
in the FirefoxProfile preferences. Sample protractor config with a makeFirefoxProfile()
helper function:
var q = require("q");
var FirefoxProfile = require("firefox-profile");
var makeFirefoxProfile = function(preferenceMap, specs) {
var deferred = q.defer();
var firefoxProfile = new FirefoxProfile();
for (var key in preferenceMap) {
firefoxProfile.setPreference(key, preferenceMap[key]);
}
firefoxProfile.encoded(function (encodedProfile) {
var capabilities = {
firefox_profile: encodedProfile,
specs: specs
};
deferred.resolve(capabilities);
});
return deferred.promise;
};
exports.config = {
getMultiCapabilities: function() {
return q.all([
makeFirefoxProfile(
{"geo.prompt.testing": true, "geo.prompt.testing.allow": true},
["specs/*.spec.js"]
)
]);
},
// ...
}
这篇关于如何选择用量角器上弹出按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!