Appium-测试失败后屏幕截图的
本文参考:http://www.cnblogs.com/hexianl/p/4958556.html
使用testng测试框架进行管理测试
1.创建监听,代码如下:

import io.appium.java_client.AppiumDriver; import java.io.File;
import java.io.IOException; import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.testng.ITestResult;
import org.testng.TestListenerAdapter;
import com.globalegrow.test.Screenshot; public class ScreenshotListener extends TestListenerAdapter{
@Override
public void onTestFailure(ITestResult tr){
AppiumDriver driver = Screenshot.getDriver();
File location = new File("screenshots1");
String screenShotName = location.getAbsolutePath()+File.separator+tr.getMethod().getMethodName()+".png";
File screenShot = driver.getScreenshotAs(OutputType.FILE);
try{
FileUtils.copyFile(screenShot, new File(screenShotName));
}
catch(IOException e){
e.printStackTrace();
}
}
}

2.创建测试类,代码如下:

import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit; import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver; import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; public class Screenshot { static AppiumDriver driver;
@BeforeClass
public void setUp() throws MalformedURLException{
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("platformName","Android");
capabilities.setCapability("deviceName","192.168.35.102:5555");
capabilities.setCapability("platformVersion", "5.1");
capabilities.setCapability("browserName", "Chrome");
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(6, TimeUnit.SECONDS);
} @Test
public void testExample() throws InterruptedException{ driver.get("http://wap-sammydress.com.trunk.s1.egomsl.com/");
driver.findElement(By.id("js_top_cate")).click();
Thread.sleep(3000);
driver.findElement(By.cssSelector("#nav > div > ul > li:nth-child(2) > p")).click();
Thread.sleep(5000);
driver.findElement(By.cssSelector("#header > div.top.on > a.icon_tag.top_user.isnoLogin")).click();
Thread.sleep(2000);
driver.findElement(By.id("email")).sendKeys("xxx@163.com");
driver.findElement(By.id("passwordsignl")).sendKeys("xxxx");
driver.findElement(By.id("js_signInBtn")).click(); Thread.sleep(2000);
} @AfterClass
public void tearDown(){
driver.quit();;
} public static AppiumDriver getDriver(){
return driver;
} }

