2016-08-17 11 views
0

Selenium webdriverとappiumを使用してAndroidデバイス上のWebアプリケーションを自動化しようとしています。 ChromeのブラウザでAndroid搭載端末でclick()が動作していないようだが、デスクトップのChromeブラウザでも同じように動作しています。AndroidデバイスでChrome用のWebdriver Cickが動作しない

gmail.comとappiumのコンソールログに問題を再現するためのテストコードを添付してください。これがchromeDriverの問題か、他の方法で実装する必要があるかどうかは不明です。 chromedriverExecutable機能の下で:あなたが追加する必要があるかもしれません

コード

import java.net.MalformedURLException; 
import java.net.URL; 
import org.openqa.selenium.By; 
import org.openqa.selenium.remote.DesiredCapabilities; 
import org.openqa.selenium.remote.RemoteWebDriver; 
import org.testng.annotations.BeforeTest; 
import org.testng.annotations.Test; 

public class TestMobileBrowser { 

    public DesiredCapabilities capabilities; 
    public RemoteWebDriver driver; 

@BeforeTest 
public void beforeTest() throws MalformedURLException{ 
    capabilities = new DesiredCapabilities(); 
    capabilities.setCapability("platformName", "Android"); 
    capabilities.setCapability("deviceName", "Android"); 
    capabilities.setCapability("browserName", "chrome"); 
    capabilities.setCapability("newCommandTimeout", 60); 
    driver = new RemoteWebDriver(new URL("http://localhost:4723/wd/hub"), capabilities);  
} 

@Test 
public void test(){ 
    driver.get("http://gmail.com"); 
    driver.findElement(By.id("Email")).sendKeys("test"); 
    driver.findElement(By.id("next")).click(); 
    driver.findElement(By.id("Passwd")).sendKeys("test"); 
    driver.findElement(By.id("signIn")).click();  
} 

} 

Appiumログ

