appium-- app自動化

appium 安裝java


1. dmg安裝的appium要診斷node

常見報錯android

Running iOS Checksios

Could not detect Mac OS X Versionmacos

Appium-Doctor detected problems. Please fix and rerun Appium-Doctorbash



解決辦法app

default path: /Applications/Appium.app/Contents/Resources/node_modules/appium/lib/doctor/ios.jsui


IOSChecker.prototype.getMacOSXVersion = function (cb) {this

exec("sw_vers -productVersion", function (err, stdout) {spa

if (err === null) {

if (stdout.match('10.8') !== null) {

this.osVersion = '10.8';

cb(null, "Mac OS X 10.8 is installed.");

} else if (stdout.match('10.9') !== null) {

this.osVersion = '10.9';

cb(null, "Mac OS X 10.9 is installed.");

} else if (stdout.match('10.10') !== null) {

this.osVersion = '10.10';

cb(null, "Mac OS X 10.10 is installed.");

} else {

this.log.fail("Could not detect Mac OS X Version", cb);

}

} else {

this.log.fail("Unknown SW Version Command: " + err, cb);

}

}.bind(this));

};

根據本身系統修改代碼


常見報錯:

Running Android Checks

ANDROID_HOME is not set

Appium-Doctor detected problems. Please fix and rerun Appium-Doctor.




解決辦法


修改配置文件.bash_profile


export ANDROID_HOME=/Applications/Android-sdk-macosx


export APPIUM_HOME=/Applications/Appium.app/Contents/Resources/node_modules/


export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_74.jdk/Contents/Home


export AAPT_HOME=/Applications/android-sdk-macosx/build-tools/


export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools:$APPIUM_HOME/.bin:$AAPT_HOME/23.0.3/


沒有就新建。根據本身的實際安裝路徑修改參數





新建avd

1. 在命令行下輸入android list target

2. android create avd -n <avd文件名> -t <target id > --abi <根據target詳細信息填abi>

3. 經過android list avd 查看建好的虛擬設備

4. emulator @<avd 文件名>

5. 建議用x86abi,可是會報錯

Emulator: ERROR: x86 emulation currently requires hardware acceleration!


Please ensure Intel HAXM is properly installed and usable.


CPU acceleration status: HAX kernel module is not installed!


回到sdk manager裏面,Extras 下面的子項,勾選Intel X86 Emulator Acceleration,安裝。

On Mac, the Android SDK gets installed at: /Users/username/Library/Android/sdk/, therefore, you will need to run the script as sudo, as follows:


sudo sh /Users/username/Library/Android/sdk/extras/intel/Hardware_Accelerated_Execution_Manager/silent_install.sh


If all goes well, the script prints the message: "Silent installation Pass!"

再次用emulator @<avd 文件名>啓動x86avd


p.s.

appium取消掉lanch avd, 手動啓動虛擬機運行代碼。



adb查看log

cd /Users/huangxuelian/Downloads/android-sdk-macosx/tools && adb logcat *:E | grep AndroidRuntime >  /Users/huangxuelian/Documents/1.txt

 

示例代碼:

import java.util.regex.Pattern;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.Select;

import io.appium.java_client.android.AndroidDriver;

import io.appium.java_client.android.AndroidElement;

  public void testUntitled() throws Exception {

  DesiredCapabilities capabilities = new DesiredCapabilities();
      capabilities.setCapability("deviceName", "Android Device");
      capabilities.setCapability("platformName", "Android");
      capabilities.setCapability("platformVersion", "4.3");
      capabilities.setCapability("app","/Users/huangxuelian/Downloads/ContactManager-selendroid.apk");
      AndroidDriver driver = new AndroidDriver<>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
      Thread.sleep(5000);
      
      driver.findElementByClassName("android.widget.CheckBox").click();
      driver.findElementById("addContactButton").click();
      //check the alert of contact  home type
      driver.findElementById("contactPhoneTypeSpinner").click();
      Assert.assertEquals("Select label", driver.findElementById("alertTitle").getText());
      Assert.assertEquals(4, driver.findElementsById("text1").size());
      Assert.assertEquals("Home", driver.findElementByName("Home").getText());
      Assert.assertEquals("Work", driver.findElementByName("Work").getText());
      Assert.assertEquals("Mobile", driver.findElementByName("Mobile").getText());
      Assert.assertEquals("Other", driver.findElementByName("Other").getText());
      driver.findElementByName("Home").click();
      //check the alert of contact  email type
      driver.findElementById("contactEmailTypeSpinner").click();
      Assert.assertEquals("Select label", driver.findElementById("alertTitle").getText());
      Assert.assertEquals(4, driver.findElementsById("text1").size());
      Assert.assertEquals("Home", driver.findElementByName("Home").getText());
      Assert.assertEquals("Work", driver.findElementByName("Work").getText());
      Assert.assertEquals("Mobile", driver.findElementByName("Mobile").getText());
      Assert.assertEquals("Other", driver.findElementByName("Other").getText());
      driver.findElementByName("Work").click();
      
      // enter info
      driver.findElementById("contactNameEditText").sendKeys("test");
      driver.findElementById("contactPhoneEditText").sendKeys("111111");
      driver.findElementById("contactEmailEditText").sendKeys("judytest@163.com");
      //if crash get log
      driver.findElementByClassName("android.widget.Button").click();
      String strCrashAlert="Unfortunately, Contact Manager has stopped.";
      
      if (driver.findElementById("message").isDisplayed()){
      Assert.assertEquals(strCrashAlert,driver.findElementByClassName("android.widget.TextView").getText());
      
      // store crash log
      SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmm");//設置日期格
      String time = df.format(new Date());
      String cmd= "cd /Users/huangxuelian/Downloads/android-sdk-macosx/tools && adb logcat *:E | grep AndroidRuntime >/Users/huangxuelian/Documents/"+time+".txt";
      Runtime.getRuntime().exec(new String[] {"sh", "-c",cmd});
      }

      driver.quit();

}

相關文章
相關標籤/搜索