我正在尝试为appium(https://github.com/testdotai/appium-classifier-plugin)运行test.ai插件。它具有自定义定位器策略。我设置了appium(版本1.13.0,也尝试降级到1.9.2-beta.2)并做到了:
'npm install -g test-ai-classifier'
它已安装,如下所示:
https://i.stack.imgur.com/fwtkt.png
然后我写了一个简单的测试来检查所有设置是否正确:
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.MobileBy;
import io.appium.java_client.MobileElement;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import org.junit.Before;
import org.junit.After;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
public class TestClass {
private AppiumDriver driver;
private By cart = MobileBy.custom("cart");
@Before
public void setUp() throws MalformedURLException {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "9");
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "NB1GAD17B1504154");
capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, "Chrome");
HashMap<String, String> customFindModules = new HashMap<>();
customFindModules.put("ai", "test-ai-classifier");
capabilities.setCapability("customFindModules", customFindModules);
capabilities.setCapability("shouldUseCompactResponses", false);
driver = new AndroidDriver(new URL("http://localhost:4723/wd/hub"), capabilities);
}
@After
public void tearDown(){
}
@Test
public void testMethod(){
goToWebsite(driver);
openCartUseAi(driver);
}
public void goToWebsite(AppiumDriver driver){
driver.get("https://www.ebay.com/");
}
public void openCartUseAi(AppiumDriver driver){
driver.findElement(cart).click();
}
}
这在运行时导致以下错误:
/usr/lib/jvm/java-1.11.0-openjdk-amd64/bin/java -ea -Didea.test.cyclic.buffer.size=1048576 -javaagent:/home/piotrek/intellij/ideaIC-2019.1.2/idea-IC-191.7141.44/lib/idea_rt.jar=46303:/home/piotrek/intellij/ideaIC-2019.1.2/idea-IC-191.7141.44/bin -Dfile.encoding=UTF-8 -classpath /home/piotrek/intellij/ideaIC-2019.1.2/idea-IC-191.7141.44/lib/idea_rt.jar:/home/piotrek/intellij/ideaIC-2019.1.2/idea-IC-191.7141.44/plugins/junit/lib/junit-rt.jar:/home/piotrek/intellij/ideaIC-2019.1.2/idea-IC-191.7141.44/plugins/junit/lib/junit5-rt.jar:/home/piotrek/IdeaProjects/appiumTestMVN/target/test-classes:/home/piotrek/Downloads/selenium-server-standalone-3.141.59.jar:/home/piotrek/.m2/repository/io/appium/java-client/7.0.0/java-client-7.0.0.jar:/home/piotrek/.m2/repository/org/seleniumhq/selenium/selenium-java/3.141.59/selenium-java-3.141.59.jar:/home/piotrek/.m2/repository/org/seleniumhq/selenium/selenium-chrome-driver/3.141.59/selenium-chrome-driver-3.141.59.jar:/home/piotrek/.m2/repository/org/seleniumhq/selenium/selenium-edge-driver/3.141.59/selenium-edge-driver-3.141.59.jar:/home/piotrek/.m2/repository/org/seleniumhq/selenium/selenium-firefox-driver/3.141.59/selenium-firefox-driver-3.141.59.jar:/home/piotrek/.m2/repository/org/seleniumhq/selenium/selenium-ie-driver/3.141.59/selenium-ie-driver-3.141.59.jar:/home/piotrek/.m2/repository/org/seleniumhq/selenium/selenium-opera-driver/3.141.59/selenium-opera-driver-3.141.59.jar:/home/piotrek/.m2/repository/org/seleniumhq/selenium/selenium-remote-driver/3.141.59/selenium-remote-driver-3.141.59.jar:/home/piotrek/.m2/repository/org/seleniumhq/selenium/selenium-safari-driver/3.141.59/selenium-safari-driver-3.141.59.jar:/home/piotrek/.m2/repository/net/bytebuddy/byte-buddy/1.8.15/byte-buddy-1.8.15.jar:/home/piotrek/.m2/repository/org/apache/commons/commons-exec/1.3/commons-exec-1.3.jar:/home/piotrek/.m2/repository/com/google/guava/guava/25.0-jre/guava-25.0-jre.jar:/home/piotrek/.m2/repository/com/google/code/findbugs/jsr305/1.3.9/jsr305-1.3.9.jar:/home/piotrek/.m2/repository/org/checkerframework/checker-compat-qual/2.0.0/checker-compat-qual-2.0.0.jar:/home/piotrek/.m2/repository/com/google/errorprone/error_prone_annotations/2.1.3/error_prone_annotations-2.1.3.jar:/home/piotrek/.m2/repository/com/google/j2objc/j2objc-annotations/1.1/j2objc-annotations-1.1.jar:/home/piotrek/.m2/repository/org/codehaus/mojo/animal-sniffer-annotations/1.14/animal-sniffer-annotations-1.14.jar:/home/piotrek/.m2/repository/com/squareup/okhttp3/okhttp/3.11.0/okhttp-3.11.0.jar:/home/piotrek/.m2/repository/com/squareup/okio/okio/1.14.0/okio-1.14.0.jar:/home/piotrek/.m2/repository/org/seleniumhq/selenium/selenium-support/3.141.59/selenium-support-3.141.59.jar:/home/piotrek/.m2/repository/org/seleniumhq/selenium/selenium-api/3.141.59/selenium-api-3.141.59.jar:/home/piotrek/.m2/repository/com/google/code/gson/gson/2.8.5/gson-2.8.5.jar:/home/piotrek/.m2/repository/org/apache/httpcomponents/httpclient/4.5.6/httpclient-4.5.6.jar:/home/piotrek/.m2/repository/org/apache/httpcomponents/httpcore/4.4.10/httpcore-4.4.10.jar:/home/piotrek/.m2/repository/commons-logging/commons-logging/1.2/commons-logging-1.2.jar:/home/piotrek/.m2/repository/commons-codec/commons-codec/1.10/commons-codec-1.10.jar:/home/piotrek/.m2/repository/cglib/cglib/3.2.8/cglib-3.2.8.jar:/home/piotrek/.m2/repository/org/ow2/asm/asm/6.2.1/asm-6.2.1.jar:/home/piotrek/.m2/repository/org/apache/ant/ant/1.10.3/ant-1.10.3.jar:/home/piotrek/.m2/repository/org/apache/ant/ant-launcher/1.10.3/ant-launcher-1.10.3.jar:/home/piotrek/.m2/repository/commons-validator/commons-validator/1.6/commons-validator-1.6.jar:/home/piotrek/.m2/repository/commons-beanutils/commons-beanutils/1.9.2/commons-beanutils-1.9.2.jar:/home/piotrek/.m2/repository/commons-digester/commons-digester/1.8.1/commons-digester-1.8.1.jar:/home/piotrek/.m2/repository/commons-collections/commons-collections/3.2.2/commons-collections-3.2.2.jar:/home/piotrek/.m2/repository/org/apache/commons/commons-lang3/3.8/commons-lang3-3.8.jar:/home/piotrek/.m2/repository/commons-io/commons-io/2.6/commons-io-2.6.jar:/home/piotrek/.m2/repository/org/springframework/spring-context/5.1.0.RELEASE/spring-context-5.1.0.RELEASE.jar:/home/piotrek/.m2/repository/org/springframework/spring-aop/5.1.0.RELEASE/spring-aop-5.1.0.RELEASE.jar:/home/piotrek/.m2/repository/org/springframework/spring-beans/5.1.0.RELEASE/spring-beans-5.1.0.RELEASE.jar:/home/piotrek/.m2/repository/org/springframework/spring-core/5.1.0.RELEASE/spring-core-5.1.0.RELEASE.jar:/home/piotrek/.m2/repository/org/springframework/spring-jcl/5.1.0.RELEASE/spring-jcl-5.1.0.RELEASE.jar:/home/piotrek/.m2/repository/org/springframework/spring-expression/5.1.0.RELEASE/spring-expression-5.1.0.RELEASE.jar:/home/piotrek/.m2/repository/org/aspectj/aspectjweaver/1.9.1/aspectjweaver-1.9.1.jar:/home/piotrek/.m2/repository/org/slf4j/slf4j-api/1.7.25/slf4j-api-1.7.25.jar:/home/piotrek/.m2/repository/junit/junit/4.12/junit-4.12.jar:/home/piotrek/.m2/repository/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 -junit4 TestClass,testMethod
Jun 07, 2019 1:43:44 PM io.appium.java_client.remote.AppiumCommandExecutor$1 lambda$0
INFO: Detected dialect: W3C
org.openqa.selenium.InvalidArgumentException: invalid argument: Unsupported locator strategy: -custom
(Session info: chrome=74.0.3729.157)
(Driver info: chromedriver=74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29}),platform=Linux 5.0.0-15-generic x86_64)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
System info: host: 'piotrek-VirtualBox', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '5.0.0-15-generic', java.version: '11.0.3'
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities {browserName: Chrome, customFindModules: {ai: test-ai-classifier}, databaseEnabled: false, desired: {browserName: Chrome, customFindModules: {ai: test-ai-classifier}, deviceName: NB1GAD17B1504154, platformName: android, platformVersion: 9, shouldUseCompactResponses: false}, deviceManufacturer: HMD Global, deviceModel: TA-1004, deviceName: NB1GAD17B1504154, deviceScreenSize: 1440x2560, deviceUDID: NB1GAD17B1504154, javascriptEnabled: true, locationContextEnabled: false, networkConnectionEnabled: true, platform: LINUX, platformName: Android, platformVersion: 9, shouldUseCompactResponses: false, takesScreenshot: true, warnings: {}, webStorageEnabled: false}
Session ID: 6cb83c3b-3405-483a-8dc3-21eec62b4676
*** Element info: {Using=-custom, value=ai:cart}
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:239)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
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.findElement(RemoteWebDriver.java:323)
at io.appium.java_client.DefaultGenericMobileDriver.findElement(DefaultGenericMobileDriver.java:62)
at io.appium.java_client.AppiumDriver.findElement(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.findElement(AndroidDriver.java:1)
at io.appium.java_client.FindsByCustom.findElementByCustom(FindsByCustom.java:38)
at TestClass.openCartUseAi(TestClass.java:64)
at TestClass.testMethod(TestClass.java:49)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Process finished with exit code 255
谁能告诉我我在做什么错?当重写此测试以不使用插件时,一切正常,因此正确设置了Appium。
我看过此文档,但仍然看不到我缺少的内容:http://appium.io/docs/en/advanced-concepts/element-finding-plugins/
预先感谢您的帮助!
PS不确定这是否相关,但是我为此使用了Ubuntu虚拟机
答案 0 :(得分:1)
此错误消息...
org.openqa.selenium.InvalidArgumentException: invalid argument: Unsupported locator strategy: -custom
...表示 ChromeDriver 由于无法启动/产生新的 WebBrowser 即 Chrome浏览器会话不受支持的定位器策略内的无效参数。
您的主要问题是所使用的二进制版本之间的不兼容性:
支持 Chrome v71-73
支持 Chrome v74
因此 ChromeDriver v2.46 与 Chrome浏览器v74.0
之间存在明显的不匹配答案 1 :(得分:0)
好的,我自己弄清楚了。显然,Appium和Test.Ai尚不支持Web应用程序上的自定义定位器策略。目前,这仅适用于本机应用程序。遗憾的是他们没有在文档中添加此信息:P