Appium mobile end test automation - Record and run test cases

Article directories are as follows

To record and perform with cases

  • Use Appium desktop use cases recorded
  • Python mounted reliance pip install Appium-Python-Client
  • Implicit increase waiting enhance stability
  • Re-run

1, using the recording Appium desktop use cases

autoGrantPermissions = true # is no longer out of the positioning information
Here Insert Picture Description
to select the lower right Send Keys, out of the input box, enter a search term and click on the Send Keys button.
Here Insert Picture Description
After the contents of the recorded script can be seen and can choose the type, as shown below:
1, Fragment
2, select the script language
. 3, all of the scripting language --Python

# This sample code uses the Appium python client
# pip install Appium-Python-Client
# Then you can paste this into a file and simply run with Python
from appium import webdriver
caps = {}
caps["platformName"] = "android"
caps["deviceName"] = "pzhang7"
caps["automationName"] = "uiautomator2"
caps["appPackage"] = "com.xueqiu.android"
caps["appActivity"] = ".view.WelcomeActivityAlias"
caps["autoGrantPermissions"] = "true"

driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", caps)

el1 = driver.find_element_by_id("com.xueqiu.android:id/home_search")
el1.click()
el2 = driver.find_element_by_id("com.xueqiu.android:id/search_input_text")
el2.send_keys("alibaba")
driver.quit()
4、复制脚本
5、删除脚本

Here Insert Picture Description
(3) show all scripting languages ​​--Java

import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;
import junit.framework.TestCase;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.remote.DesiredCapabilities;

public class SampleTest {

  private AndroidDriver driver;

  @Before
  public void setUp() throws MalformedURLException {
    DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
    desiredCapabilities.setCapability("platformName", "android");
    desiredCapabilities.setCapability("deviceName", "pzhang7");
    desiredCapabilities.setCapability("automationName", "uiautomator2");
    desiredCapabilities.setCapability("appPackage", "com.xueqiu.android");
    desiredCapabilities.setCapability("appActivity", ".view.WelcomeActivityAlias");
    desiredCapabilities.setCapability("autoGrantPermissions", "true");

    URL remoteUrl = new URL("http://127.0.0.1:4723/wd/hub");

    driver = new AndroidDriver(remoteUrl, desiredCapabilities);
  }

  @Test
  public void sampleTest() {
    MobileElement el1 = (MobileElement) driver.findElementById("com.xueqiu.android:id/home_search");
    el1.click();
    MobileElement el2 = (MobileElement) driver.findElementById("com.xueqiu.android:id/search_input_text");
    el2.sendKeys("alibaba");
  }

  @After
  public void tearDown() {
    driver.quit();
  }
}

2, mounted reliance Pythony Appium-Python-Client

After the script to run properly store the Python script to any local path, in the top three rows Python script description can be seen say you want to install Appium-Python-Client

pip install Appium-Python-Client

Here Insert Picture Description
Exit Appium recording interface;
and then switch to the cmd interface, and execute the Python script, as shown below, abnormal information, in fact, no element found
Here Insert Picture Description

3, increasing the waiting enhance stability implicit

Rerun added after waiting for the code above to implicitly
driver.implicitly_wait (10) # wait 10 seconds was added Implicit

# This sample code uses the Appium python client
# pip install Appium-Python-Client
# Then you can paste this into a file and simply run with Python

from appium import webdriver

caps = {}
caps["platformName"] = "android"
caps["deviceName"] = "pzhang7"
caps["automationName"] = "uiautomator2"
caps["appPackage"] = "com.xueqiu.android"
caps["appActivity"] = ".view.WelcomeActivityAlias"
caps["autoGrantPermissions"] = "true"

driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", caps)

driver.implicitly_wait(10) #添加隐式等待10秒

el1 = driver.find_element_by_id("com.xueqiu.android:id/home_search")
el1.click()
el2 = driver.find_element_by_id("com.xueqiu.android:id/search_input_text")
el2.send_keys("alibaba")

driver.quit()

4, re-run

Re-run test cases, after waiting 10 seconds can be a normal operation.

Guess you like

Origin www.cnblogs.com/PeterZhang1520389703/p/12013959.html