自动化测试selenium使用

 

 

1.导入pom包

		<dependency>
			<groupId>org.seleniumhq.selenium</groupId>
			<artifactId>selenium-java</artifactId>
			<version>3.141.59</version>
		</dependency>

2.使用的是谷歌测试

下载驱动文件

http://chromedriver.storage.googleapis.com/index.html?path=73.0.3683.20/

 

相关代码

	 System.setProperty("webdriver.chrome.driver", "E:\\soft_ware\\chromedriver.exe");
		WebDriver driver = new ChromeDriver();
		driver.get("http://www.baidu.com/");
		
		driver.close();

3.基础使用

https://www.peyesight.cn/second_arrive_store/index.html#/home?activeId=9c38d622-8f5f-4dbb-b22d-c2ff7b32a53e&code=b&status=1

自定义分辨率 只适用于PC,宽不能低于指定分辨率

WebDriver driver = new ChromeDriver();
Dimension targetSize = new Dimension(375, 812);
driver.manage().window().setSize(targetSize);
//下面的全屏,如果有需要注释掉,
//driver.manage().window().maximize();

 

适用于手机

	Map<String, String> mobileEmulation = new HashMap<String, String>();
        mobileEmulation.put("deviceName", "iPhone X");
        ChromeOptions headlessOptions = new ChromeOptions();
        headlessOptions.setExperimentalOption("mobileEmulation", mobileEmulation);
        DesiredCapabilities capabilities = DesiredCapabilities.chrome();
        capabilities.setCapability(ChromeOptions.CAPABILITY, headlessOptions);

    	WebDriver driver =new ChromeDriver(capabilities);

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值