admin管理员组

文章数量:1614268

使用chrome driver和chrome浏览器并进入chrome的 toggle device mode 模式,就可以很好的模拟手机端,下面直接上代码

			System.setProperty("webdriver.chrome.driver", config.getProperty("chromePath"));
		        Map<String, String> mobileEmulation = new HashMap<String, String>();  
		        mobileEmulation.put("deviceName", "Apple iPhone 6");  
		        Map<String, Object> chromeOptions = new HashMap<String, Object>();     
		        chromeOptions.put("mobileEmulation", mobileEmulation);     
		        DesiredCapabilities capabilities = DesiredCapabilities.chrome();       
		        capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions); 
		        
			driver=new MobileChromeDriver(capabilities);



这里MobileChromeDriver是为了方便使用TouchActions,只需新建一个类继承自ChromeDriver并实现HasTouchScreen接口。

public class MobileChromeDriver extends ChromeDriver implements HasTouchScreen {
    private RemoteTouchScreen touch;

    public MobileChromeDriver(Capabilities capabilities) {
        super(capabilities);
        touch = new RemoteTouchScreen(getExecuteMethod());
    }

    public TouchScreen getTouch() {
        return touch;
    }
}


转载自:http://wwwblogs/iamhp/p/6016194.html

http://wwwblogs/g-song/p/5205972.html

本文标签: 打开浏览器模式手机selenium