selenium3.141+java模拟F12进入wap页面

因为公司有wap和微信专区渠道,我都是在电脑上模拟的,所以想试一下自动化测试能否模拟,发现可以,代码如下:

package testsuite;
import java.util.HashMap;
import java.util.Map;

import org.openqa.selenium.By;
import org.openqa.selenium.Cookie;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import framework.Base;

public class runtest {
	public static WebDriver driver = null;
    @SuppressWarnings("deprecation")
	@BeforeClass
    public void beforeClass(){
        System.setProperty("webdriver.chrome.driver", ".\\chromedriver.exe");

    Map<String, String> mobileEmulation = new HashMap<String, String>();
    //设置设备,例如:Google Nexus 7/Apple iPhone 6
    //mobileEmulation.put("deviceName", "Google Nexus 7"); 
    mobileEmulation.put("deviceName", "iPhone X");   //这里是要使用的模拟器名称,就是浏览器中模拟器中的顶部型号
    Map<String, Object> chromeOptions = new HashMap<String, Object>();     
    chromeOptions.put("mobileEmulation", mobileEmulation);     
    DesiredCapabilities capabilities = DesiredCapabilities.chrome();       
    capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
    try {
        System.out.println("开始启动driver~~~");
        driver = new ChromeDriver(capabilities);
        System.out.println("启动driver成功~~~");
    } catch (Exception e) {
        System.out.println("启动driver失败~~~");
        System.out.println(e.getMessage());
    }
    driver.get("https://www.baidu.com");
}

 
@Test
public void login(){        
	}
}

执行后网页显示如下:
在这里插入图片描述

之后就可以对元素进行操作了,模拟了手机网页自动化测试

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值