移动测试基础 使用 chrome mobile emulation 来辅助 device 测试

麦子 · 2014年06月08日 · 最后由 恒温 回复于 2017年01月11日 · 2194 次阅读
本帖已被设为精华帖!

如果你测试的是 web app 或者是 hybrid app, chrome mobile emulation 可以辅助大家快速的在 PC 端完成 debug,或者是 html 部分的冒烟,布局测试。

Mobile emulation 只有在 chrome 32 版本之后才有!!!

启动模拟器

打开 chrome,navigate 到 developer tools(F12), 点击 “show drawer” 按钮。

设备栏:

设备栏提供了十几种流行的手机模式:iphones,ipads,Samsung Galaxy......当然相应的信息会体现在 UA 上。
选择设备,刷新页面。

屏幕栏

屏幕栏允许大家定制化手机的分辨率,像素比例.......

用户终端栏

User Agent 是一个古老的技术,旨在根据不同的 agent string 来显示不同的 mobile website。目前多被响应式设计所取代。

感应器栏

通过此栏你可以实现 device 的硬件模拟,包括触摸,地理定位,加速度计......

回到 browser 模式

回到设备栏,点击 “reset” 按钮。

总结:

Chrome 的模拟器对于开发,测试都是非常有用的,但是它还远远不能替代真机上的用户和 mobile site, app 的真实交互,体验。
所以如果你想进行 quick and dirty 的 mobile testing, chrome mobile emulation 是个不错的选择。

共收到 8 条回复 时间 点赞

#3 楼 @Lihuazhang 我用的这段代码,一直爆(unknown error: cannot parse capability: chromeOptions)这个错误。找了好久的原因了。可否给解答一下。

#5 楼 @tester_all cannot org.openqa.selenium.WebDriverException: unknown error: cannot parse capability: chromeOptions
from unknown error: unrecognized chrome option: mobileEmulation
(Driver info: chromedriver=2.9.248315,platform=Windows NT 6.1 SP1 x86_64) (WARNING: The server did not provide any stacktrace information) 遇到这个错误怎么解决呢

#3 楼 @lihuazhang 这样可以切换到手机模式,解决了有的页面只能在手机上滑动的问题

新人,目前入职测试攻城狮,听说回帖要超过 10

这个帖子也顶下,另外可以用 chromedriver 来自动化模拟。

package com.testerhome;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
import java.util.HashMap;
import java.util.Map;

import static org.junit.Assert.assertTrue;

/**
 * Created by lihuazhang on 15/4/4.
 */
public class ChromeMobileEmulatorTest {

    private WebDriver driver;


    @Before
    public void createDriver() {
        Map<String, String> mobileEmulation = new HashMap<String, String>();
        mobileEmulation.put("deviceName", "Google Nexus 5");
        Map<String, Object> chromeOptions = new HashMap<String, Object>();
        chromeOptions.put("mobileEmulation", mobileEmulation);
        DesiredCapabilities capabilities = DesiredCapabilities.chrome();
        capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
        driver = new ChromeDriver(capabilities);
    }

    @After
    public void quitDriver() {
        driver.quit();
    }

    @Test
    public void testBaiduSearch() throws InterruptedException {
        driver.get("http://www.baidu.com");
        Thread.sleep(5000);  // Let the user actually see something!
        WebElement searchBox = driver.findElement(By.name("word"));
        searchBox.sendKeys("ChromeDriver");
        searchBox.submit();
        Thread.sleep(5000);  // Let the user actually see something!
        assertTrue(driver.getPageSource().contains("ChromeDriver"));
        driver.quit();
    }
}

很强大的 chrome 回归手机上的 web app 很有用,模拟 ua

写的很好, 超实用的技能 Get

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册