zoukankan      html  css  js  c++  java
  • appium向前进步一点点

     之前获取元素一直失败,报异常错误,定位不到,排出不是没有元素的原因,后来更新了下appium的版本和更换了导入的包才成功

    看到junit执行成功的一瞬间 ,简直哭了

    1、Returned value cannot be converted to WebElement: {ELEMENT=1}

    2、org.openqa.selenium.NoSuchElementException: An element could not be located on the page using the gi

    3、java.lang.NoSuchFieldError: INSTANCE

    大致是这三种错误:

    之前我导入的包是

    后来更换为

    这个是打开模拟器计算器后点击相应数字及符号

    package com;
    import java.net.URL;
    import java.util.List;
    import java.util.concurrent.TimeUnit;
    import org.junit.After;
    import org.junit.Before;
    import org.junit.Test;
    import org.openqa.selenium.By;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.remote.DesiredCapabilities;
    
    import io.appium.java_client.android.AndroidDriver;
    
    
    
    public class AppTest {
        AndroidDriver<WebElement> driver;
        @Before
        public void setUp() throws Exception {
            DesiredCapabilities cap=new DesiredCapabilities();
            cap.setCapability("deviceName","emulator-5554");//测试设备名称
            cap.setCapability("platformVersion", "5.1.1");//平台版本
            cap.setCapability("appPackage", "com.android.calculator2");//应用(计算器)的包名
            cap.setCapability("appActivity", ".Calculator");//应用(计算器)启动的Activity名称       
            cap.setCapability("automationName", "Appium");//指定自动化的引擎,默认appium
            cap.setCapability("platformName", "Android");//平台名称
            driver = new AndroidDriver<>(new URL("http://127.0.0.1:4723/wd/hub"), cap);
           
        } 
    
        @After
        public void tearDown() throws Exception {
            driver.quit();
        }
    
        @Test
        public void test() throws InterruptedException {
            
            driver.manage().timeouts().implicitlyWait(40, TimeUnit.SECONDS);//隐式等待,若找到元素,直接往下进行,无需完成等待时间
            driver.findElement(By.id("digit_6")).click();
            List<WebElement> btnList=driver.findElementsByClassName("android.widget.Button");
            WebElement btn7=btnList.get(0);
            btn7.click();
            driver.findElementById("com.android.calculator2:id/op_mul").click();
            
            Thread.sleep(8000);//显示等待,必须等待时间结束后才执行下一步
            //driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
        
            driver.findElementByXPath("//android.widget.Button[contains(@text,'5')]").click();
        driver.findElementByAndroidUIAutomator("new UiSelector().text("2")").click();
            driver.findElementByAccessibilityId("equals").click();
    
                    
            Thread.sleep(2000);
            
            
        }
    
    }
  • 相关阅读:
    使用鼠标
    TCP编程函数和步骤
    ASP.NET MVC+EF框架+EasyUI实现
    线性表简介
    一个项目的简单开发流程——需求、数据库、编码
    图像处理网络资源
    OPENCV 中的图像旋转与缩放
    命令行下面使用MAKEFILE方式编译OPENCV程序
    OpenCV In Thanksgiving Day
    OpenCV 下面的图像亮度变换 Intensity transformation
  • 原文地址:https://www.cnblogs.com/snailvsstar/p/9188356.html
Copyright © 2011-2022 走看看