Webdriver - Firefox 设置地理位置信息相关测试
来源:互联网 发布:sql求和保留两位小数 编辑:程序博客网 时间:2024/06/10 12:12
Webdriver - Firefox 设置地理位置信息相关测试
作者:
时间: 2015/11
Faking Geolocation in Selenium WebDriver with Firefox
I recently worked on some Selenium WebDriver tests that needed to provide a Geolocation to a HTML5 site so it could display some results. There’s a couple of things to keep in mind when doing this:
- There are two Firefox about:config preferences that you must both set in your WebDriver Firefox profile to always supply the Geolocation information to your test (instead of displaying a prompt). These are:
- set ‘geo.prompt.testing’ to true
- set ‘geo.prompt.testing.allow’ to true
- If you want to use a specific location you need to override an about:config preference to a JSON file containing that location. This is only supported in very recent versions of Firefox (I tested version 31). Whilst this can bemanually done using a data:application/json string, Firefox using WebDriver in C# completely ignores this so the workaround is to create a JSON file with the location and reference using using a file:/// prefix
- Create C:\Dev\Brussels.json etc containing something like:
{ "status": "OK", "accuracy": 10.0, "location": { "lat": 50.850780, "lng": 4.358138, "latitude": 50.850780, "longitude": 4.358138, "accuracy": 10.0 }}
- set ‘geo.wifi.uri’ to ‘file:///C:/Dev/brussels.json’ (or wherever your file is)
- Create C:\Dev\Brussels.json etc containing something like:
Once you’ve done this you should be able to test Geolocation without seeing the prompt or being able to completely override the location. Some example C# WebDriver scripts are below.
using System;using Microsoft.VisualStudio.TestTools.UnitTesting;using OpenQA.Selenium;using OpenQA.Selenium.Firefox;using OpenQA.Selenium.Support.UI;namespace GeoLocation.Tests.Acceptance{ [TestClass] public class WebDriverGeoLocation { [TestMethod] public void CanOverrideLocationInNewerVersionsOfFirefoxLike31() { var profile = new FirefoxProfile {EnableNativeEvents = false}; profile.SetPreference("geo.prompt.testing", true); profile.SetPreference("geo.prompt.testing.allow", true); profile.SetPreference("geo.wifi.uri", "file:///C:/Dev/brussels.json"); var driver = new FirefoxDriver(profile); driver.Navigate().GoToUrl("http://html5demos.com/geo"); new WebDriverWait(driver, TimeSpan.FromSeconds(15)).Until(ExpectedConditions.ElementExists((By.ClassName("success")))); Assert.AreEqual("found you!", driver.FindElement(By.Id("status")).Text); driver.Close(); } [TestMethod] public void CantOverrideLocationInOlderVersionsOfFirefoxLike24() { var profile = new FirefoxProfile { EnableNativeEvents = false }; profile.SetPreference("geo.prompt.testing", true); profile.SetPreference("geo.prompt.testing.allow", true); var driver = new FirefoxDriver(profile); driver.Navigate().GoToUrl("http://html5demos.com/geo"); new WebDriverWait(driver, TimeSpan.FromSeconds(15)).Until(ExpectedConditions.ElementExists((By.ClassName("success")))); Assert.AreEqual("found you!", driver.FindElement(By.Id("status")).Text); driver.Close(); } }}
Enjoy your Geolocation testing!
原文:http://watirmelon.com/2014/09/18/faking-geolocation-in-selenium-webdriver-with-firefox/
0 0
- Webdriver - Firefox 设置地理位置信息相关测试
- Webdriver设置Firefox自动下载
- Webdriver使用自定义Firefox Profile运行测试
- 使用Webdriver+TestNG,设置FireFox安装路径。
- 地理位置信息
- 用FireFox的webdriver做自动化测试时,FireFox版本不宜过高
- WebDriver配置Firefox代理服务器
- webdriver启动firefox浏览器
- webdriver使用Firefox调测
- 设置Webdriver启动chrome为默认用户的配置信息
- 使用webdriver的move_by_offset测试百度设置功能
- 显示ip地理位置信息
- Location获取地理位置信息
- 显示ip地理位置信息
- 獲取地理位置信息
- ios获取地理位置信息
- android获取地理位置信息
- html5 获取地理位置信息
- struts框架设计
- WAMP安装与配置---详细
- Android应用程序基础
- java插入排序方法
- HDOJ 1272 小希的迷宫
- Webdriver - Firefox 设置地理位置信息相关测试
- Mac上的抓包工具Charles
- Filtering F4 Help Values in Table Control, Based On Other Field Value
- Android webview使用详解
- java二分查找方法
- 下载数据库mysql压缩包地址
- ubuntu14.04,安装rpm程序!!
- 《linux shell》笔记之date
- Android 利用Properties进行authority管理