Java 无法实例化 AppiumDriver 类型
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26715642/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cannot instantiate the type AppiumDriver
提问by paul
I have added following jars in my projects build path:
我在我的项目构建路径中添加了以下 jars:
- java-client-2.0.0 from http://appium.io/downloads.html>> Appium Client libraries >> Java
- selenium-java-2.43.1
- selenium-java-2.43.1-srcs
selenium-server-standalone-2.43.1
and here's my code:public class SampleApp{ WebDriver dr; @Test public void testApp() throws MalformedURLException, InterruptedException { String apkpath = "D:\apkdump\sampleapp.apk"; File app = new File (apkpath); DesiredCapabilities capabilities= new DesiredCapabilities(); capabilities.setCapability(CapabilityType.BROWSER_NAME,""); capabilities.setCapability("deviceName","TestADB18"); capabilities.setCapability("platformName","Android"); capabilities.setCapability("app",app.getAbsolutePath()); capabilities.setCapability("appPackage", "com.test"); capabilities.setCapability("appActivity", "com.sampleapp.Main"); dr = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities); dr.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); } }
I am getting red line below
new AppiumDriver
which says thatCannot instantiate the type AppiumDriver
. Now if remove allselenium jars
the error disappears but then I can't resolve errors with webdriver.What is the conflict between jars?
I saw similar question herebut that could run the code and was getting
Null pointer exception
but in my case I cant even run it, it is giving run on saving the code. Secondly the answer has been posted without usingAppiumDriver
- java-client-2.0.0 来自http://appium.io/downloads.html>> Appium 客户端库 >> Java
- 硒-java-2.43.1
- selenium-java-2.43.1-srcs
selenium-server-standalone-2.43.1
这是我的代码:public class SampleApp{ WebDriver dr; @Test public void testApp() throws MalformedURLException, InterruptedException { String apkpath = "D:\apkdump\sampleapp.apk"; File app = new File (apkpath); DesiredCapabilities capabilities= new DesiredCapabilities(); capabilities.setCapability(CapabilityType.BROWSER_NAME,""); capabilities.setCapability("deviceName","TestADB18"); capabilities.setCapability("platformName","Android"); capabilities.setCapability("app",app.getAbsolutePath()); capabilities.setCapability("appPackage", "com.test"); capabilities.setCapability("appActivity", "com.sampleapp.Main"); dr = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities); dr.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); } }
我在下面
new AppiumDriver
看到红线,上面写着Cannot instantiate the type AppiumDriver
。现在,如果删除所有selenium jars
错误消失,但我无法解决 webdriver 的错误。jar 之间的冲突是什么?
我在这里看到了类似的问题,但是可以运行代码并且正在运行,
Null pointer exception
但是在我的情况下,我什至无法运行它,它正在运行保存代码。其次,答案已发布而未使用AppiumDriver
采纳答案by paul
This error can be fixed by downgrading the Appium Client
(see step 1 in my question) from latest to java-client-1.5.0
. You can keep rest of the jars to latest.
可以通过将Appium Client
(参见我的问题中的第 1 步)从 latest降级到java-client-1.5.0
. 您可以将其余的罐子保持最新。
Downgraded version of Appium Client
can be downloaded from here http://mvnrepository.com/artifact/io.appium/java-client/1.5.0
Appium Client
可以从这里下载的
降级版本http://mvnrepository.com/artifact/io.appium/java-client/1.5.0
回答by Hassan Radi
You don't need to downgrade or anything. There is a design change in the Java Client version 2.0.0 as they mention on their site:
你不需要降级或任何东西。正如他们在他们的网站上提到的,Java 客户端 2.0.0 版中有一个设计更改:
AppiumDriver is now an abstract class, use IOSDriver and AndroidDriver which both extend it.
AppiumDriver 现在是一个抽象类,使用 IOSDriver 和 AndroidDriver 扩展它。
So, just change your driver line to be:
因此,只需将您的驱动程序行更改为:
dr = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);
Hope that helps...
希望有帮助...
回答by Satya Ram hari krishna swamy
WebDriver driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),getDesiredCapabilities("192.21.168.56:5555"));
use this. and import:
用这个。并导入:
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
回答by Guru
dr=new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);
dr=new AppiumDriver(new URL(" http://127.0.0.1:4723/wd/hub"),capabilities);
proper URL to be established
要建立正确的 URL
回答by Manish Patil
for appium version 1.7 use capability cap.setCapability(MobileCapabilityType.AUTOMATION_NAME, "uiautomator2");
对于 appium 1.7 版使用功能 cap.setCapability(MobileCapabilityType.AUTOMATION_NAME, "uiautomator2");
while for v1.8.1 its not needed
而对于 v1.8.1 则不需要