简体   繁体   English

线程“ main”中的异常org.openqa.selenium.WebDriverException

[英]Exception in thread “main” org.openqa.selenium.WebDriverException

I'm trying to test my application in eclipse IDE using java throwing this error. 我正在尝试使用抛出此错误的Java在Eclipse IDE中测试我的应用程序。 I started appium server also. 我也启动了appium服务器。 gave matching port numbers too. 也提供了匹配的端口号。 this is my log trace. 这是我的日志跟踪。 help me out.Thanks in advance 帮帮我。谢谢

This is the code I used for testing my android app using appium: 这是我使用appium测试我的android应用程序的代码:

public class MilonowFirstTest {

        static AppiumDriver<WebElement> driver;

    //  @BeforeClass
        public static void main(String[] args) throws MalformedURLException

        //public void Setup() throws MalformedURLException
        {
            DesiredCapabilities cap = new DesiredCapabilities();
            //cap.setCapability(AndroidMobileCapabilityType.De, value);
            cap.setCapability(MobileCapabilityType.DEVICE_NAME, "Android emulator");
            //cap.setCapability(MobileCapabilityType.APP_PACKAGE, value);
            cap.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, "com.test.myapp");

            //cap.setCapability(MobileCapabilityType.APP, "");
            cap.setCapability("avd", "Honor 7X API 27");
            cap.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
            cap.setCapability(MobileCapabilityType.PLATFORM_VERSION, "23");
            cap.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Appium");

            driver = new AndroidDriver<WebElement>(new URL("http://127.0.0.1:4723/wb/hub"), cap);

            Assert.assertNotNull(driver.getContext());
        }

//      @Test()
//      public void SimpleTest()
//      {
//          Assert.assertNotNull(driver.getContext());
//      }
    }

Error log: 错误日志:

Exception in thread "main" org.openqa.selenium.WebDriverException: It is impossible to create a new session because 'createSession' which takes HttpClient, InputStream and long was not found or it is not accessible
Build info: version: '3.12.0', revision: '7c6e0b3', time: '2018-05-08T15:15:03.216Z'
System info: host: 'DESKTOP-4DSS7OC', ip: '192.168.2.21', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_161'
Driver info: driver.version: AndroidDriver
    at io.appium.java_client.remote.AppiumCommandExecutor$1.createSession(AppiumCommandExecutor.java:195)
    at io.appium.java_client.remote.AppiumCommandExecutor.createSession(AppiumCommandExecutor.java:209)
    at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:231)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:543)
    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:207)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:130)
    at io.appium.java_client.DefaultGenericMobileDriver.<init>(DefaultGenericMobileDriver.java:38)
    at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:84)
    at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:94)
    at io.appium.java_client.android.AndroidDriver.<init>(AndroidDriver.java:93)
    at testcase.MilonowFirstTest.main(MilonowFirstTest.java:37)
Caused by: java.lang.reflect.InvocationTargetException
    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 io.appium.java_client.remote.AppiumCommandExecutor$1.createSession(AppiumCommandExecutor.java:185)
    ... 13 more
Caused by: org.openqa.selenium.WebDriverException: Unable to parse remote response: The URL '/wb/hub/session' did not map to a valid resource
Build info: version: '3.12.0', revision: '7c6e0b3', time: '2018-05-08T15:15:03.216Z'
System info: host: 'DESKTOP-4DSS7OC', ip: '192.168.2.21', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_161'
Driver info: driver.version: AndroidDriver
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:111)
    ... 18 more

Close the appium server and start it again, this should work. 关闭appium服务器,然后重新启动,这应该可以工作。 The permanent solution for this problem is: 该问题的永久解决方案是:

  • Start Appium app 启动Appium应用
  • Go to advance setting 转到高级设置
  • enter server address and server port that you want. 输入所需的服务器地址和服务器端口。 I am using 127.0.0.1 as server address and 4723 as server port 我正在使用127.0.0.1作为服务器地址和4723作为服务器端口
  • Select or check session Override 选择或检查会话覆盖

If you like you can save this configuration as preset for using next time. 如果愿意,可以将该配置另存为预设以供下次使用。 Also include following desire capabilities in your app 在您的应用程序中还包括追随欲望的能力

AppiumDriver<MobileElement> driver;
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("deviceName", "Android phone");
caps.setCapability("udid", "your device uuid");
caps.setCapability("platformName", "Android");
caps.setCapability("platformVersion", "your device version");
caps.setCapability("appPackage", "name of app package");
caps.setCapability("appActivity", "name of app activity");

driver=new AndroidDriver<MobileElement>(new URL(
            "http://127.0.0.1:4723/wd/hub"), caps);

How to find device uuid? 如何找到装置uuid?

  • Enable usb debugging mode in your android device and connect to your laptop 在Android设备中启用USB调试模式并连接到笔记本电脑
  • Open command prompt and type adb devices 打开命令提示符并键入adb设备

