1

移动设备 chrome 浏览器正在启动和关闭,浏览器中未获取 url。Eclipse:氧气 1.0 三星 S5 Appium 版本:1.4.16 浏览器:Chrome。

我正在尝试在移动浏览器中点击网址“us.justdial.com”。设备浏览器连续 4 次启动和关闭,然后脚本失败。

以下是错误报告:

[RemoteTestNG] detected TestNG version 6.13.1
FAILED: Appium_device1
org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: A new session could not be created. (Original error: session not created exception
from unknown error: Runtime.executionContextCreated has invalid 'context': {"auxData":{"frameId":"15216.1","isDefault":true},"id":1,"name":"","origin":"://"}
  (Session info: chrome=55.0.2883.91)
  (Driver info: chromedriver=2.18.343845 (73dd713ba7fbfb73cbb514e62641d8c96a94682a),platform=Windows NT 6.1 SP1 x86))) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 30.09 seconds
Build info: version: '3.7.1', revision: '8a0099a', time: '2017-11-06T21:07:36.161Z'
System info: host: 'MUM-SOFT-VAIBHA', ip: '172.29.5.188', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_144'
Driver info: driver.version: AndroidDriver
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
    at org.openqa.selenium.remote.JsonWireProtocolResponse.lambda$new$0(JsonWireProtocolResponse.java:53)
    at org.openqa.selenium.remote.JsonWireProtocolResponse.lambda$getResponseFunction$2(JsonWireProtocolResponse.java:91)
    at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:123)
    at java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)
    at java.util.Spliterators$ArraySpliterator.tryAdvance(Unknown Source)
    at java.util.stream.ReferencePipeline.forEachWithCancel(Unknown Source)
    at java.util.stream.AbstractPipeline.copyIntoWithCancel(Unknown Source)
    at java.util.stream.AbstractPipeline.copyInto(Unknown Source)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
    at java.util.stream.FindOps$FindOp.evaluateSequential(Unknown Source)
    at java.util.stream.AbstractPipeline.evaluate(Unknown Source)
    at java.util.stream.ReferencePipeline.findFirst(Unknown Source)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:126)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:73)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:142)
    at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:89)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:600)
    at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)
    at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
    at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:219)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:142)
    at io.appium.java_client.DefaultGenericMobileDriver.<init>(DefaultGenericMobileDriver.java:38)
    at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:83)
    at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:93)
    at io.appium.java_client.android.AndroidDriver.<init>(AndroidDriver.java:72)
    at Appium_device.Appium_device1(Appium_device.java:57)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:571)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:707)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:979)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
    at org.testng.TestRunner.privateRun(TestRunner.java:648)
    at org.testng.TestRunner.run(TestRunner.java:505)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
    at org.testng.SuiteRunner.run(SuiteRunner.java:364)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1187)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1116)
    at org.testng.TestNG.runSuites(TestNG.java:1028)
    at org.testng.TestNG.run(TestNG.java:996)
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)


===============================================
    Default test
    Tests run: 1, Failures: 1, Skips: 0
===============================================


===============================================
Default suite
Total tests run: 1, Failures: 1, Skips: 0

测试脚本如下:

import java.net.MalformedURLException;
import java.net.URL;
//import java.util.concurrent.TimeUnit;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
//import org.openqa.selenium.remote.RemoteWebDriver;
//import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

import io.appium.java_client.android.AndroidDriver;

public class Appium_device {
    @Test
    public void Appium_device1() throws MalformedURLException, InterruptedException {
    //APPLICATION_LOG.info("Initializing project properties");
    DesiredCapabilities capabilities = new DesiredCapabilities();

      // Set android deviceName desired capability. Set your device name.
    //  capabilities.setCapability("deviceName", "5203a1bbea4a8385");
    //  capabilities.setCapability("deviceName", "4100df0accbd9f00");
    //   capabilities.setCapability("deviceName", "0123456789ABCDEF");
      capabilities.setCapability("deviceName", "4d007af54ac04177");

      // Set BROWSER_NAME desired capability. It's Android in our case here.
      capabilities.setCapability(CapabilityType.BROWSER_NAME, "Chrome");
    // capabilities.setCapability("browsername", "chrome");

      // Set android VERSION desired capability. Set your mobile device's OS version.
    //  capabilities.setCapability(CapabilityType.VERSION, "4.2.2");
    // capabilities.setCapability(CapabilityType.VERSION, "6.0.1");
    capabilities.setCapability(CapabilityType.VERSION, "6.0.1");

      // Set android platformName desired capability. It's Android in our case here.
      capabilities.setCapability("platformName", "Android");

      // Set android appPackage desired capability. It is
      // com.android.calculator2 for calculator application.
      // Set your application's appPackage if you are using any other app.
    // capabilities.setCapability("appPackage", "org.mozilla.firefox");
      capabilities.setCapability("appPackage", "com.android.chrome");


      // Set android appActivity desired capability. It is
      // com.android.calculator2.Calculator for calculator application.
      // Set your application's appPackage if you are using any other app.
      capabilities.setCapability("appActivity", "com.google.android.apps.chrome.Main");

      // Created object of RemoteWebDriver will all set capabilities.
      // Set appium server address and port number in URL string.
      // It will launch calculator app in android device.
    //   webdriver.Chrome(executable_path='C:\Users\Ganeshkumarg\Downloads\chromedriver_win32\chromedriver.exe');
     URL url = new URL("http://127.0.0.1:4723/wd/hub");
     // webDriver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);

      WebDriver driver = new AndroidDriver (url, capabilities);
      Thread.sleep(10000);
      driver.get("us.justdial.com");
        Thread.sleep(5000);
        System.out.println("Site hit");
        //exclewrtdt.writeData("Launched justdial website", "true");
        Thread.sleep(3000);
    }
}

请参阅 Appium 日志的屏幕截图。

请您调查一下。在此处输入图像描述

4

4 回答 4

2

您需要修复的几件事:

  1. 将 appium 服务器更新到1.7.x,1.4.16 太旧了,可能无法在 Android 6+ 的设备上正常工作:npm -g update appium
  2. 使用正确的能力:

    { "platformName": "Android", "deviceName": "device", "browserName": "Chrome" }

  3. 正确初始化驱动程序:

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

于 2017-12-28T08:34:28.827 回答
1

非常感谢所有的建议和答案,最后,我更新了我的 appium 并使用了@dmle 方法

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

同样有效。

谢谢

于 2017-12-29T10:39:14.940 回答
0

你在哪里使用“AppiumDriver”?使用如下

 AppiumDriver driver = new AndroidDriver(new URL(appiumHost + ":" + appiumPort + "/wd/hub"), capabilities);
于 2017-12-26T12:20:06.327 回答
0

更改这行代码

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

至 :-

  WebDriver driver;
 driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
于 2017-12-26T11:44:53.203 回答