手機自動化測試技術 Q&A

手機自動化測試技術 Q&A

如何取得特定 APK Package Name & Activity Name?

1. adb shell pm list packages -f
2. adb pull <Name of the APK> // you will get the APK file
3. 7Zip the APK and check manifest.xml

如何安裝 APK?

adb install <*.apk>

如何 Zoom In?

// how to Pinch and Zoom

@Test
public void testExample(){
      int scrHeight = driver.manage().window().getSize().getHeight(); //To get the mobile screen height
      int scrWidth = driver.manage().window().getSize().getWidth();//To get the mobile screen width MultiTouchAction multiTouch = new
		MultiTouchAction(driver);
		TouchAction tAction0 = new TouchAction(driver);
		TouchAction tAction1 = new TouchAction(driver);
		tAction0.press(scrWidth/2,scrHeight/2).wait
		Action(1000).moveTo(0,60).release();//press finger center of the screen and then move y axis
		tAction1.press(scrWidth/2,scrHeight/2+40).wait
		Action(1000).moveTo(0,80).release();// press thumb slightly down on the center of the screen and then move y axis
		multiTouch.add(tAction0).add(tAction1);
		multiTouch.perform();// now perform both the actions simultaneously (tAction0 and tAction1)
}

 

如何 Drag And Drop?

// How to Drag and Drop
@Test
public void testExample(){
	MobileElement appsIcon=(MobileElement)driver.find
	ElementByAccessibilityId("Apps");
	appsIcon.click();
	MobileElement calculator=(MobileElement)driver.findElementByName("Calculator");
	TouchAction act=new TouchAction(driver);
	act.press(calculator).perform();//we are not releasing calculator icon 
	act.moveTo(driver.findElement(By.name("Appinfo"))).release().perform();// then move the icon into App Info and now released the icon
}

 

如何 Scroll and swipe?

@Test
public void testExample(){
         TouchAction tAction=new TouchAction(driver);
       tAction.press(300,500).moveTo(600,500).release().perform(); //First tap on the screen and swipe it right using moveTo function
}

 

iOS 環境安裝

  • iOS requirements
  • Mac OS X 10.7 or later
  • Xcode (4.6.3+; 5.1 is recommended)
  • Java version 7 or later
  • Homebrew
  • Node and npm

Mac 環境變數設定

open ~/.bash_profile
export JAVA_HOME=path/to/the/java/home
export ANDROID_HOME=path/to/the/android/sdk
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools

Appium for iOS

  • Xcode https://itunes.apple.com/us/app/xcode/id497799835
  • Homebrew ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”.
  • brew doctor
  • Node and npm
  • brew install node

安裝 Appium

npm install –g appium

安裝 Jar 檔

  • Selenium Server and WebDriver Java client ( https://selenium-release.storage.googleapis.com/index.html )
  • Appium Java client ( http://search.maven.org/#search|ga|1|appium%20java%20client
  • Gson ( http://mvnrepository.com/artifact/com.google.code.gson)
  • sudo authorize_ios

iOS Physical

  • Provisional profile: Xcode > Windows > Devices > Show Provisioning Profile
  • SafariLauncher is to launch the Safari browser
  • https://github.com/snevesbarros/SafariLauncher/archive/master.zip
  • replace the SafariLauncher app with your app

WebView Access
brew install ios-webkit-debug-proxy

 

 

Android vs iOS 的環境準備

 

Android iOS
Java (version 7 or later)
The Android SDK API (version 17 or later)
An emulator
Eclipse
TestNG
The Appium server
The Appium client library (Java)
The Selenium Server and WebDriver Java library
The APK Info app
Mac OS 10.7 or later
Xcode (version 4.6.3 or later; 5.1 is recommended)
Simulator
Safari on simulator
Java Version 7
Eclipse
TestNG
The Appium Server
The Appium client library (Java)
The Selenium Server and WebDriver Java library
Appium 設定 (native/hybrid apps)

  • Select App Path and provide the path of the application.
  • Select Force Device and choose a simulator from the list.
  • Select Platform Version from the dropdown or you can also
  • Type in a version (for example, 8.1)

 

 

Appium 設定 (Web Apps)

  • Use Mobile Safari.
  • Force Device and choose a simulator from the list.
  • Platform Version

 

 

Leave a Reply

Your email address will not be published.