线程“main"中的异常org.openqa.selenium.WebDriverException [英] Exception in thread "main" org.openqa.selenium.WebDriverException

查看:32
本文介绍了线程“main"中的异常org.openqa.selenium.WebDriverException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用抛出此错误的 java 在 Eclipse IDE 中测试我的应用程序.我也启动了 appium 服务器.也给出了匹配的端口号.这是我的日志跟踪.帮帮我.提前致谢

这是我用于使用 appium 测试我的 android 应用程序的代码:

公共类 MilonowFirstTest {静态 AppiumDriver司机;// @课前public static void main(String[] args) 抛出 MalformedURLException//public void Setup() 抛出 MalformedURLException{DesiredCapabilities cap = new DesiredCapabilities();//cap.setCapability(AndroidMobileCapabilityType.De, value);cap.setCapability(MobileCapabilityType.DEVICE_NAME,Android 模拟器");//cap.setCapability(MobileCapabilityType.APP_PACKAGE, value);cap.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, "com.test.myapp");//cap.setCapability(MobileCapabilityType.APP, "");cap.setCapability("avd", "荣誉 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());}//     @测试()//public void SimpleTest()//{//Assert.assertNotNull(driver.getContext());//}}

错误日志:

线程main" org.openqa.selenium.WebDriverException 中的异常:无法创建新会话,因为使用 HttpClient、InputStream 和 long 的createSession"未找到或无法访问构建信息:版本:'3.12.0',修订版:'7c6e0b3',时间:'2018-05-08T15:15:03.216Z'系统信息:主机:'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.version:AndroidDriver在 io.appium.java_client.remote.AppiumCommandExecutor$1.createSession(AppiumCommandExecutor.java:195)在 io.appium.java_client.remote.AppiumCommandExecutor.createSession(AppiumCommandExecutor.java:209)在 io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:231)在 org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:543)在 io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)在 io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)在 io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)在 org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:207)在 org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:130)在 io.appium.java_client.DefaultGenericMobileDriver.(DefaultGenericMobileDriver.java:38)在 io.appium.java_client.AppiumDriver.(AppiumDriver.java:84)在 io.appium.java_client.AppiumDriver.(AppiumDriver.java:94)在 io.appium.java_client.android.AndroidDriver.<init>(AndroidDriver.java:93)在 testcase.MilonowFirstTest.main(MilonowFirstTest.java:37)引起:java.lang.reflect.InvocationTargetException在 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)在 sun.reflect.NativeMethodAccessorImpl.invoke(来源不明)在 sun.reflect.DelegatingMethodAccessorImpl.invoke(来源不明)在 java.lang.reflect.Method.invoke(Unknown Source)在 io.appium.java_client.remote.AppiumCommandExecutor$1.createSession(AppiumCommandExecutor.java:185)……还有 13 个引起:org.openqa.selenium.WebDriverException:无法解析远程响应:URL '/wb/hub/session' 未映射到有效资源构建信息:版本:'3.12.0',修订版:'7c6e0b3',时间:'2018-05-08T15:15:03.216Z'系统信息:主机:'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.version:AndroidDriver在 org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:111)……还有 18 个

解决方案

关闭 appium 服务器并重新启动它,这应该可以工作.此问题的永久解决方案是:

  • 启动 Appium 应用
  • 进入高级设置
  • 输入您想要的服务器地址和服务器端口.我使用 127.0.0.1 作为服务器地址,使用 4723 作为服务器端口
  • 选择或检查会话覆盖

如果您愿意,可以将此配置保存为预设以备下次使用.还要在您的应用中加入以下欲望功能

AppiumDriver司机;DesiredCapabilities caps = new DesiredCapabilities();caps.setCapability("deviceName", "Android 手机");caps.setCapability("udid", "你的设备 uuid");caps.setCapability("platformName", "Android");caps.setCapability("platformVersion", "您的设备版本");caps.setCapability("appPackage", "应用包名称");caps.setCapability("appActivity", "应用活动名称");driver=new AndroidDriver(新网址(http://127.0.0.1:4723/wd/hub"),大写);

如何查找设备 uuid?

  • 在您的 Android 设备中启用 USB 调试模式并连接到您的笔记本电脑
  • 打开命令提示符并输入 adb devices

它将显示连接到您的笔记本电脑的设备列表.在连接的设备列表下方,您可以找到您的设备 uuid

如何查找 appPackage 和 appActivity

单击此处:如何查找 appPackage 和 appActivity?>

I'm trying to test my application in eclipse IDE using java throwing this error. I started appium server also. 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:

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. The permanent solution for this problem is:

  • Start Appium app
  • 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
  • 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?

  • Enable usb debugging mode in your android device and connect to your laptop
  • Open command prompt and type adb devices

It will show the list of connected devices to your laptop. Below List of devices attached you can find your device uuid

How to find appPackage and appActivity

click here: How to find appPackage and appActivity?

这篇关于线程“main"中的异常org.openqa.selenium.WebDriverException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