• 功能很强大,非常棒啊!.已 star。

  • 用 appium 可以提高测试的技能,但刚开始可能速度慢,需要一定的编程经验
    商业工具 UI 友好,效率可能高点

  • 公司想在商业工具内选型

  • qq:52795474

  • 嗯, 用错了,应该是 closeapp, 再 launchapp

  • 我把手机内的 appium 的预装的输入法卸载了,就好了。

  • 解决问题,奖励 800 块

  • 2.UserLogin.java: 用于测试登录功能

    package com.tebon.tebonadvapptest.deal.userlogin;

    import org.testng.annotations.Test;

    import com.tebon.tebonadvapptest.TebonAppTestDriver;

    import io.appium.java_client.TouchAction;
    import io.appium.java_client.android.AndroidDriver;
    import io.appium.java_client.android.AndroidElement;
    import junit.framework.Assert;

    import org.testng.annotations.BeforeTest;

    import java.util.List;
    import java.util.Set;
    import java.util.concurrent.TimeUnit;

    import org.openqa.selenium.WebElement;
    import org.testng.Reporter;
    import org.testng.annotations.AfterClass;
    import org.testng.annotations.AfterTest;
    import org.testng.annotations.BeforeClass;

    public class UserLogin {

    private AndroidDriver driver;

    @Test(priority = 1)
    public void StartupApp() throws InterruptedException {

    //swipe pages of startup screen
    int width = driver.manage().window().getSize().width;
    int height = driver.manage().window().getSize().height;

    int srcwid = width-10;
    int srcheight = height/2;
    new TouchAction(driver).press(srcwid,srcheight).moveTo(-350, 0).release().perform();
    Thread.sleep(5000);

    new TouchAction(driver).press(srcwid,srcheight).moveTo(-350, 0).release().perform();
    Thread.sleep(5000);

    //点击'立即体验'按钮进入主界面
    driver.findElementByXPath("//android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/"
    + "android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.RelativeLayout/"
    + "android.view.ViewGroup/android.widget.RelativeLayout/android.widget.Button").click();

    Thread.sleep(5000);

    Reporter.log("StartupApp: 德邦高端 APP 启动测试用例通过!");
    }

    @Test(priority = 2)
    public void InputEmptyDealAccount() throws InterruptedException {

    driver.findElementByXPath("//android.widget.FrameLayout[@resource-id='android:id/content']/android.widget.RelativeLayout/"
    + "android.widget.LinearLayout/android.widget.RelativeLayout/android.view.ViewGroup/"
    + "android.widget.FrameLayout/android.widget.LinearLayout/android.widget.RelativeLayout/"
    + "android.widget.LinearLayout[2]/android.widget.LinearLayout/android.widget.ImageView").click();
    Thread.sleep(5000);
    driver.findElementByXPath("//android.view.View[@content-desc='点击请登录']").click();
    Thread.sleep(5000);

    //手机验证码登录
    driver.findElementById("com.tebonsc:id/edit_PhoneNumber").sendKeys("13900000000");
    driver.findElementById("com.tebonsc:id/image_yanzhengma").click();
    Thread.sleep(5000);
    driver.findElementById("com.tebonsc:id/iamge_login").click();
    Thread.sleep(5000);

    //交易账号登录
    driver.findElementById("com.tebonsc:id/login").click();
    Thread.sleep(1000);
    String loginhint = driver.findElementByXPath("//android.widget.TextView[@text='输入的账号不能为空!']").getText();
    if(loginhint.contains("输入的账号不能为空")) Assert.assertEquals(true, true);

    driver.findElementByXPath("//android.widget.Button[@text='确定']").click();
    Thread.sleep(1000);
    Reporter.log("InputEmptyDealAccount: 未输入客户号进行登录测试通过!");

    }

    @Test(priority = 2)
    public void LoginSuccess() throws InterruptedException {

    driver.findElementById("com.tebonsc:id/edit_account").sendKeys("99006");

    //List elist = driver.findElementsByXPath("//*");

    Thread.sleep(5000);
    driver.findElementById("com.tebonsc:id/edit_password").sendKeys("111111");
    Thread.sleep(15000);
    driver.findElementById("com.tebonsc:id/login").click();
    Thread.sleep(10000);

    //Check login dealing account info
    String dealaccount = driver.findElementByXPath("//android.view.View[@content-desc='王']").toString();
    if(dealaccount.contains("王
    ")) Assert.assertEquals(true, true);
    String saledepart = driver.findElementByXPath("//android.view.View[@content-desc='上海凉城路证券营业部']").toString();
    if(dealaccount.contains("上海凉城路证券营业部")) Assert.assertEquals(true, true);

    Thread.sleep(5000);

    //swipe to Main UI of APP for later test
    int width = driver.manage().window().getSize().width;
    int height = driver.manage().window().getSize().height;
    int srcwid = width-10;
    int srcheight = height/2;
    driver.tap(1, srcwid, srcheight, 500);
    Thread.sleep(5000);

    Reporter.log("LoginSuccess: 12 位客户号正常登录测试通过!");

    }

    @BeforeClass
    public void InitialAppTestDriver() throws Exception {
    TebonAppTestDriver.getInstance().setup();
    driver = TebonAppTestDriver.getInstance().getDriver();
    }

    @AfterClass
    public void afterTest() {
    TebonAppTestDriver.getInstance().ReleaseDriver();
    }

    }

    运行 InputEmptyDealAccount(),是没问题的,
    但是运行到用例 LoginSuccess() 的第一条语句
    driver.findElementById("com.tebonsc:id/edit_account").sendKeys("99006");

    程序就报 element is not located.
    PASSED: StartupApp
    PASSED: InputEmptyDealAccount
    FAILED: LoginSuccess
    org.openqa.selenium.NoSuchElementException: An element could not be located on the page using the given search parameters. (WARNING: The server did not provide any stacktrace information)
    Command duration or timeout: 9.00 seconds

    请问什么原因啊?搞了好久了,始终找不出原因.谁要知道原因,解决问题了,一定给现金奖励哦。绝不虚言。

  • 2 个 java 文件:
    1.TebonAppTestDriver.java: 初始化 driver

    package com.tebon.tebonadvapptest;

    import java.io.File;
    import java.net.URL;

    import org.openqa.selenium.remote.DesiredCapabilities;

    import io.appium.java_client.android.AndroidDriver;
    import io.appium.java_client.android.AndroidElement;

    public class TebonAppTestDriver {

    private TebonAppTestDriver(){}

    private static TebonAppTestDriver instance = new TebonAppTestDriver();

    public static TebonAppTestDriver getInstance()
    {

    return instance;

    }

    private static AndroidDriver driver;

    public AndroidDriver getDriver() {
    return driver;
    }

    private boolean isNotInstall = false;

    public void setup() throws Exception {

    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("deviceName", "3HX5T17114002385");
    capabilities.setCapability("automationName", "Appium");
    capabilities.setCapability("platformName", "Android");
    //capabilities.setCapability("platformVersion", "23");
    capabilities.setCapability("platformVersion", "7.0");

    // 配置测试 apk
    capabilities.setCapability("appPackage", "com.tebonsc");
    capabilities.setCapability("appActivity", "com.zztzt.android.simple.activity.tztCommHeadPageActivity");
    capabilities.setCapability("sessionOverride", true); // 每次启动时覆盖 session,否则第二次后运行会报错不能新建 session
    capabilities.setCapability("unicodeKeyboard", true); // 设置键盘
    capabilities.setCapability("resetKeyboard", false); // 设置默认键盘为 appium 的键盘
    //capabilities.setCapability("automationName", "uiautomator2");

    //ios 专用,当 iOS 的个人信息访问警告 (如 位置、联系人、图片) 出现时,自动选择接受 ( Accept )。默认值 false
    capabilities.setCapability("autoAcceptAlerts", true);

    if (isNotInstall) {
    File classpathRoot = new File(System.getProperty("user.dir"));
    File appDir = new File(classpathRoot, "apps");
    File app = new File(appDir, "TztTebonGenApp2-hs03-release.apk");
    capabilities.setCapability("app", app.getAbsolutePath());
    }

    driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
    Thread.sleep(5000);
    }

    public void ReleaseDriver() {
    driver.quit();
    }
    }

    后面附上用例的代码

  • appium-setting,appium-unlock 都从手机上卸载掉了,桌面上没找的 appium inputxxx

  • 换成 7.0 就不报连不上的错误了,但是报下面的错误:
    [MJSONWP] Encountered internal error running command: Error: Error executing adbExec. Original error: 'Command 'D:\android-sdk\platform-tools\adb.exe -P 5037 -s 3HX5T17114002385 install C:\Users\wuqs\AppData\Local\Programs\appium-desktop\resources\app\node_modules\appium\node_modules\appium-android-ime\bin\UnicodeIME-debug.apk' exited with code 1'; Stderr: 'adb: failed to install C:\Users\wuqs\AppData\Local\Programs\appium-desktop\resources\app\node_modules\appium\node_modules\appium-android-ime\bin\UnicodeIME-debug.apk: Failure [INSTALL_FAILED_UPDATE_INCOMPATIBLE: Package io.appium.android.ime signatures do not match the previously installed version; ignoring!]'; Code: '1'

  • 这个 DesiredCapabilities 设置的有问题吗
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("deviceName", "3HX5T17114002385");

    capabilities.setCapability("automationName", "Appium");
    capabilities.setCapability("platformName", "Android");
    capabilities.setCapability("platformVersion", "24");

    // 配置测试 apk
    capabilities.setCapability("appPackage", "com.tebonsc");
    capabilities.setCapability("appActivity", "com.zztzt.android.simple.activity.tztCommHeadPageActivity");
    capabilities.setCapability("sessionOverride", true); // 每次启动时覆盖 session,否则第二次后运行会报错不能新建 session
    capabilities.setCapability("unicodeKeyboard", true); // 设置键盘
    capabilities.setCapability("resetKeyboard", false); // 设置默认键盘为 appium 的键盘
    capabilities.setCapability("automationName", "uiautomator2");

    //ios 专用,当 iOS 的个人信息访问警告 (如 位置、联系人、图片) 出现时,自动选择接受 ( Accept )。默认值 false
    capabilities.setCapability("autoAcceptAlerts", true);

    if (isNotInstall) {
    File classpathRoot = new File(System.getProperty("user.dir"));
    File appDir = new File(classpathRoot, "apps");
    File app = new File(appDir, "TztTebonGenApp2-hs03-release.apk");
    capabilities.setCapability("app", app.getAbsolutePath());
    }

    driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);

  • 怎么填,在哪填

  • case 在 appium:1.4.16.1 用这个配置运行没报错啊,
    手机也确实是 android 7.0(API 24),

  • 和 app 的作者沟通了下,好像实现没用 webview

  • driver.getPageSource() 会执行大概 20 秒,然后 app 就会推出,此时拿到的内容也不是 app 登录页面的内容,而是手机主页的内容

  • 使用 driver.getContextHandles() 只获取到 NATIVE APP 的情况,我的手机 android 版本是 android 7.0

  • 我打开开发者选项中显示布局边界选项,没看出是 webview,请大神指教

  • 怎么看出是 webview,我 看了下,没看出是 webview,请指教,如果进入这个登录页面后,不点击登录按钮,直接先输入客户号,是可以找到客户号编辑框的。
    只有进入这个页面后,什么都不输入,直接点击登录,然后弹出 “客户号不能为空” 信息框,点击确定后,再定位客户号编辑框,就找不到这个编辑框了。我上面的代码有问题吗?

  • 如何切换,我试了这个代码好像不行 driver.context("webview");
    请指教

  • 我发现在第一个测试用例,执行过 点击确定按钮之后,这个页面上的所有元素都定位不了。奇怪,这是什么道理。

  • 没明白,你说的意思。能再具体点吗

  • 我查了,就是那个交易账号的编辑框 "com.tebonsc:id/edit_account" 没定位到。

  • 两个测试用例:
    先执行第一个测试用例 (priority=2),用户不输入交易账号,直接点击登录,弹出一个消息框"输入的账号不能为空!",点击"确定"按钮
    再执行第二个测试用例 (priority=3),调用代码(driver.findElementById("com.tebonsc:id/edit_account").sendKeys("99006");)自动输入交易账号,这时就报下面的错误:

    org.openqa.selenium.NoSuchElementException: An element could not be located on the page using the given search parameters. (WARNING: The server did not provide any stacktrace information)
    Command duration or timeout: 44 milliseconds

    下面是这两个测试用例的代码:
    @Test(priority = 2)
    public void InputEmptyDealAccount() throws InterruptedException {

    driver.findElementByXPath("//android.widget.FrameLayout[@resource-id='android:id/content']/android.widget.RelativeLayout/"
    + "android.widget.LinearLayout/android.widget.RelativeLayout/android.view.ViewGroup/"
    + "android.widget.FrameLayout/android.widget.LinearLayout/android.widget.RelativeLayout/"
    + "android.widget.LinearLayout[2]/android.widget.LinearLayout/android.widget.ImageView").click();
    Thread.sleep(5000);
    driver.findElementByXPath("//android.view.View[@content-desc='点击请登录']").click();
    Thread.sleep(5000);

    //手机验证码登录
    driver.findElementById("com.tebonsc:id/edit_PhoneNumber").sendKeys("13900000000");
    driver.findElementById("com.tebonsc:id/image_yanzhengma").click();
    Thread.sleep(5000);
    driver.findElementById("com.tebonsc:id/iamge_login").click();
    Thread.sleep(5000);

    //交易账号登录
    driver.findElementById("com.tebonsc:id/login").click();
    Thread.sleep(5000);

    String loginhint = driver.findElementByXPath("//android.widget.TextView[@text='输入的账号不能为空!']").getText();
    if(loginhint.contains("输入的账号不能为空")) Assert.assertEquals(true, true);

    driver.findElementByXPath("//android.widget.Button[@text='确定']").click();

    Thread.sleep(5000);

    //driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
    Reporter.log("InputEmptyDealAccount: 未输入客户号进行登录测试通过!");

    }

    @Test(priority = 3)
    public void LoginSuccess() throws InterruptedException {

    //交易账号登录
    driver.findElementById("com.tebonsc:id/edit_account").sendKeys("99006");
    Thread.sleep(5000);
    driver.findElementById("com.tebonsc:id/edit_password").sendKeys("111111");
    Thread.sleep(15000);
    driver.findElementById("com.tebonsc:id/login").click();
    Thread.sleep(10000);

    //Check login dealing account info
    String dealaccount = driver.findElementByXPath("//android.view.View[@content-desc='王']").toString();
    if(dealaccount.contains("王
    ")) Assert.assertEquals(true, true);
    String saledepart = driver.findElementByXPath("//android.view.View[@content-desc='上海凉城路证券营业部']").toString();
    if(dealaccount.contains("上海凉城路证券营业部")) Assert.assertEquals(true, true);

    Thread.sleep(5000);

    //swipe to Main UI of APP for later test
    int width = driver.manage().window().getSize().width;
    int height = driver.manage().window().getSize().height;
    int srcwid = width-10;
    int srcheight = height/2;
    driver.tap(1, srcwid, srcheight, 500);
    Thread.sleep(5000);

    Reporter.log("LoginSuccess: 12 位客户号正常登录测试通过!");

    }