Appium-ADT-Eclipse realizes automated testing of Android machines

 

The first step is to install the JDK;

The second step is to install Eclipse;

The third step, download and install AndroidSDK;

The fourth step, install the ADT plug-in for Eclipse

 The details are described below.

The first step is to install the JDK

Android automated development and testing must install JDK (Java Development Kit), not just JRE (Java Runtime Edition), you need to install JavaJDK before installing Android development tools. Especially the Eclipse development process must be supported by JDK or JRE, otherwise an error will be reported when starting Eclipse:

 

First, go to the JAVA official website (http://www.oracle.com/technetwork/java/javase/downloads/index.html) to download the JDK ( note that it is downloading JDK , not JRE ),

 

After clicking the JDK download button, enter the JDK version selection interface, find the JDK version suitable for your computer system, and download it, as shown in the figure below, for win32-bit systems, choose Windows x86, and for 64-bit systems, choose Windows x64 for installation:

 

After downloading, double-click to install:

 

Then choose the path you want to install:

 

When installing JDK, JRE will be automatically installed for you, just choose the path you want to install:

 

Then continue to the next step until the final installation is complete:

 

After installation, environment variables must be configured. (1) Create a new system environment variable, the variable name is JAVA_HOME , and the variable value is the installation path of the JDK, as shown in the following figure:

 

Then in the system variable list, (2) Double-click the Path variable and append: %JAVA_HOME%\bin; %JAVA_HOME%\jre\bin  to the variable value ( note that when adding at the end of the variable, remember to add Semicolon ):

 

Now Oracle JDK has become part of the search path of system executable files, and the address is easy to find. In order to verify whether the installation is successful, open a command line window and execute javac -version at the command prompt. If the installation is successful, you will see the Oracle JDK version number, as shown in the following figure:

 

 

The second step, install Eclipse

 

Go to Eclipse official website (http://www.eclipse.org/downloads/) to download Eclipse, choose EclipseIDE for JAVA EE Developers, choose 32-bit or 64-bit installation package according to your system

 

After Eclipse is downloaded, it is a zip compressed package, directly unzip it to the folder you want to use, no need to install it yourself, the file directory is as follows:

 

After Eclipse is installed, double-click "eclipse.exe" to open it, as shown in the following figure:

 

 

It should be noted that Eclipse is opened at this time. The following errors may be reported:

 

The possible cause of this problem is that the environment variables of the JDK are not configured properly. Please configure them according to the JDK environment variable setting method mentioned in the first step. If it still reports an error, then it may be that the environment variables are still not set. In this case, we only need to restart the computer. If it still doesn't work, you can modify the Eclipse.ini file and add two lines at the beginning:

-vm

D:\android\Java\jdk1.8.0_51\ bin\javaw.exe (Note, you must replace D:\android\Java\jdk1.8.0_51\ with your own jdk installation directory)

After some tossing through the above, now Eclipse can start smoothly!

After starting Eclipse, you will first be asked to choose a workspace, and just specify one yourself (the default is the workspace folder of the C drive):

 

Then enter the Eclipse welcome interface, as shown in the following figure:

 

At this point, the Eclipse installation is complete.

 

The third step, download and install AndroidSDK

In the first two steps, we have configured the JDK variable environment and installed Eclipse. After these two steps, the Java development environment is ready. If we are only developing ordinary JAVA applications, then we are here. But if we want to develop Android applications through Eclipse, then we also need to download the Android SDK (Software Development Kit) and install the ADT plug-in on Eclipse.

First, download the Android SDK Tools. Friends who have crossed the wall can go to the official website of Google Android to download (http://developer.android.com/sdk/index.html). Friends who are not willing to go over the wall can download from my bd network disk (http://pan.baidu.com/s/1nt8BcBB), or download from this website (http://www.androiddevtools.cn/). Let's introduce the situation of downloading on this website. First, open http://www.androiddevtools.cn/ , we can see that there are various tools needed for Android development. First, find SDK Tools:

 

Just choose the latest version. Note that there are exe and zip files for downloading. The exe is an installation program. You need to double-click to install it after downloading. It is recommended to download the zip archive, after downloading, directly unzip it to the path where you want to install Android. The decompressed file directory is as follows:

 

Then double-click "SDK Manager.exe" to start SDK Manager, as shown in the figure:

 

Seeing that there are so many to choose to install, is it a bit dizzy for a while and I don’t know what to do. . . Especially for patients with severe choice phobias like Neo, it really feels like their heads are bursting. . . At this time, we must keep calm.

Here I only talk about a few that must be installed, as shown in the figure above, the Android SDK Tools in the Tools folder (this we have already downloaded in the previous step, generally will not let you install it again, but there are May let you update), then Android SDK Platform-tools and Android SDKBuild-tools. Note that you only need to download the latest version.

Then there is the choice of API. We can see that there are many APIs of many versions from Android 2.2 to Android 5.x, so how to choose? Here I suggest, if you are a novice, just choose the latest version, because Android is backward compatible. You will need to download the others in the future (because the speed of downloading and installing is too slow...). So as shown in the figure above, here I only chose to download the latest Android 5.1.1 (API 22). What needs to be explained here is that if you do not plan to use the simulator for debugging in the future, but always use the real machine to debug, then you do not need to install "system images". However, if you are a novice, I don’t know how to choose. I suggest you just tick them all.

The last thing is in the extras folder, as shown in the figure below,

 

In theory, everything in extras should be downloaded if the internet speed permits and there is plenty of time. It should be a good thing. However, at the beginning of the installation, you can install only the three in the picture above, namely Android Support Repository, Android Support Library and Google USB Driver. Others will be downloaded later if you have time.

Then you can install it. It should be noted that these things are downloaded on Google's server. As we have walls in the sky, we may not be able to connect, as shown in the figure below:

 

At this time, we can download and install through a domestic mirror server with Android SDK. Here are a few recommended:

1. Mirror station address of the Chinese Academy of Sciences Open Source Association:

IPV4/IPV6:  http://mirrors.opencas.ac.cn      Port: 80

2. Mirror server address of Beijing University of Chemical Technology:

IPv4:  http://ubuntu.buct.edu.cn/ Port: 80      

IPv4:  http://ubuntu.buct.cn/ Port: 80  

IPv6:  http://ubuntu.buct6.edu.cn/ Port: 80  

3. Mirror server address of Dalian Neusoft Institute of Information:

http://mirrors.neusoft.edu.cn   Port: 80

 

Choose any one you like. Here I chose the third site, the mirror image of Dalian Neusoft, and the method of use is as follows:

First, click on "Tools" in the menu, and then select "Options..." in the drop-down,

 

Then in the pop-up dialog box, fill in the HTTP Proxy Server as mirrors.neusoft.edu.cn (the address of the mirror server, be careful not to add http before it), and then fill in the HTTP Proxy Port as 80 (port number). Finally, check the " Forcehttps://... sources to be fetched using http://... " checkbox below, as shown in the figure below

 

Then click close, close the dialog box, and restart the SDK Manager.

After a long download and installation process (it is recommended to download at night...), we can see that the status behind the previously selected and installed items has changed from the previous "Not installed" to the current "Installed". This It means that we have successfully installed it! Are you excited? . ps. . Brush your teeth and wash your face quickly. . I'm going to be late. . .

 

Because it is very long to download and install directly using the SDK Manager online, if you don’t want to wait for such a long time, you can go to the domestic website (http://www.androiddevtools.cn/) to download the package that needs to be installed. This way It is much faster, but you have to pay attention to choosing the package you need to download and the corresponding version. I won't go into details here. If you have a choice of phobia, you can leave me a message.

 

Ok, then is the last step, we are familiar with setting environment variables. Here you need to append the " \platform-tools" and "\tools" paths to the system environment variable Path, as follows:

First, create a new system environment variable, the variable name is (3) ANDROID_SDK_HOME , the variable value is your SDK installation path, here my installation path is: D:\android\android-sdk , as shown in the figure:

 

Then after the Path variable of the system, append;   % ANDROID_SDK_HOME%\platform-tools;% ANDROID_SDK_HOME%\tools , as shown in the figure:

 

Then we can check whether the Android SDK is installed successfully: enter " adb version " in the command line window, and the following display appears, the installation is successful:

 

 The fourth step, install the ADT plug-in for Eclipse

Thanks for the great picker Bryant! Finally came to the last step! In order to be able to develop Android on Eclipse, we must install an ADT (Android Development Tools) plug-in for him.

First open the Eclipse software. Enter the welcome interface. Click "Help" in the menu and select "Install New Software...", as shown in the figure below:

 

After clicking "Install New Software...", the "Install" window pops up, and then click the "Add" button,

 

Then the "Add Repository" window will pop up, enter the information as follows: Name (ADT), Location (http://dl-ssl.google.com/android/eclipse/), as shown in the figure below, and then click the "OK" button :

 

In the pop-up dialog box, select the tool to be installed, and then the next step is fine:

 

However, if we did not modify the hosts or use a proxy to circumvent the wall, because ( http://dl-ssl.google.com/android/eclipse/ ) this website will not go up in the sky, the following error will be reported:

 

In this case, we either choose to continue the online installation by modifying the hosts or using a proxy to circumvent the wall, or we can use the offline installation method (recommended). For details, see my other blog (http://blog. csdn.net/dr_neo/article/details/46941859)

After everything is installed, restart Eclipse, and then Eclipse will intelligently associate it with the Android SDK in the same directory according to the location of the directory. You can view it by selecting the menu item "Window" and then clicking Preference, as shown in the figure:

 

Select "Android" in the sidebar, and then if you can see the installed SDK platform, it has been automatically associated, as shown in the figure below; if you find that it is not automatically associated, you need to add it yourself, and click "Browse..." Button, select your SDK installation path, just add it~

 

At this point, our entire Android development environment construction on windows is completed. At this time, in Eclipse, select the menu item File—>New—>Project to create a new project, and we can see the establishment of the Android project Options:

 

 

Install NodeJs

 

1. Download Node.js

https://nodejs.org/en/ , the left is the stable version, and the right is the latest version. The stable version is recommended.

 

2. Install Node.js

The next step along the way, remember the installation path (installed here under D:\Program Files\nodejs).

After the installation is complete (need to configure the environment variable: create a new NODE_PATH, the value is the installation path of node, such as: E:\Program Files\nodejs\node_modules) run cmd, execute node -v and npm -v commands to view the installation. If the execution result is as shown in the figure below, the installation is successful.

(After executing this command, the node_global folder will be automatically generated in the nodejs installation directory, if it is not generated, create it manually)

 

****************************************************************************************************************

 

Writing automation scripts

The code (full) is as follows:

package com.tinglv.imguider;

import java.net.MalformedURLException;

import java.net.URL;

import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;

import io.appium.java_client.android.AndroidDriver;

public class AppiumTest {

	public static void main(String[] args) throws MalformedURLException, InterruptedException {

        DesiredCapabilities capabilities = new DesiredCapabilities();
        //手机类型或模拟器类型
        capabilities.setCapability("deviceName", "oppo-oppo_r9sk-2c9c6a56");
        //自动化测试引擎
        capabilities.setCapability("automationName", "Appium");
        //手机操作系统iOS, Android, or FirefoxOS
        capabilities.setCapability("platformName", "Android");
        //手机操作系统版本号
        capabilities.setCapability("platformVersion", "Android 6.0.1");
        //app包名
        capabilities.setCapability("appPackage", "com.android.calculator2");
        //app中启动的 Activity名称
        capabilities.setCapability("appActivity", ".Calculator");

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

        driver.findElement(By.name("6")).click();    //通过By.name 方式获取 计算器数字 6,并且点击
        driver.findElement(By.name("6")).click();
        driver.findElement(By.name("6")).click();
        driver.findElement(By.name("delete")).click();
        driver.findElement(By.name("*")).click();
        driver.findElement(By.name("1")).click();
        driver.findElement(By.name("1")).click();
        driver.findElement(By.name("=")).click();
        Thread.sleep(1000);

        String result = driver.findElement(By.id("com.android.calculator2:id/formula")).getText();
        System.out.println(result);

        driver.quit();
    }
}

//通过By.name 方式获取 计算器数字 6,并且点击
        driver.findElement(By.name("6")).click();
        driver.findElement(By.name("6")).click();
        driver.findElement(By.name("delete")).click();
        driver.findElement(By.name("*")).click();
        driver.findElement(By.name("1")).click();
        driver.findElement(By.name("1")).click();
        driver.findElement(By.name("=")).click();
        Thread.sleep(1000);

        String result = driver.findElement(By.id("com.android.calculator2:id/formula")).getText();
        System.out.println(result);

        driver.quit();
    }
}

 

 

 

  • For the capabilities parameter in the code, please refer to
http://appium.io/slate/en/master/?ruby#appium-server-capabilities
  • Perform automated testing

1. Start Android virtual devices

Write picture description here

  •  
  • Remember to keep the Android Emulator open

 

2. Start appium

  • Remember: Click the start button in the upper right corner

3. Execute the script in Eclipse 
Write picture description here

At this point, you can see that the Android Emulator is automatically executed step by step according to the script

Finally, test developers are welcome to add QQ friends to communicate with each other or have the opportunity to cooperate to establish a group     QQ: 1284817639

WeChat contact information

 

Guess you like

Origin blog.csdn.net/yang520java/article/details/80168203