It will show the list of connected devices to your laptop. 它将显示您的笔记本电脑已连接设备的列表。 Below List of devices attached you can find your device uuid 在连接的设备列表下方,您可以找到您的设备uuid

How to find appPackage and appActivity 如何找到appPackage和appActivity

click here: How to find appPackage and appActivity? 单击此处: 如何找到appPackage和appActivity?

Try by putting in desired capabilities parameter "APP", 尝试输入所需的功能参数“ APP”,

cap.setCapability(MobileCapabilityType.APP, "path_to_your_app");

or as You started with a matched in-pair caps, if application is already installed on your device: 或者,如果您已在设备上安装了应用程序,则从匹配的配对电容开始时:

    cap.setCapability("appActivity", "com.test.myapp.ui.activities.MainActivity");
    cap.setCapability("appPackage", "com.test.myapp");

and You can check Your activity and package name with this command, by opening application on Your phone and going to console and run this: 您可以通过以下方法检查您的活动和程序包名称:打开手机上的应用程序,然后进入控制台并运行该程序:

adb shell dumpsys window windows | grep -E 'mCurrentFocus|mFocusedApp'

this will return something like this: 这将返回如下内容:

mCurrentFocus=Window{5f6bfe8 u0 d0 abc.com.test.android/com.test.abc.ui.home.HomeActivity} mCurrentFocus = Window {5f6bfe8 u0 d0 abc.com.test.android/com.test.abc.ui.home.HomeActivity}
mFocusedApp=AppWindowToken{123d4faf token=Token{asd2342 ActivityRecord{323tgee3 u0 abc.com.test.android/com.test.abc.ui.home.HomeActivity t1732}}} mFocusedApp = AppWindowToken {123d4faf token = Token {asd2342 ActivityRecord {323tgee3 u0 abc.com.test.android/com.test.abc.ui.home.HomeActivity t1732}}}

where as follows: 如下:

Window{5f6bfe8 u0 d0 abc.com.test.android/com.test.abc.ui.home.HomeActivity} 窗口{5f6bfe8 u0 d0 abc.com.test.android/com.test.abc.ui.home.HomeActivity}

activity: ` 活动:

"abc.com.test.android" “ abc.com.test.android”

...and is a package ...是一个包装

"com.test.abc.ui.home.HomeActivity" “ com.test.abc.ui.home.HomeActivity”

but recommended to put all params in the mix APP, APP_PACKAGE, APP_ACTIVITY 但建议将所有参数混合使用APP,APP_PACKAGE和APP_ACTIVITY

hope this helps, 希望这可以帮助,

You are calling 你在打电话

  driver = new AndroidDriver<WebElement>(new URL("http://127.0.0.1:4723/wb/hub"), cap); 

Correct URL should be /wd/hub . 正确的URL应该是/ wd / hub

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 线程“主” org.openqa.selenium.WebDriverException中的异常:无法访问Chrome - Exception in thread “main” org.openqa.selenium.WebDriverException: chrome not reachable 线程“主”org.openqa.selenium.WebDriverException 中的异常:权限被拒绝 - Exception in thread “main” org.openqa.selenium.WebDriverException: permission denied 如何修复线程“主”org.openqa.selenium.WebDriverException 中的异常? - How to fix Exception in thread “main” org.openqa.selenium.WebDriverException? 线程“主” org.openqa.selenium.WebDriverException中的异常:未定义$ - Exception in thread “main” org.openqa.selenium.WebDriverException: $ is not defined 线程“主”org.openqa.selenium.WebDriverException 中的异常:未知错误:使用 Selenium Java 的意外命令响应 - Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: unexpected command response using Selenium Java 线程“主” org.openqa.selenium.WebDriverException中的异常:未知错误:无法聚焦元素 - Exception in thread “main” org.openqa.selenium.WebDriverException: unknown error: cannot focus element 线程“main”中的异常 org.openqa.selenium.WebDriverException:驱动程序服务器进程过早死亡 - Exception in thread "main" org.openqa.selenium.WebDriverException: Driver server process died prematurely 线程“ main” org.openqa.selenium.WebDriverException中的异常:未知错误:Chrome无法启动:正常退出 - Exception in thread “main” org.openqa.selenium.WebDriverException: unknown error: Chrome failed to start: exited normally 线程“main”org.openqa.selenium.WebDriverException 中的异常:返回值无法转换为 WebElement:{stacktrace=Backtrace: - Exception in thread "main" org.openqa.selenium.WebDriverException: Returned value cannot be converted to WebElement: {stacktrace=Backtrace: 线程“主”中的异常org.openqa.selenium.WebDriverException:java.net.SocketException:连接重置 - Exception in thread “main” org.openqa.selenium.WebDriverException: java.net.SocketException: Connection reset
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM