日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

appium第一个安卓自动化工程

發(fā)布時(shí)間:2025/5/22 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 appium第一个安卓自动化工程 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

轉(zhuǎn)自:https://university.utest.com/how-to-set-up-your-first-android-automation-project-with-appium/

Appium?is an open-source tool for automating native, mobile web, and hybrid applications on iOS and Android platforms. Native apps are those written using the iOS or Android SDKs. Mobile web apps are web apps accessed using a mobile browser (Appium supports Safari on iOS and Chrome or the built-in ‘Browser’ app on Android). Hybrid apps have a wrapper around a “webview” — a native control that enables interaction with web content. Projects likePhonegap, make it easy to build apps using web technologies that are then bundled into a native wrapper, creating a hybrid app.

Importantly, Appium is cross-platform. It allows you to write tests against multiple platforms (iOS and Android), using the same API. This enables code reuse between iOS and Android test suites.

For this example, I will use a contact manager app provided by Appium as a sample app and a Samsung Galaxy S4 with Android 4.4.2.?Get?Contact Manager at GitHub.

PREREQUISITES

  • Eclipse is installed
  • Android SDK and APIs for recent versions of Android
  • Selenium Webdriver knowledge
  • Java knowledge
  • SETUP

  • Download?Selenium Java zip archive?and extract all the files in a folder called Selenium.
  • Download?Appium for Windows zip archive?and extract all files in a folder called Appium.
  • Download?Appium Java client?jar and add it to Apium folder. This contains abstract class AppiumDriver which inherits from Selenium Java client. IOSDriver and AndroidDriver both extend AppiumDriver and add specific methods for Android and iOS automation. Basically this is an adaptation of Selenium Java client,but adapted to mobile automation.
  • Create a new java project in Eclipse and add Selenium and Appium Java client Jar files to the project ( Right-click project -> Properties -> java build path -> Add external JARs).
  • Add a package and a new class to the project.
  • IMPORT REQUIRED LIBRARIES

    1. The first step in writing a new test class is to import the needed libraries:

    //used to verify if URL is malformed
    import java.net.MalformedURLException;

    //library used to create URL for the Appium server
    import java.net.URL;

    //library used to create the path to APK
    import java.io.File;

    //library used to find elements (by id, class, xpath etc)
    import org.openqa.selenium.By;

    //library for web element
    import org.openqa.selenium.WebElement;

    //libraries for configuring Desired Capabilities
    import org.openqa.selenium.remote.CapabilityType;
    import org.openqa.selenium.remote.DesiredCapabilities;

    //library for test methods
    import org.junit.*;

    //library for Appium drivers
    import io.appium.java_client.AppiumDriver;
    import io.appium.java_client.android.AndroidDriver;

    CREATING THE PATH TO APK FILE

    Since the apk is stored in the computer and is not already installed on the device we need to create a file object which represents the actual apk file on the disk. I placed the folder ContactManager which contains the apk file inside the Eclipse project.

    File classpathRoot = new File(System.getProperty(“user.dir”)); // path to Eclipse project
    File appDir = new File(classpathRoot, “/ContactManager”); // path to <project folder>/Contact Manager
    File app = new File(appDir, “ContactManager.apk”); path to <project folder>/Contact Manager/ContactManager.apk

    DESIRED CAPABILITIES

    To be able to test the app on an actual device Desired Capabilities need to be set. Desired Capabilities are a set of keys and values sent to the Appium server to tell the server what kind of automation session we’re interested in starting up. There are also capabilities used to modify the behaviour of the server during automation.

    DesiredCapabilities capabilities = new DesiredCapabilities();

    //Name of mobile web browser to automate. Should be an empty string if automating an app instead.
    capabilities.setCapability(CapabilityType.BROWSER_NAME, “”);

    //which mobile OS to use: Android, iOS or FirefoxOS
    capabilities.setCapability(“platformName”, “Android”);

    //Mobile OS version – in this case 4.4 since my device is running Android 4.4.2
    capabilities.setCapability(CapabilityType.VERSION, “4.4”);

    //device name – since this is an actual device name is found using ADB
    capabilities.setCapability(“deviceName”, “111bd508″);

    //the absolute local path to the APK
    capabilities.setCapability(“app”, app.getAbsolutePath());

    //Java package of the tested Android app
    capabilities.setCapability(“appPackage”, “com.example.android.contactmanager”);

    // activity name for the Android activity you want to run from your package. This need to be preceded by a . (example: .MainActivity)
    capabilities.setCapability(“appActivity”, “.ContactManager”);

    // constructor to initialize driver object
    driver = new AndroidDriver(new URL(“http://127.0.0.1:4723/wd/hub”), capabilities);

    HOW TO FIND DEVICENAME

    Since we are trying to run the test on an actual device we need to use ADB to find the device name. This is required when creating desired capabilities to specify on what device you want your tests to be run.?You can use this course?to see how to use “adb devices” to find your device id. Once you run adb devices command the only thing left is to copy the device id in the code.

    HOW TO FIND APPPACKAGE AND APPACTIVITY FOR APK FILE

  • Download and install SDK.
  • Inside SDK Manager download Tools (Android SDK build-tools) and APIs for recent versions of Android.
  • Open SDK folder and go to build-tools folder.
  • Open any folder (example: 21.1.2).
  • Open a command prompt window in this folder ( Shift+ right click – Open command window here).
  • Run command “aapt list -a <path_to_apk_we_need_to_test> >manifest.txt” ( this command will write the app manifest in manifest.txt file inside the same folder).
  • Open the manifest.txt txt file.
  • At the beginning of the file there should be details about the package including name ( example: com.example.android.contactmanager).
  • At the end of the file there should be details about activity including name ( example: ContactManager).
  • ?

    HOW TO RUN APPIUM SERVER

  • Go to the Appium folder you downloaded earlier and run Appium.exe.
  • Click on General Settings button (second button) and verify URL you defined in Eclipse matches the server address and port from the Appium app.?
  • Click on Launch Appium Node Server.
  • HOW TO FIND ELEMENTS IN A NATIVE APP

  • Go to SDK folder and open the tools folder.
  • Open uiautomatorviewer.?
  • On the actual device, open the app to the page you want to automate.
  • In UI Automator Viewer, click on Device screenshot (second button).
  • Click any element on the page and look in the Node detail window (there you will find details about the selected element: id, class, name, etc.)
  • Use the info found (id, class) in Eclipse to click buttons, fill input fields.
  • SELENIUM CODE

    Since Appium server is running and all the settings for testing on the actual phone are set we are ready to write test methods:

    @Test
    public void addContact() throws exception{
    // locate Add Contact button and click it
    WebElement addContactButton = driver.findElement(By.name(“Add Contact”));
    addContactButton.click();
    //locate input fields and type name and email for a new contact and save it
    List<WebElement> textFieldsList = driver.findElementsByClassName(“android.widget.EditText”);
    textFieldsList.get(0).sendKeys(“Some Name”);
    textFieldsList.get(2).sendKeys(“Some@example.com”);
    driver.findElementByName(“Save”).click();
    //insert assertions here
    }

    Since this is the first basic test to see how and if the automation is working there are no assertions in the code. You can modify the code and add assertions to see if contact was added successfully.?Learn more about assertions in this uTest University course.?

    The entire code:

    package tests;

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

    import org.openqa.selenium.By;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.remote.CapabilityType;
    import org.openqa.selenium.remote.DesiredCapabilities;
    import org.junit.*;

    import io.appium.java_client.AppiumDriver;
    import io.appium.java_client.android.AndroidDriver;
    public class TestOne {

    private AndroidDriver driver;

    @Before
    public void setUp() throws MalformedURLException{

    File classpathRoot = new File(System.getProperty(“user.dir”));
    File appDir = new File(classpathRoot, “/ContactManager”);
    File app = new File(appDir, “ContactManager.apk”);

    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(CapabilityType.BROWSER_NAME, “”); //Name of mobile web browser to automate. Should be an empty string if automating an app instead.
    capabilities.setCapability(“platformName”, “Android”);
    capabilities.setCapability(CapabilityType.VERSION, “4.4”);
    capabilities.setCapability(“deviceName”, “111bd508″);
    capabilities.setCapability(“app”, app.getAbsolutePath());
    capabilities.setCapability(“appPackage”, “com.example.android.contactmanager”);
    capabilities.setCapability(“appActivity”, “.ContactManager”);
    driver = new AndroidDriver(new URL(“http://127.0.0.1:4723/wd/hub”), capabilities);
    }
    @Test
    public void addContact() throws Exception {
    WebElement addContactButton = driver.findElement(By.name(“Add Contact”));
    addContactButton.click();
    List<WebElement> textFieldsList = driver.findElementsByClassName(“android.widget.EditText”);
    textFieldsList.get(0).sendKeys(“Some Name”);
    textFieldsList.get(2).sendKeys(“Some@example.com”);
    driver.findElementByName(“Save”).click();
    //insert assertions here
    }

    轉(zhuǎn)載于:https://www.cnblogs.com/melody-emma/p/4682628.html

    總結(jié)

    以上是生活随笔為你收集整理的appium第一个安卓自动化工程的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。

    主站蜘蛛池模板: 欧美成人做爰猛烈床戏 | 91精品国产一区二区三区 | 久草综合视频 | 一级黄色大片免费观看 | 国产网站在线 | h在线免费观看 | www.桃色av嫩草.com | 国产午夜精品一区二区三区视频 | 精品午夜久久久 | 91视频地址 | 日本人妻熟妇久久久久久 | 成全世界免费高清观看 | av片免费在线播放 | 麻豆剧场 | 欧美性极品少妇xxxx | 国产精品自拍网站 | 福利视频导航网 | 青青青免费在线 | 邻家有女4完整版电影观看 欧美偷拍另类 | 欧美性色黄大片手机版 | 黑巨茎大战欧美白妞 | 国产精品亚洲五月天丁香 | 牛牛视频在线观看 | 黑人玩弄人妻一区二区三区 | 玖玖在线免费视频 | 精品一区二区三区蜜桃 | 国产黄色一级网站 | 伊人免费在线观看高清版 | 自拍av在线 | 精品一区二区三区视频日产 | 中文字幕av一区二区三区人妻少妇 | av基地 | 午夜999| 亚洲视频一区二区三区在线观看 | 久久精品aaaaaa毛片 | 91精品免费观看 | 欧美黑人又粗又大的性格特点 | 在线看片中文字幕 | 亚洲精品aaaaa | 久久亚洲精品视频 | 色香蕉网 | 日本福利视频一区 | 欧美日韩一区二区三区国产精品成人 | 深夜激情网 | 亚洲天堂影院 | 巨物撞击尤物少妇呻吟 | 91破处视频 | 日韩视频一区二区三区 | 白浆一区 | 中文字幕第十二页 | 欧美日韩视频免费 | 国产黄a三级三级看三级 | 中文写幕一区二区三区免费观成熟 | 久久99久久98精品免观看软件 | 国产精品19乱码一区二区三区 | 成年在线观看 | 男人视频网站 | 久久精品123 | 亚洲国产精品成人综合久久久 | 亚洲精品美女视频 | 亚洲91色| 国产福利在线播放 | 亚洲国产综合一区 | 欧美国产日韩视频 | 欧美另类亚洲 | 免费在线观看毛片 | 欧美成人综合视频 | 女儿的朋友5中汉字晋通话 欧美成人免费高清视频 | 精品日本一区二区三区在线观看 | 伊人国产在线视频 | 中国大陆一级片 | 亚洲国产一级 | 日本少妇激三级做爰在线 | 蜜桃av中文字幕 | 黄色污污视频软件 | 国产噜噜噜噜久久久久久久久 | 日本少妇做爰全过程毛片 | 涩漫天堂 | 少妇闺蜜换浪荡h肉辣文 | 欧美国产大片 | 欧美一区在线看 | 男女免费视频 | 国产午夜在线视频 | 国产精品一区二区不卡 | 欧美日韩激情一区二区 | 国产精品久久国产精品 | 成人免费视频一区 | 中文字幕网站在线观看 | 蜜桃精品视频在线 | 国产一区二区视频在线 | 欧美第二页 | 国产免费自拍视频 | 国产毛片网 | 欣赏asian国模裸体pics | 欧美日韩 一区二区三区 | 亚洲欧美日韩免费 | 亚洲看看 | 国产一级视频在线播放 | 四虎色播 |