zoukankan      html  css  js  c++  java
  • APP自動化測試腳本1

    package com.lemon.day01;

    import java.net.MalformedURLException;

    import java.net.URL;

    import java.util.List;

    import org.openqa.selenium.By;

    import org.openqa.selenium.WebElement;

    import org.openqa.selenium.remote.DesiredCapabilities;

    import org.testng.Assert;

    import org.testng.annotations.BeforeMethod;

    import org.testng.annotations.Test;

    import io.appium.java_client.AppiumDriver;

    import io.appium.java_client.android.AndroidDriver;

    public class APPTest {

    AppiumDriver<WebElement> driver;

    @BeforeMethod

    public void beforeMethod() throws MalformedURLException{

    //1;添加配置

       //手工:找到设备、APP、APP某个页面

    DesiredCapabilities desiredcapabilities = new DesiredCapabilities();

    desiredcapabilities.setCapability("deviceName","127.0.0.1:52001");//设备名

    desiredcapabilities.setCapability("appPackage","com.tencent.mm");//app包,区别我们每台设备的app

      //使用命令:adb shell dumpsys activity | find "mFocusedActivity"

    desiredcapabilities.setCapability("appActivity","com.tencent.mm.ui.LauncherUI");//指定页面

      //2;创建驱动

      //remoteAddress:远程url地址

      //desiredCapablites :这个驱动期望得到的能力

    URL remoteAddress = new URL("http://127.0.0.1:4723/wd/hub");//固定不变的

    driver = new AndroidDriver<WebElement>(remoteAddress,desiredcapabilities);

    }

      @Test

       public void TestCase001() throws MalformedURLException, InterruptedException {

      //3;找到页面元素

       //自动化:程序自动定位到页面元素

      Thread.sleep(10000);

      WebElement registerBtn = driver.findElement(By.id("d36"));

      Thread.sleep(10000);  

      registerBtn.click();

      Thread.sleep(1000);

      //4;操作页面元素来模拟用户操作

      //测试用例,进入注册页面,如 昵称、手机号、密码都不输入的情况,然后点击注册

      List<WebElement> elements = driver.findElements(By.id("ht"));

      

     // WebElement nickNameInput = driver.findElement(By.id("ht"));

      //nickNameInput.sendKeys("");//输入字符串

      elements.get(0).sendKeys("");

     // WebElement mobilPhoneInput = driver.findElement(By.id("ht"));

     // mobilPhoneInput.sendKeys("");

      elements.get(1).sendKeys("");

     // WebElement pwdInput = driver.findElement(By.id("ht"));

      //pwdInput.sendKeys("");

      elements.get(2).sendKeys("");

      WebElement registerBtnn = driver.findElement(By.id("cw1"));

      boolean isEnabled = registerBtnn.isEnabled();//是否被激活

      Assert.assertFalse(isEnabled);//断言判断是否可以点击

      driver.quit();

      }

      @Test

    public void TestCase002() throws MalformedURLException, InterruptedException {

      //3;找到页面元素

       //自动化:程序自动定位到页面元素

      Thread.sleep(10000);

      WebElement registerBtn = driver.findElement(By.id("d36"));

      Thread.sleep(10000);  

      registerBtn.click();

      Thread.sleep(1000);

      //4;操作页面元素来模拟用户操作

      //测试用例,进入注册页面,如 昵称、手机号、密码都不输入的情况,然后点击注册

      List<WebElement> elements = driver.findElements(By.id("ht"));

      

     // WebElement nickNameInput = driver.findElement(By.id("ht"));

      //nickNameInput.sendKeys("");//输入字符串

      elements.get(0).sendKeys("shashe");

     // WebElement mobilPhoneInput = driver.findElement(By.id("ht"));

     // mobilPhoneInput.sendKeys("");

      elements.get(1).sendKeys("");

     // WebElement pwdInput = driver.findElement(By.id("ht"));

      //pwdInput.sendKeys("");

      elements.get(2).sendKeys("");

      WebElement registerBtnn = driver.findElement(By.id("cw1"));

      boolean isEnabled = registerBtnn.isEnabled();//是否被激活

      Assert.assertFalse(isEnabled);//断言判断是否可以点击

      driver.quit();

    }

      @Test

    public void TestCase003() throws MalformedURLException, InterruptedException {

      //3;找到页面元素

       //自动化:程序自动定位到页面元素

      Thread.sleep(10000);

      WebElement registerBtn = driver.findElement(By.id("d36"));

      Thread.sleep(10000);  

      registerBtn.click();

      Thread.sleep(1000);

      //4;操作页面元素来模拟用户操作

      //测试用例,进入注册页面,如 昵称、手机号、密码都不输入的情况,然后点击注册

      List<WebElement> elements = driver.findElements(By.id("ht"));

      

     // WebElement nickNameInput = driver.findElement(By.id("ht"));

      //nickNameInput.sendKeys("");//输入字符串

      elements.get(0).sendKeys("shashe");

     // WebElement mobilPhoneInput = driver.findElement(By.id("ht"));

     // mobilPhoneInput.sendKeys("");

      elements.get(1).sendKeys("15111916767");

     // WebElement pwdInput = driver.findElement(By.id("ht"));

      //pwdInput.sendKeys("");

      elements.get(2).sendKeys("");

      WebElement registerBtnn = driver.findElement(By.id("cw1"));

      boolean isEnabled = registerBtnn.isEnabled();//是否被激活

      Assert.assertFalse(isEnabled);//断言判断是否可以点击

      driver.quit();

    }

    }

  • 相关阅读:
    vue part1 基础
    【转载】NBU异机恢复oracle
    【转载】跨域请求
    [转载] django contenttypes
    rest_framework setting
    rest_framework 视图/路由/渲染器/认证授权/节流
    【转载整理】 mysql百万级数据库分页性能
    rest_framework 分页
    rest_framework 序列化
    django middleware
  • 原文地址:https://www.cnblogs.com/shashe/p/8711558.html
Copyright © 2011-2022 走看看