> info: --> POST /wd/hub/session {"desiredCapabilities":{"newCommandTimeout":60,"browserName":"chrome","platformName":"Android","deviceName":"Android"}} 
> info: Client User-Agent string: Apache-HttpClient/4.5.1 (Java/1.8.0_60) 
> info: Set mode: Proxying straight through to Chromedriver 
> info: [debug] Looks like we want chrome on android 
> info: [debug] Creating new appium session b061da72-cfb4-4d06-8595-b9fe52439d37 
> info: [debug] Checking whether adb is present 
> info: [debug] Using adb from D:\eGain\Automation\Android\sdk\platform-tools\adb.exe 
> info: [debug] Using fast reset? true 
> info: [debug] Preparing device for session 
> info: [debug] Not checking whether app is present since we are assuming it's already on the device 
> info: Retrieving device 
> info: [debug] Trying to find a connected android device 
> info: [debug] Getting connected devices... 
> info: [debug] executing cmd: D:\eGain\Automation\Android\sdk\platform-tools\adb.exe devices 
> info: [debug] 1 device(s) connected 
> info: Found device a33124a7 
> info: [debug] Setting device id to a33124a7 
> info: [debug] Waiting for device to be ready and to respond to shell commands (timeout = 5) 
> info: [debug] executing cmd: D:\eGain\Automation\Android\sdk\platform-tools\adb.exe -s a33124a7 wait-for-device 
> info: [debug] executing cmd: D:\eGain\Automation\Android\sdk\platform-tools\adb.exe -s a33124a7 shell "echo 'ready'" 
> info: [debug] Starting logcat capture 
> info: [debug] Pushing unlock helper app to device... 
> info: [debug] executing cmd: D:\eGain\Automation\Android\sdk\platform-tools\adb.exe -s a33124a7 install "C:\Program Files (x86)\Appium\node_modules\appium\build\unlock_apk\unlock_apk-debug.apk" 
> info: [debug] executing cmd: D:\eGain\Automation\Android\sdk\platform-tools\adb.exe -s a33124a7 shell "dumpsys window" 
> info: Unlocking screen 
> info: [debug] Screen is locked, trying to unlock 
> info: [debug] Getting device API level 
> info: [debug] executing cmd: D:\eGain\Automation\Android\sdk\platform-tools\adb.exe -s a33124a7 shell "getprop ro.build.version.sdk" 
> info: [debug] Device is at API Level 23 
> info: [debug] executing cmd: D:\eGain\Automation\Android\sdk\platform-tools\adb.exe -s a33124a7 shell "am start -S -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -f 0x10200000 -n io.appium.unlock/.Unlock" 
> info: [debug] executing cmd: D:\eGain\Automation\Android\sdk\platform-tools\adb.exe -s a33124a7 shell "dumpsys window" 
> info: [debug] Screen is unlocked, continuing 
> info: [debug] Forwarding system:4724 to device:4724 
> info: [debug] executing cmd: D:\eGain\Automation\Android\sdk\platform-tools\adb.exe -s a33124a7 forward tcp:4724 tcp:4724 
> info: [debug] Pushing appium bootstrap to device... 
> info: [debug] executing cmd: D:\eGain\Automation\Android\sdk\platform-tools\adb.exe -s a33124a7 push "C:\\Program Files (x86)\\Appium\\node_modules\\appium\\build\\android_bootstrap\\AppiumBootstrap.jar" /data/local/tmp/ 
> info: Starting App 
> info: [debug] Attempting to kill all 'uiautomator' processes 
> info: [debug] Getting all processes with 'uiautomator' 
> info: [debug] executing cmd: D:\eGain\Automation\Android\sdk\platform-tools\adb.exe -s a33124a7 shell "ps 'uiautomator'" 
> info: [debug] No matching processes found 
> info: [debug] Running bootstrap 
> info: [debug] spawning: D:\eGain\Automation\Android\sdk\platform-tools\adb.exe -s a33124a7 shell uiautomator runtest AppiumBootstrap.jar -c io.appium.android.bootstrap.Bootstrap -e pkg com.android.chrome -e disableAndroidWatchers false 
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: numtests=1 
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream= 
> info: [debug] [UIAUTOMATOR STDOUT] io.appium.android.bootstrap.Bootstrap: 
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner 
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: test=testRunServer 
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: class=io.appium.android.bootstrap.Bootstrap 
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: current=1 
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: 1 
> info: [debug] [BOOTSTRAP] [debug] Socket opened on port 4724 
> info: [debug] [BOOTSTRAP] [debug] Appium Socket Server Ready 
> info: [debug] [BOOTSTRAP] [debug] Loading json... 
> info: [debug] [BOOTSTRAP] [debug] Registered crash watchers. 
> info: [debug] Pushing command to appium work queue: ["getDataDir",{}] 
> info: [debug] [BOOTSTRAP] [debug] Client connected 
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"getDataDir","params":{}} 
> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION 
> info: [debug] [BOOTSTRAP] [debug] Got command action: getDataDir 
> info: [debug] dataDir set to: /data/local/tmp 
> info: Chromedriver: Changed state to 'starting' 
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":0,"value":"\/data\/local\/tmp"} 
> info: Chromedriver: Set chromedriver binary as: C:\Program Files (x86)\Appium\node_modules\appium\node_modules\appium-chromedriver\chromedriver\win\chromedriver.exe 
> info: Chromedriver: Killing any old chromedrivers, running: FOR /F "usebackq tokens=5" %a in (`netstat -nao ^| findstr /R /C:"9515 "`) do (FOR /F "usebackq" %b in (`TASKLIST /FI "PID eq %a" ^| findstr /I chromedriver.exe`) do (IF NOT %b=="" TASKKILL /F /PID %a)) 
> info: Chromedriver: No old chromedrivers seemed to exist 
> info: Chromedriver: Spawning chromedriver with: C:\Program Files (x86)\Appium\node_modules\appium\node_modules\appium-chromedriver\chromedriver\win\chromedriver.exe --url-base=wd/hub --port=9515 
> info: Chromedriver: [STDOUT] Starting ChromeDriver 2.23.409699 (49b0fa931cda1caad0ae15b7d1b68004acd05129) on port 9515 
> Only local connections are allowed. 
> info: JSONWP Proxy: Proxying [GET /status] to [GET http://127.0.0.1:9515/wd/hub/status] with no body 
> info: JSONWP Proxy: Got response with status 200: "{\"sessionId\":\"\",\"status\":0,\"value\":{\"build\":{\"version\":\"alpha\"},\"os\":{\"arch\":\"x86_64\",\"name\":\"Windows NT\",\"version\":\"10.0.10586\"}}}" 
> info: JSONWP Proxy: Proxying [POST /session] to [POST http://127.0.0.1:9515/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.android.chrome","androidDeviceSerial":"a33124a7"}}} 
> info: JSONWP Proxy: Got response with status 200: {"sessionId":"0ebf4514a9760982649f45ce431656e8","status":0,"value":{"acceptSslCerts":true,"applicationCacheEnabled":false,"browserConnectionEnabled":false,"browserName":"chrome","chrome":{"chromedr... 
> info: Chromedriver: Changed state to 'online' 
> info: [debug] Overriding session id with "0ebf4514a9760982649f45ce431656e8" 
> info: [debug] Device launched! Ready for commands 
> info: [debug] Setting command timeout to 60 secs 
> info: [debug] Appium session started with sessionId 0ebf4514a9760982649f45ce431656e8 
> info: <-- POST /wd/hub/session 303 18667.504 ms - 70 
> info: --> GET /wd/hub/session/0ebf4514a9760982649f45ce431656e8 {} 
> info: JSONWP Proxy: Proxying [GET /wd/hub/session/0ebf4514a9760982649f45ce431656e8] to [GET http://127.0.0.1:9515/wd/hub/session/0ebf4514a9760982649f45ce431656e8] with body: {} 
> info: JSONWP Proxy: Got response with status 200: {"sessionId":"0ebf4514a9760982649f45ce431656e8","status":0,"value":{"acceptSslCerts":true,"applicationCacheEnabled":false,"browserConnectionEnabled":false,"browserName":"chrome","chrome":{"chromedr... 
> info: JSONWP Proxy: Replacing sessionId 0ebf4514a9760982649f45ce431656e8 with 0ebf4514a9760982649f45ce431656e8 
> info: <-- GET /wd/hub/session/0ebf4514a9760982649f45ce431656e8 200 11.638 ms - 606 
> info: --> POST /wd/hub/session/0ebf4514a9760982649f45ce431656e8/url {"url":"http://gmail.com"} 
> info: JSONWP Proxy: Proxying [POST /wd/hub/session/0ebf4514a9760982649f45ce431656e8/url] to [POST http://127.0.0.1:9515/wd/hub/session/0ebf4514a9760982649f45ce431656e8/url] with body: {"url":"http://gmail.com"} 
> info: JSONWP Proxy: Got response with status 200: {"sessionId":"0ebf4514a9760982649f45ce431656e8","status":0,"value":null} 
> info: JSONWP Proxy: Replacing sessionId 0ebf4514a9760982649f45ce431656e8 with 0ebf4514a9760982649f45ce431656e8 
> info: <-- POST /wd/hub/session/0ebf4514a9760982649f45ce431656e8/url 200 2374.402 ms - 72 
> info: --> POST /wd/hub/session/0ebf4514a9760982649f45ce431656e8/element {"using":"id","value":"Email"} 
> info: JSONWP Proxy: Proxying [POST /wd/hub/session/0ebf4514a9760982649f45ce431656e8/element] to [POST http://127.0.0.1:9515/wd/hub/session/0ebf4514a9760982649f45ce431656e8/element] with body: {"using":"id","value":"Email"} 
> info: JSONWP Proxy: Got response with status 200: {"sessionId":"0ebf4514a9760982649f45ce431656e8","status":0,"value":{"ELEMENT":"0.46630814854548563-1"}} 
> info: JSONWP Proxy: Replacing sessionId 0ebf4514a9760982649f45ce431656e8 with 0ebf4514a9760982649f45ce431656e8 
> info: <-- POST /wd/hub/session/0ebf4514a9760982649f45ce431656e8/element 200 154.429 ms - 103 
> info: --> POST /wd/hub/session/0ebf4514a9760982649f45ce431656e8/element/0.46630814854548563-1/value {"id":"0.46630814854548563-1","value":["test"]} 
> info: JSONWP Proxy: Proxying [POST /wd/hub/session/0ebf4514a9760982649f45ce431656e8/element/0.46630814854548563-1/value] to [POST http://127.0.0.1:9515/wd/hub/session/0ebf4514a9760982649f45ce431656e8/element/0.46630814854548563-1/value] with body: {"id":"0.46630814854548563-1","value":["test"]} 
> info: JSONWP Proxy: Got response with status 200: {"sessionId":"0ebf4514a9760982649f45ce431656e8","status":0,"value":null} 
> info: JSONWP Proxy: Replacing sessionId 0ebf4514a9760982649f45ce431656e8 with 0ebf4514a9760982649f45ce431656e8 
> info: <-- POST /wd/hub/session/0ebf4514a9760982649f45ce431656e8/element/0.46630814854548563-1/value 200 300.313 ms - 72 
> info: --> POST /wd/hub/session/0ebf4514a9760982649f45ce431656e8/element {"using":"id","value":"next"} 
> info: JSONWP Proxy: Proxying [POST /wd/hub/session/0ebf4514a9760982649f45ce431656e8/element] to [POST http://127.0.0.1:9515/wd/hub/session/0ebf4514a9760982649f45ce431656e8/element] with body: {"using":"id","value":"next"} 
> info: JSONWP Proxy: Got response with status 200: {"sessionId":"0ebf4514a9760982649f45ce431656e8","status":0,"value":{"ELEMENT":"0.46630814854548563-2"}} 
> info: JSONWP Proxy: Replacing sessionId 0ebf4514a9760982649f45ce431656e8 with 0ebf4514a9760982649f45ce431656e8 
> info: <-- POST /wd/hub/session/0ebf4514a9760982649f45ce431656e8/element 200 160.963 ms - 103 
> info: --> POST /wd/hub/session/0ebf4514a9760982649f45ce431656e8/element/0.46630814854548563-2/click {"id":"0.46630814854548563-2"} 
> info: JSONWP Proxy: Proxying [POST /wd/hub/session/0ebf4514a9760982649f45ce431656e8/element/0.46630814854548563-2/click] to [POST http://127.0.0.1:9515/wd/hub/session/0ebf4514a9760982649f45ce431656e8/element/0.46630814854548563-2/click] with body: {"id":"0.46630814854548563-2"} 
> info: JSONWP Proxy: Got response with status 200: {"sessionId":"0ebf4514a9760982649f45ce431656e8","status":0,"value":null} 
> info: JSONWP Proxy: Replacing sessionId 0ebf4514a9760982649f45ce431656e8 with 0ebf4514a9760982649f45ce431656e8 
> info: <-- POST /wd/hub/session/0ebf4514a9760982649f45ce431656e8/element/0.46630814854548563-2/click 200 350.330 ms - 72 
> info: --> POST /wd/hub/session/0ebf4514a9760982649f45ce431656e8/element {"using":"id","value":"Passwd"} 
> info: JSONWP Proxy: Proxying [POST /wd/hub/session/0ebf4514a9760982649f45ce431656e8/element] to [POST http://127.0.0.1:9515/wd/hub/session/0ebf4514a9760982649f45ce431656e8/element] with body: {"using":"id","value":"Passwd"} 
> info: JSONWP Proxy: Got response with status 200: {"sessionId":"0ebf4514a9760982649f45ce431656e8","status":7,"value":{"message":"no such element: Unable to locate element: {\"method\":\"id\",\"selector\":\"Passwd\"}\n (Session info: chrome=52.0.2... 
> info: JSONWP Proxy: Replacing sessionId 0ebf4514a9760982649f45ce431656e8 with 0ebf4514a9760982649f45ce431656e8 
> info: <-- POST /wd/hub/session/0ebf4514a9760982649f45ce431656e8/element 200 227.600 ms - 331 
> info: [debug] Didn't get a new command in 60 secs, shutting down... 
> info: Shutting down appium session 
> info: Chromedriver: Changed state to 'stopping' 
> info: JSONWP Proxy: Proxying [DELETE /] to [DELETE http://127.0.0.1:9515/wd/hub/session/0ebf4514a9760982649f45ce431656e8] with no body 
> info: JSONWP Proxy: Got response with status 200: "{\"sessionId\":\"0ebf4514a9760982649f45ce431656e8\",\"status\":0,\"value\":null}" 
> info: Chromedriver: Changed state to 'stopped' 
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"shutdown"} 
> info: [debug] [BOOTSTRAP] [debug] Got command of type SHUTDOWN 
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":0,"value":"OK, shutting down"} 
> info: [debug] [BOOTSTRAP] [debug] Closed client connection 
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: numtests=1 
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=. 
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner 
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: test=testRunServer 
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: class=io.appium.android.bootstrap.Bootstrap 
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: current=1 
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: 0 
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream= 
> info: [debug] [UIAUTOMATOR STDOUT] Test results for WatcherResultPrinter=. 
> info: [debug] [UIAUTOMATOR STDOUT] Time: 76.13 
> info: [debug] [UIAUTOMATOR STDOUT] OK (1 test) 
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: -1 
> info: [debug] Sent shutdown command, waiting for UiAutomator to stop... 
> info: [debug] UiAutomator shut down normally 
> info: [debug] executing cmd: D:\eGain\Automation\Android\sdk\platform-tools\adb.exe -s a33124a7 shell "am force-stop com.android.chrome" 
> info: [debug] Stopping logcat capture 
> info: [debug] Logcat terminated with code null, signal SIGTERM 
> info: [debug] Cleaning up appium session 
> info: [debug] We shut down because no new commands came in 

答えて

0
capabilities.setCapability("deviceName", "YOUR-DEVICE-NAME"); // such as GalaxyS6 
capabilities.setCapability("browserName", "Chrome"); // its Chrome instead of chrome 

。 Webdriverの実行可能ファイルへの絶対パス(クロム埋め込みプログラムに独自のウェブドライバがある場合は、Appiumにバンドルされているオリジナルのクロムドライバの代わりに使用する必要があります)

パスワードフィールドが見つからない場合は、キーボードを最初に隠す。

driver.hideKeyboard(); 
driver.findElement(By.id("Passwd")).sendKeys("test"); 
+0

がある私はhideKeyboardが利用できないので、あなたがAndroidDriverを使用することを示唆している、RemoteWebDriverなくAndroidDriverを使用していますか?最新のchromeDriverも使用しています(AppiumにバンドルされているchromeDriverに置き換えて)ので、この機能を追加する必要はありません。返信を確認していただきありがとうございます。 – Monty

+0

また、driver.hideKeyboard()を使用して、Appium上で次のような例外を取得し、テストが進行しません - エラー:リモートサーバーにコマンドをプロキシできませんでした。元のエラー:404 - 不明なコマンド:セッション/ 57103790618761d0f1b87cefcb083e41/appium/device/hide_keyboard – Monty

+0

@Vaibhavスクリーンショットを投稿してください。ログインとパスワード画面。 uiautomatorviewer、appium inspector、またはchrome device inspectorを使用していますか? – Suman

1

@Vaibhav IDとパスワードフィールドエントリとappium間の画面遷移がありますので、私はそれのための待機条件を追加するようにお勧めしますので、次の画面が表示される前に、パスワードフィールドを探し始めます。

WebDriverWait wait = new WebDriverWait(driver, 30); 
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//android.widget.EditText[@resource-id='Passwd']"))); 

以下の機能が私のために働いた -

public void setUp() throws Exception { 
DesiredCapabilities capabilities = new DesiredCapabilities(); 
capabilities.setCapability("deviceName", "Galaxy"); 
capabilities.setCapability("platformName", "Android"); 
capabilities.setCapability(CapabilityType.BROWSER_NAME, "Chrome"); 
capabilities.setCapability("platformVersion", "6.0"); 
capabilities.setCapability("appPackage", "com.android.chrome"); 
capabilities.setCapability("appActivity","com.google.android.apps.chrome.ChromeTabbedActivity"); 
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities); 

}

をしかし、あなたはGmailのユーザー名を入力し、次にあなたが使用することができ、あなたの能力を使用して「次へ」ボタンをクリックすることができればあなたの既存の能力。パスワードをクリックする前にwaitステートメントを追加するだけです。

+0

私はwait/sleep/waitで要素が存在することを確認しましたが、動作しません。また、ロケータを使って要素が強調表示され、ロケータがクリックされる前にそのロケータが識別されていることを確認して問題があるかどうかを確認しました。すべては問題ありませんが、クリックしてください:(...... AUTはgmail.comとは異なりますが、AUTは公開されていませんが、コードは同じです(ロケータを除く)。 - のドライバのボタンの。findElement(By.id( "button-1041")) – Monty

+0

あなたはスクリーンショットを共有できますか?条件付き待機を追加する場合は、次のページのチェックを追加しますか? – Suman

1

次のコードは、私

のために働いているここでは、コード

public class TestMobileBrowser { 

public DesiredCapabilities capabilities; 
public AppiumDriver driver; 
@BeforeTest 
public void beforeTest() throws Exception{ 

capabilities = new DesiredCapabilities(); 
capabilities.setCapability("deviceName", "Android"); 
capabilities.setCapability("platformName", "Android"); 
capabilities.setCapability(CapabilityType.BROWSER_NAME, "Chrome"); 
capabilities.setCapability("platformVersion", "5.0.2"); 
capabilities.setCapability("appPackage", "com.android.chrome"); 
capabilities.setCapability("appActivity","com.google.android.apps.chrome.ChromeTabbedActivity"); 
driver= new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities); 
} 

@Test 
public void test(){ 
driver.get("http://gmail.com"); 
driver.findElement(By.id("Email")).sendKeys("test"); 
Thread.sleep(30000); 
driver.findElement(By.id("next")).click(); 
driver.findElement(By.id("Passwd")).sendKeys("test"); 
driver.findElement(By.id("signIn")).click();  
} 

} 
関連する問題