tesng的xml文件配置监听如下:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="test">
<!-- 配置testng监听器 -->
<listeners>
<listener class-name="com.xxx.ScreenshotListener" />
</listeners>
<test name="version" preserve-order="true">
<classes>
<class name="com.xxx.test.Screenshot">
<methods>
<include name="testExample" />
</methods>
</class>
</classes>
</test>
</suite>
运行测试,testExample运行失败后截图如下:
Appium-测试失败后屏幕截图的的更多相关文章
- Appium-测试失败后获取屏幕截图的方法
最近一直在研究appium,偶尔的机会发现断言后获取屏幕截图.觉得这个方法不错,分享给大家 这样以后在遇到断言,想截图错误屏幕的时候,能够用的上. 1.首先需要2个类,一个是测试类(TestDropL ...
- 【亲测】Appium测试Android混合应用时,第二次切换到WebView失败
要解决的问题:Appium测试Android混合应用时,第二次切换到WebView时失败 原因分析:在用Appium测试Android混合应用时,当程序第一次切换到WebView时,可以正常进行自动化 ...
- Fedora 21 安装 Nvidia 驱动以及失败后的补救方法
在 Linux 桌面系统下玩了这么久,大部分时间都是使用 Ubuntu,偶尔使用一下 Fedora.我的电脑中安装有多个 Linux 发行版,见这里<在同一个硬盘上安装多个Linux发行版及Fe ...
- 删除Windows中隐藏的物理网卡和网络虚拟化失败后的虚拟网卡
Windows环境下,在更换硬件服务器主板和网卡等硬件.恢复操作系统或者网络虚拟化失败后,可能会出现网卡方面的问题.例如,设备管理器中多了不应该存在的网卡:因命名冲突无法重命名当前网络连接:IP地址冲 ...
- testNG实现test失败后重复执行,
test失败自动执行大大提高测试结果的准确性, 1.修改testNG源码实现test失败自动执行, 首先获取testng的源码, 获取源代码,构建过程: $ git clone git://githu ...
- jmeter接口测试-线程组设置(断言失败后用例停止执行)
问题描述: jmeter跑接口用例的时候,其中一条用例的对断言失败后,后面的用例都不执行了! 解决思路1: 考虑应该有地方设置,在菜单栏找了半天没找到,百度也没有查到 解决思路2: jmeter源码导 ...
- SQL Server 2008 R2中配置作业失败后邮件发送通知
SQL Server日常维护中难免会遇到作业失败的情况.失败后自然需要知道它失败了,除了例行检查可以发现出错以外,有一个较实时的监控还是很有必要的.比较专业的监控系统比如SCOM虽然可以监控作业执行情 ...
- Appium使用Python运行appium测试的实例
Appium使用Python运行appium测试的实例 一. Appium之介绍 https://testerhome.com/topics/8038 详情参考--https://testerhom ...
- Unittest 支持 case 失败后自动截图功能的另外两种方式
原生的unittest框架是不支持case失败后自动截图的功能的,网上看了大家的解决办法,大体上分为两种:1.要么加装饰器2.也有人封装断言这里我们看看还有没有其他的更加方便的方法值得大家一起探讨一下 ...
随机推荐
- 浅谈对MJRefresh(上)下拉刷新控件的理解
MJRefresh GitHub地址:https://github.com/CoderMJLee/MJRefresh 利用业余时间研究了一下iOS的开发,发现OC特定的语法方式吸引了我,而且iOS开发 ...
- 敏捷开发系列之旅 第五站(不一样的RUP统一软件开发过程)
概述 RUP,统一软件开发过程,是一个面向对象且基于网络的程序开发方法论.根据Rational的说法,RUP就好像一个在线的指导者,他可以为所有方面和层次的程序开发提供指导方针.模板以及事例支持. ...
- js 实现图片无限横向滚动效果
门户网站好多都有产品无线滚动展现的效果: 测试demo1 -- 非无缝滚动(可以看出来从头开始的效果): css样式如下: .box{ width: 1000px; border: 1px solid ...
- Spring(十八)之页面重定向
首先说明,该示例的maven依赖可以复用Spring(十七)之表单处理还有 还有就是对应的web.xml和servlet.xml文件都能复用,不必再次修改. 说到重定向不得不提到一个转发.这里概述一下 ...
- mybatis映射文件参数处理 #{}取值与${}取值的区别
#{}:是以预编译的映射,将参数设置到sql语句中,和jdbc的preraredStatement一样,使用占位符,防止sql注入. ${}:取出的值会直接拼装在sql中,会有安全问题. 大多数情况下 ...
- 如果js设置移动端有两种方式 大家可以参考
//使用em单位 var scaleObj = { documentEle : document.documentElement, deviceWidth : document.documentEle ...
- java连接linux的三种方式(附执行命令)
# 本地调用使用JDK自带的RunTime类和Process类实现 public static void main(String[] args){ Process proc = RunTime.get ...
- 闲谈Hybrid
前言 当经常需要更换样式,产品迭代,那么我们应该考虑hybrid混合开发,上层使用Html&Css&JS做业务开发,底层透明化.上层多多样化,这种场景非常有利于前端介入,非常适合业务快 ...
- 竞赛题解 - NOIP2018 旅行
\(\mathcal {NOIP2018} 旅行 - 竞赛题解\) 坑还得一层一层的填 填到Day2T1了 洛谷 P5022 题目 (以下copy自洛谷,有删减/修改 (●ˇ∀ˇ●)) 题目描述 小 ...
- hdu_5187_zhx's contest
Problem Description As one of the most powerful brushes, zhx is required to give his juniors n probl ...