앱피움은 모바일 앱의 테스트 자동화를 가능하게 해주는 오픈소스 라이브러리다. 네이티브(Native), 하이브리드(Hybrid), 모바일 웹(Mobile web) 등 다양한 타입의 앱에 대한 테스트를 자동화하는 것이 앱피움의 특징이다. 앱피움을 통해 자동화된 테스트는 실제 기기나 에뮬레이터 혹은 시뮬레이터에서 실행된다.
앱피움은 플랫폼 벤더가 제공한 테스트 프레임워크에 Selenium WebDriver API로 랩핑한 클라이언트 라이브러리(Client library)들을 다양한 개발 언어로 제공한다.
Appium architecture 1. 스크립트의 API들은 WebDriver JSON Wire Protocol을 사용해 앱피움 서버와 통신한다. 2. 앱피움 서버는 스크립트가 제공하는 안드로이드 SDK 버전에 맞춰 테스트 프레임워크(UIAutomator 혹은 Selendroid)를 처리할 수 있는 모듈과 TCP 서버를 가지는 bootstrap.jar을 디바이스/에뮬레이터에 설치한다. 3. 앱피움 서버는 스크립트상에 command를 디바이스의 TCP 서버로 전달한다. 4. 기기 상의 UIAutomator 서버는 전달받은 명령어를 안드로이드 버전에 맞는 UIAutomator 혹은 Selendroid 명령어로 바꿔 실행하고, 실행 결과를 앱피움 서버로 보낸다. 5. 앱피움 서버는 콘솔에 처리 결과를 표시한다.
앱피움 실행 환경 구성하기
먼저 Node.js, NPM( nodejs.org/download) 구성이다. 홈브루(homebrew)를 사용하거나 소스를 받아 Node.js를 설치한다. Node.js를 설치하면 NPM이 함께 설치된다.
다음은 앱피움( appium.io) 설치다. NPM을 사용하거나 설치 파일을 다운로드해 앱피움과 앱피움에 종속(dependency)이 있는 모듈들을 한번에 설치하자. 앱피움 설치가 완료되면 앱피움을 실행할 수 있는지 종속성(dependency)을 체크한다.
안드로이드 애플리케이션 자동화 테스트 개발 환경 구성하기
우선 자바 JDK 환경을 구성하자. 오라클 자바 공식 사이트( www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html)에서 JDK를 다운로드해 설치한다.
환경 설정 파일에 JAVA_HOME 환경변수를 만들고 JDK 패스를 설정한다. 설정된 값이 적용될 수 있도록 source 명령어를 실행한다. 환경변수 값이 제대로 설정됐는지 확인한다.
자바 IDE(통합개발환경)로 사용할 이클립스(Eclipse)를 설치하자. 이클립스 사이트( eclipse.org/downloads/)에서 소스를 다운로드해 압축을 풀면 eclipse 디렉토리가 보인다. 디렉토리 아래 eclipse App 파일을 더블클릭해 실행한다.
이제 메이븐(Maven)을 구성해 보자. 메이븐 빌드 도구를 아파치 메이븐 프로젝트 공식 사이트( maven.apache.org/source-repository.html)에서 다운로드해 설치한다. 홈브류를 사용하거나 소스를 다운로드해 메이븐을 설치하고 환경 변수를 설정한다. 설정된 값이 적용될 수 있도록 source 명령어를 실행하고 환경변수 값이 제대로 설정됐는지 확인한다.
다음으로 이클립스를 위한 메이븐 플러그인(Maven Plug in) ‘Maven Plugin for Eclipse( download.eclipse.org/technology/m2e/releases)’를 설치한다. 이클립스에서 Eclipse Help → Install New Software… 메뉴를 통해 설치하면 된다.
안드로이드 에뮬레이터 ‘지니모션(Genymotion)’을 설치해 보자. 우선 지니모션 사이트의 다운로드 페이지( www.genymotion.com/#!/download)에 진입하자. 계정을 생성한 후 에뮬레이터(Emulator) 설치 파일을 다운로드하고 지니모션 설치 파일을 더블클릭한다. 지니모션과 지니모션 셀(Shell)을 애플리케이션으로 드러그 엔 드롭해 설치하면 된다.
이제 이클립스를 위한 지니모션 플러그인(Genymotion Plug in)을 설치할 차례다. ‘Genymotion Plugin for Eclipse’는 지니모션 플러그인 페이지( plugins.genymotion.com/eclipse)에서 다운로드할 수 있다. 이클립스에서 Eclipse Help → Install New Software… 서브 메뉴를 통해 설치하면 된다.
설치가 완료되면 가상 디바이스 매니저를 클릭한다. 처음엔 디바이스가 하나도 없을 것이다. New를 클릭해 디바이스를 생성 창을 띄운다. 여기서 Add를 클릭해 디바이스를 추가한다.
The way your web content behaves on mobile can be dramatically different from the desktop experience. Remote debugging with Chrome DevTools lets you debug live content on your Android device from your development machine.
Note: Remote debugging requires your version of desktop Chrome to be newer than the version of Chrome for Android on your device. For best results, useChrome Canary(Mac/Windows) or the ChromeDev channelrelease (Linux) on desktop.
If at any time you encounter problems with remote debugging, refer to theTroubleshootingsection.
Setting up your Android device
Follow these instructions to set up your Android device for remote debugging.
1. Enable USB debugging
On your Android device, selectSettings > Developer options.
Note: OnAndroid 4.2and later, the developer options are hidden by default. To enable the developer options, selectSettings > About phoneand tapBuild numberseven times.
An alert prompts you to allow USB debugging. TapOK.
2. Connect your device
Connect the Android device to your development machine using a USB cable.
Note: If you are developing onWindows, install the appropriate USB driver for your device. SeeOEM USB Driverson the Android Developers' site.
Discovering devices in Chrome
After setting up remote debugging on Android, discover your device in Chrome.
On your desktop Chrome browser, navigate tochrome://inspect. Confirm thatDiscover USB devicesis checked:
On your device, an alert prompts you to allow USB debugging from your computer. TapOK.
The messageUSB debugging connecteddisplays in the device's notification drawer.
Note: During remote debugging, Chrome prevents your device’s screen from going to sleep. This feature is useful for debugging, but is also less secure. So be sure to keep an eye on your device!
On your computer, thechrome://inspectpage displays every connected device, along with its open tabs and debug-enabled WebViews.
If you have problems finding your device on thechrome://inspect page, see theTroubleshootingsection.
Debugging remote browser tabs
From thechrome://inspect page, you can launch DevTools and debug your remote browser tabs.
To start debugging, clickinspectbelow the browser tab you want to debug.
A new instance of Chrome DevTools launches on your computer. From this instance, you can interact with the selected browser tab on your device in real time.
For example, you can use DevTools to inspect web page elements on your device:
When you mouse over an element in theElementspanel, DevTools highlights the element on your device.
You can also click theInspect Elementicon in DevTools and tap your device screen. DevTools highlights the tapped element in theElementspanel.
Note: The version of Chrome on your device determines the version of DevTools used during remote debugging. For this reason, the remote debugging DevTools might differ from the version that you normally use.
Debugging tips
Here are a few tips to help get you started with remote debugging:
UseF5(orCmd+ron Mac) to reload a remote page from the DevTools window.
Keep the device on a cellular network. Use theNetworkpanelto view the network waterfall under actual mobile conditions.
Use theTimelinepanelto analyze rendering and CPU usage. Hardware on mobile devices often runs much slower than on your development machine.
On Android 4.4 (KitKat) or later, you can use DevTools to debug WebView content in native Android applications.
Configure WebViews for debugging
WebView debugging must be enabled from within your application. To enable WebView debugging, call the static methodsetWebContentsDebuggingEnabledon the WebView class.
This setting applies to all of the application's WebViews.
Tip: WebView debugging isnotaffected by the state of thedebuggableflag in the application's manifest. If you want to enable WebView debugging only whendebuggableistrue, test the flag at runtime.
Thechrome://inspectpage displays a list of debug-enabled WebViews on your device.
To start debugging, clickinspectbelow the WebView you want to debug. Use DevTools as you would for aremote browser tab.
The gray graphics listed with the WebView represent its size and position relative to the device's screen. If your WebViews have titles set, the titles are listed as well.
Live screencasting
Shifting your attention between screens isn’t always convenient. Screencast displays your device's screen right alongside DevTools on your development machine. You can interact with the content on your device from the screencast too.
As of KitKat 4.4.3, screencast is available for both browser tabs and Android WebViews.
Start a screencast session
To start screencasting, click theScreencasticon in the upper right corner of your remote debugging DevTools window.
TheScreencastpanel opens on the left and displays a live view of your device's screen.
Screencast only displays page content. Transparent portions of the screencast are covered by the omnibox, device keyboard, and other device interfaces.
Note: Because screencast continuously captures frames, it has some performance overhead. If your tests are sensitive to frame rate, disable screencast.
Interact with your device using the screencast
When you interact with the screencast, clicks are translated into taps, firing proper touch events on the device. Keystrokes from your computer are sent to the device, so you can avoid typing with your thumbs.
Other DevTools work with the screencast too. For example, to inspect an element, click theInspect Elementicon and then click inside the screencast.
Tips: To simulate a pinch gesture, holdShiftwhile dragging. To scroll, use your trackpad or mouse wheel or fling with your pointer.
Port forwarding
Your phone can't always reach the content on your development server. They might be on different networks. Moreover, you might be developing on a restricted corporate network.
Port forwarding on Chrome for Android makes it easy to test your development site on mobile. It works by creating a listening TCP port on your mobile device that maps to a particular TCP port on your development machine. Traffic between these ports travels through USB, so the connection doesn't depend on your network configuration.
To enable port forwarding:
Openchrome://inspecton your development machine.
ClickPort Forwarding. The port forwarding settings display.
In theDevice portfield, enter the port number you want your Android device to listen on. (The default port is 8080.)
In theHostfield, enter the IP address (or hostname) and port number where your web application is running. This address can be any local location accessible from your development machine. Currently, port numbers must be between 1024 and 32767 (inclusive).
CheckEnable port forwarding.
ClickDone.
The port status indicators onchrome://inspectare green when port forwarding is successful.
Now you can open a new Chrome for Android tab and view the content of your local server on your device.
Virtual host mapping
Port forwarding works great when you're developing onlocalhost. But there are cases when you might be using a customized local domain.
For example, suppose you're using a third party JavaScript SDK that only works on whitelisted domains. So you added an entry, such as127.0.0.1 production.com, to yourhosts file. Or maybe you configured a customized domain using virtual hosts on your web server (MAMP).
If you want your phone to reach content on your customized domain, you can use port forwarding in combination with a proxy server. The proxy maps requests from your device to the correct location on the host machine.
Set up port forwarding to a proxy
Virtual host mapping requires you to run a proxy server on the host machine. All requests from your Android device will be forwarded to the proxy.
To set up port forwarding to a proxy:
On the host machine, install proxy software such asCharles Proxy(free trial available) orSquid.
Run the proxy server and note the port that it's using.
Note: The proxy server and your development server must be running on different ports.
In a Chrome browser, navigate tochrome://inspect.
ClickPort forwarding. The port forwarding settings display.
In theDevice portfield, enter the port number that you want your Android device to listen on. Use a port that Android allows, such as9000.
In theHostfield, enterlocalhost:xxxx, wherexxxxis the port your proxy is running on.
CheckEnable port forwarding.
ClickDone.
The proxy on the host machine is set up to make requests on behalf of your Android device.
Configure proxy settings on your device
Your Android device needs to communicate with the proxy on the host machine.
To configure the proxy settings on your device:
SelectSettings > Wi-Fi.
Long-press the network that you are currently connected to.
Note: Proxy settings apply per network.
TapModify network.
SelectAdvanced options. The proxy settings display.
Tap theProxymenu and selectManual.
In theProxy hostnamefield, enterlocalhost.
In theProxy portfield, enter9000.
TapSave.
With these settings, your device forwards all of its requests to the proxy on the host machine. The proxy makes requests on behalf of your device, so requests to your customized local domain are properly resolved.
Now you can load local domains on Chrome for Android just as you would on the host machine.
Tip: To resume normal browsing, remember to revert the proxy settings on your device after you disconnect from the host.
Troubleshooting
I can't see my device on thechrome://inspect page.
If you are developing onWindows, verify that the appropriate USB driver for your device is installed. SeeOEM USB Driverson the Android Developers' site.
Verify that the device is connected directly to your machine, bypassing any hubs.
Verify thatUSB debuggingis enabled on your device. Remember to accept the USB debugging permission alerts on your device.
On your desktop browser, navigate tochrome://inspectand verify thatDiscover USB devicesis checked.
Remote debugging requires your version of desktop Chrome to be newer than the version of Chrome for Android on your device. Try usingChrome Canary(Mac/Windows) or the ChromeDev channelrelease (Linux) on desktop.
If you still can't see your device, unplug it. On your device, selectSettings > Developer options. TapRevoke USB debugging authorizations. Then, retry thedevice setupanddiscovery processes.
I can't see my browser tabs on thechrome://inspectpage.
On your device, open the Chrome browser and navigate to the web page you want to debug. Then, refresh thechrome://inspectpage.
I can't see my WebViews on thechrome://inspect page.
On your device, open the app with the WebView you want to debug. Then, refresh thechrome://inspectpage.
I can't access my web server from my Android device.
If network restrictions prevent your mobile device from accessing your development server, try enablingport forwardingor setting up avirtual host map.
Lastly, if remote debugging still isn't working, you can revert to thelegacy workflowusing theadbbinary from the Android SDK.
Additional information
Remote debugging and ADB
You no longer need to configureADBor the ADB plugin to debug remote browser tabs and WebViews. Remote debugging for Android is now part of the standard Chrome DevTools. It works on all operating systems: Windows, Mac, Linux, and Chrome OS.
If you do encounter problems with remote debugging, you can try thelegacy workflowusing theadbbinary from the Android SDK.
Note: The direct USB connection between Chrome and the device might interrupt youradbconnection. Before establishing youradbconnection, uncheckDiscover USB devicesonchrome://inspect. Then, disconnect and reconnect the device.
Remote debugging for DevTools extension developers
If you need to convert a Java Keystore file to a different format, it usually easier to create a new private key and certificates but it is possible toconvert a Java Keystore to PEM format.