Allure是一款开源的报告框架

一、搭建环境步骤

1.集成依赖

<!--https://mvnrepository.com/artifact/io.qameta.allure/allure-testng--><dependency><groupId>io.qameta.allure</groupId><artifactId>allure-testng</artifactId><version>2.12.1</version></dependency>

2.设置编码,避免乱码

<properties><aspectj.version>1.8.10</aspectj.version><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding><maven.compiler.encoding>UTF-8</maven.compiler.encoding></properties>

3.引入Maven surefire插件:生成Allure报表

<build><plugins><plugin><!--maven-surefire-plugin配合testng/junit执行测试用例的maven插件--><groupId>org.apache.maven.plugins</groupId><artifactId>maven-surefire-plugin</artifactId><version>2.22.1</version><configuration><!--测试失败后,是否忽略并继续测试--><testFailureIgnore>true</testFailureIgnore><suiteXmlFiles><!--testng配置文件名称--><suiteXmlFile>testng.xml</suiteXmlFile></suiteXmlFiles><!--设置参数命令行--><argLine><!--UTF-8编码-->-Dfile.encoding=UTF-8<!--配置拦截器-->-javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"</argLine><systemProperties><property><!--配置allure结果存储路径--><name>allure.results.directory</name><value>${project.build.directory}/allure-results</value></property></systemProperties></configuration><dependencies><!--aspectjweavermaven坐标--><dependency><groupId>org.aspectj</groupId><artifactId>aspectjweaver</artifactId><version>${aspectj.version}</version></dependency></dependencies></plugin><!--maven-compiler-plugin确保maven工程JDK版本为1.8,不会变--><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><configuration><source>8</source><target>8</target></configuration></plugin></plugins></build>

4.构建测试:mvn tes

注意:要生成Allure...

阅读全文

log4j是一个日志框架,配置简单,功能强大,在项目中用来记录日志很方便

使用log4j的操作步骤

1.引入Log4j依赖

<!--https://mvnrepository.com/artifact/log4j/log4j--><dependency><groupId>log4j</groupId><artifactId>log4j</artifactId><version>1.2.17</version></dependency>

