栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

基于JAVA实现的WEB端UI自动化 - WebDriver高级篇 - 代码检查点[验证点/断言]与图像检查点

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

基于JAVA实现的WEB端UI自动化 - WebDriver高级篇 - 代码检查点[验证点/断言]与图像检查点

文章目录
    • 代码检查点[验证点/断言]
      • 检查方式 - 元素是否正常 - `try catch`
      • 验证页面里是不是存在某文字
      • 验证页面是否存在某元素
      • 验证某一个元素是否包含某些文字
      • 验证字体颜色是否符合预期
      • 验证背景颜色是否符合预期
      • 验证元素的属性 title
      • 验证某个元素对应的value值必须是/必须不是某值
    • 图像检查点

代码检查点[验证点/断言] 检查方式 - 元素是否正常 - try catch
//元素是否存在	
		try{
			WebElement el = Demo16_status_driver.findElement(By.name("user"));
			System.out.println("该元素存在");
		}
		catch(NoSuchElementException e){
			System.out.println("未找到该元素");
		}

		//元素是否显示
		try{
			WebElement el = Demo16_status_driver.findElement(By.name("user"));
			System.out.println("该元素存在");
			System.out.println("display:"+el.isDisplayed());
		}
		catch(NoSuchElementException e){
			System.out.println("未找到该元素");
 		}
		
		try{
			WebElement el = Demo16_status_driver.findElement(By.name("display"));
			System.out.println("该元素存在");
			System.out.println("display:"+el.isDisplayed());
			if(el.isDisplayed()){
				System.out.println("且正常显示");
			}
			else{
				System.out.println("但未显示");
			}
		}
		catch(NoSuchElementException e){
			System.out.println("未找到该元素");
 		}

验证页面里是不是存在某文字
WebDriverWait wait = new WebDriverWait(Demo20_daimajianchadian, 30);
WebElement el = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[contains(.,besttest)]")));
验证页面是否存在某元素
WebElement el2 = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id='su']")));
验证某一个元素是否包含某些文字
Boolean status = Demo20_daimajianchadian.findElement(By.id("aa")).getText().contains("besttest");
验证字体颜色是否符合预期

raba (101,120,100,1) 与 #001400 进制之间的转换

String rgb="";
Demo20_daimajianchadian.findElement(By.id("aa")).getCssValue("color").equals(rgb);
验证背景颜色是否符合预期
Demo20_daimajianchadian.findElement(By.id("aa")).getCssValue("backgroup-color").equals(rgb);
验证元素的属性 title
String qiwang="";
Boolean status = Demo20_daimajianchadian.findElement(By.id("aa")).getAttribute("title").equals(qiwang);
验证某个元素对应的value值必须是/必须不是某值
Boolean status3 = Demo20_daimajianchadian.findElement(By.id("aa")).getAttribute("value").equals(qiwang);
图像检查点
		Demo21_tuxiangjianchadian.manage().window().maximize();//浏览器最大化
		Thread.sleep(3000);
		Demo21_tuxiangjianchadian.get("file:///C:/Users/Administrator/Desktop/autoTest/bootstrap-snippet-login-form/login2.html");
		
		//临时文件  (截图)
		File soure_file = ((TakesScreenshot)Demo21_tuxiangjianchadian).getScreenshotAs(OutputType.FILE);
		
		//copy文件至固定路径
		String path="D:/pic/";
		try {
			FileUtils.copyFile(soure_file, new File(path+System.currentTimeMillis()+".png"));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		Thread.sleep(3000);
		Demo21_tuxiangjianchadian.quit(); //退出WebDriver
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/346348.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号