一、手势操作-滑动

下拉刷新

//下拉刷新-向下滑动//按住起始点->滑动到终止点位置上->手指抬起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不一样的是,它永远不会获得...

阅读全文

一、WebElement常用AP

click():触发当前元素的点击事件

clear():清空内容

sendKeys():文本框中写入内容、按键操作

element.sendKeys(Keys.CONTROL,"a");//ctrl+a全选element.sendKeys(Keys.CONTROL,"x");//ctrl+x剪切element.sendKeys(Keys.CONTROL,"c");//ctrl+c复制element.sendKeys(Keys.CONTROL,"v");//ctrl+v粘贴element.sendKeys(Keys.ENTER);//回车element.sendKeys(Keys.BACK_SPACE);//删除element.sendKeys(Keys.SPACE);//空格键

getTagName():获取元素的标签名

getAttribute(属性名):根据属性名获取元素属性值...

阅读全文