2.配置Log4j.properties文件(存放在resources目录下

#根logger主要定义log4j支持的日志级别及输出目的地log4j.rootLogger=INFO,console,file###输出信息到控制台配置####表示输出到控制台log4j.appender.console=org.apache.log4j.ConsoleAppender#将System.out作为输出log4j.appender.console.Target=System.out#使用灵活的布局展示日志信息log4j.appender.console.layout=org.apache.log4j.PatternLayout#日志详细输出信息样式log4j.appender.console.layout.ConversionPattern=%d{yyyy-MM-ddHH:mm:ss}%-5p%c{1}:%L-%m%n###输出信息到文件中配置####每天产生一个日志文件log4j.appender.file=org.apache.log4j.DailyRollingFileAppender#输出文件目的地log4j.appender.file.File=log/web_auto.log#新的日志信息是否追加到旧的日志文件末尾log4j.appender.file.Append=false#使用灵活的布局展示日志信息log4j.appender.file.layout=org.apache.log4j.PatternLayout#日志详细输出信息样式log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-ddHH:mm:ss}%-5p%c{1}:%L-%m%n

3.使用方式...

阅读全文

一、手势操作-滑动

下拉刷新

//下拉刷新-向下滑动//按住起始点->滑动到终止点位置上->手指抬起TouchActiontouchAction=newTouchAction(driver);//起始点PointOptionstartPoint=PointOption.point(424,632);//终止点PointOptionendPoint=PointOption.point(424,1000);//设置滑动时间-waitOptions类型的参数WaitOptionswaitOptions=WaitOptions.waitOptions(Duration.ofMillis(1000));touchAction.press(startPoint).waitAction(waitOptions).moveTo(endPoint).release().perform();/***向下滑动的通用封装*@paramswipeTime滑动时间*/publicstaticvoidswipeDown(longswipeTime){//约定滑动起始点与终止点的位置//滑动起始点:1/2宽度1/4高度滑动终止点:1/2宽度3/4高度intscreenWidth=driver.manage().window().getSize().getWidth();intscreenHeight=driver.manage().window().getSize().getHeight();TouchActiontouchAction=newTouchAction(driver);//起始点(424,632)PointOptionpointOptionA=PointOption.point(screenWidth/2,screenHeight/4);//终止点(424,1000)PointOptionpointOptionB=PointOption.point(screenWidth/2,screenHeight*3/4);//设置滑动时间-waitOptions类型的参数WaitOptionswaitOptions=WaitOptions.waitOptions(Duration.ofMillis(swipeTime));touchAction.press(pointOptionA).waitAction(waitOptions).moveTo(pointOptionB).release().perform();}/***向上滑动的通用封装*@paramswipeTime滑动时间*/publicstaticvoidswipeUp(longswipeTime){//约定滑动起始点与终止点的位置//滑动起始点:1/2宽度1/4高度滑动终止点:1/2宽度3/4高度intscreenWidth=driver.manage().window().getSize().getWidth();intscreenHeight=driver.manage().window().getSize().getHeight();TouchActiontouchAction=newTouchAction(driver);//起始点(424,632)PointOptionpointOptionA=PointOption.point(screenWidth/2,screenHeight*3/4);//终止点(424,1000)PointOptionpointOptionB=PointOption.point(screenWidth/2,screenHeight/4);//设置滑动时间-waitOptions类型的参数WaitOptionswaitOptions=WaitOptions.waitOptions(Duration.ofMillis(swipeTime));touchAction.press(pointOptionA).waitAction(waitOptions).moveTo(pointOptionB).release().perform();}/***向左滑动的通用封装*@paramswipeTime滑动时间*/publicstaticvoidswipeLeft(longswipeTime){//约定滑动起始点与终止点的位置//滑动起始点:1/2宽度1/4高度滑动终止点:1/2宽度3/4高度intscreenWidth=driver.manage().window().getSize().getWidth();intscreenHeight=driver.manage().window().getSize().getHeight();TouchActiontouchAction=newTouchAction(driver);//起始点(424,632)PointOptionpointOptionA=PointOption.point(screenWidth*3/4,screenHeight/2);//终止点(424,1000)PointOptionpointOptionB=PointOption.point(screenWidth/4,screenHeight/2);//设置滑动时间-waitOptions类型的参数WaitOptionswaitOptions=WaitOptions.waitOptions(Duration.ofMillis(swipeTime));touchAction.press(pointOptionA).waitAction(waitOptions).moveTo(pointOptionB).release().perform();}/***向右滑动的通用封装*@paramswipeTime滑动时间*/publicstaticvoidswipeRight(longswipeTime){//约定滑动起始点与终止点的位置//滑动起始点:1/2宽度1/4高度滑动终止点:1/2宽度3/4高度intscreenWidth=driver.manage().window().getSize().getWidth();intscreenHeight=driver.manage().window().getSize().getHeight();TouchActiontouchAction=newTouchAction(driver);//起始点(424,632)PointOptionpointOptionA=PointOption.point(screenWidth/4,screenHeight/2);//终止点(424,1000)PointOptionpointOptionB=PointOption.point(screenWidth*3/4,screenHeight/2);//设置滑动时间-waitOptions类型的参数WaitOptionswaitOptions=WaitOptions.waitOptions(Duration.ofMillis(swipeTime));touchAction.press(pointOptionA).waitAction(waitOptions).moveTo(pointOptionB).release().perform();}//场景:滑动到页面底部driver.findElement(By.id("com.lemon.lemonban:id/navigation_tiku")).click();driver.findElement(By.id("com.lemon.lemonban:id/button_go_login")).click();driver.findElement(By.id("com.lemon.lemonban:id/et_mobile")).sendKeys("13323234545");driver.findElement(By.id("com.lemon.lemonban:id/et_password")).sendKeys("234545");driver.findElement(By.id("com.lemon.lemonban:id/btn_login")).click();driver.findElement(MobileBy.AndroidUIAutomator("newUiSelector().text(\"软件测试基础\")")).click();driver.findElement(By.id("com.lemon.lemonban:id/first_level")).click();Thread.sleep(3000);//循环滑动while(true){//滑动前的页面源代码StringbeforeSource=driver.getPageSource();swipeUp(1000);Thread.sleep(1000);//什么时候跳出循环呢?//1、等待【全部加载完成】出来之后?缺点:(1)必须要保证此元素要立马出来(2)有些页面没有这个提示//通过getPageSource进行判断/*if(driver.getPageSource().contains("全部加载完成")){break;}*///2、getPageSource,通过滑动前后页面的pageSource是不是发生变化//滑动之后的页面源代码StringafterSource=driver.getPageSource();if(afterSource.equals(beforeSource)){//滑动到了页面的底部break;}}

二、特殊场景元素定位

1.toast元素定位

Android中的Toast是一种简易的消息提示框,当视图显示给用户,在应用程序中显示为浮动和Dialog不一样的是,它永远不会获得...

阅读全文