selenium 2 关于移动端wap网页的测试,3种解决思路。

本文介绍了使用Selenium 2进行移动端WAP网页测试的三种解决方案,重点关注通过第三方浏览器模拟,例如利用Chrome在iOS和Android上的浏览器模拟功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本文纯属虚构:

1.使用第三方浏览器模拟,本文拟用chrome。

chrome 支持 主流系统ios、Android的浏览器模拟。

如图



 
java 初始化driver
//userAgent 可以通过上图UA栏获取,如:Mozilla/5.0 (iPhone; CPU iPhone OS 7_0 like Mac OS X; en-us) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11A465 Safari/9537.53
String userAgent = "user_agent_string" ; chromeOptions co = new ChromeOptions (); co . addArguments ( "--user-agent=" + userAgent ); DesiredCapabilities cap = DesiredCapabilities . chrome (); cap . setCapability ( ChromeOptions . CAPABILITY , co ); WebDriver driver = new ChromeDriver ( cap );

其他语言参考:http://simply-tutorial.com/blog/2014/07/10/selenium-webdriver-set-browsers-user-agent-and-proxy/

2.使用selenium 的androiddriver,iphonedriver,

需要下载
以Android为例,下载 androiddriver以及Android-server.apk,android模拟器(或使用真机) ,速度较慢

1. Setup Android emulator   a. Download the Android SDK              http://developer.android.com/sdk/index.html               Note that there is an emulator bug on Gingerbread((2.3.x) that might cause WebDriver to crash. My testing is on Ice Cream Sandwich (4.0.x)

  b. Install Android SDK:              http://developer.android.com/sdk/installing.html

  c. Start Android SDK Manager (SDK Manager.exe)   d. Select and install Package online   e. Start AVD Manager.exe   f. Create an emulator

2. Install the AndroidDriver APK by using platform-tools    a. list divce name:               adb devices   b. download AndroidDriver APK:               http://code.google.com/p/selenium/downloads/list   c. install AndroidDriver APK:               adb -s emulator-5554 -e install -r c:\android-server-2.21.0.apk   d. start the Android WebDriver application              adb -s emulator-5554 shell am start -a android.intent.action.MAIN -n org.openqa.selenium.android.app/.MainActivity   e. setup the port forwarding in order to forward traffic from the host machine to the emulator               adb -s emulator-5554 forward tcp:8080 tcp:8080

3. 编写测试脚本运行: import junit.framework.TestCase;    import org.openqa.selenium.By;  import org.openqa.selenium.WebElement;  import org.openqa.selenium.android.AndroidDriver;    public class OneTest extends TestCase {      public void testGoogle() throws Exception {      WebDriver driver = new AndroidDriver();            // And now use this to visit Google      driver.get("http://www.google.com");            // Find the text input element by its name      WebElement element = driver.findElement(By.name("q"));            // Enter something to search for      element.sendKeys("Cheese!");            // Now submit the form. WebDriver will find the form for us from the element      element.submit();            // Check the title of the page      System.out.println("Page title is: " + driver.getTitle());      driver.quit();    }  } 来自:http://blog.youkuaiyun.com/gxlujun/article/details/7520558

3.使用appium /或者robotium等,如果单单测试wap页,此方法不推荐。效率不高.有种高射炮打蚊子的意思。不在赘述,自行google









评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值