1.实现浏览器截屏
3.检查页面元素文本是否出现
4.拖拽页面可以移动的元素
//调用getscreenshotAs方法把当前浏览器打开的页面进行截图,保存到file对象中
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
try {
//把file对象转换为一个保存在c潘霞testing目录中名字为test.png的图片文件
//目标文件不存在则新建
FileUtils.copyFile(scrFile, new File("D:\\eclipsss\\test.png"));
} catch (IOException e) {
e.printStackTrace();
}
2.杀死浏览器进程
WindowsUtils.tryToKillByName("firefox.exe");3.检查页面元素文本是否出现
WebElement text = driver.findElement(By.xpath("//p[1]"));//获取p标签的文字内容
String contentText = text.getText();
Assert.assertEquals("《光荣之路》这个电影真的很棒!", contentText);
Assert.assertTrue(contentText.contains("光荣之路"));
Assert.assertTrue(contentText.startsWith("《光荣"));
Assert.assertTrue(contentText.endsWith("很棒!"));4.拖拽页面可以移动的元素
//寻找可以被拖拽的页面对象
WebElement draggable = driver.findElement(By.id("draggable"));
//向下拖动是个像素,共拖动5次
for (int i = 0; i < 5; i++) {
new Actions(driver).dragAndDropBy(draggable, 0, 10).build().perform();
}
for (int i = 0; i < 5; i++) {
new Actions(driver).dragAndDropBy(draggable, 10, 0).build().perform();
}
本文介绍了使用自动化测试工具进行浏览器截屏、杀死浏览器进程、检查页面元素文本、以及拖拽页面元素的操作方法。
3566

被折叠的 条评论
为什么被折叠?



