• 功能很强大,非常棒啊!.已 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