gpt4 book ai didi

java - Appium TestNG 测试 : Unable to select from secondary Menu list: NoSuchElementException

转载 作者:行者123 更新时间:2023-12-02 10:53:57 24 4
gpt4 key购买 nike

我正在使用 maven 和 testNG 以及 Appium Desktop 构建示例 appium 框架。

我想构建并运行一个“简单测试”;只是为了确保在开始执行添加“页面对象”和 log4j 等复杂操作之前我拥有正确的“testNG 边界”

我创建了一个非常简单的测试,使用 Android 来执行拖放测试。

流程是从应用程序主菜单>点击 View >点击拖放>执行拖放

查看下面的菜单

enter image description here

现在我可以从主菜单中选择“ View ”,但无法从 View 菜单中点击拖放。我不断收到以下错误消息,据我所知,选择 View “看起来不错”的语法。

如果语法错误

  1. 我做错了什么?
  2. 如何修复它?

TestNG代码

   public class DragnDropTest {
static AndroidDriver<MobileElement> driver;

@BeforeTest
public AndroidDriver<MobileElement> initDriver() throws MalformedURLException{



DesiredCapabilities caps =new DesiredCapabilities();
caps.setCapability("deviceName", "JacquelineNexus5");
caps.setCapability("platformName", "Android");
caps.setCapability("platformVersion", "8.0");
caps.setCapability("automationName", "UiAutomator2");
caps.setCapability("appPackage", "com.example.android.apis");
caps.setCapability("appActivity", "ApiDemos");

driver = new AndroidDriver<MobileElement>(new URL("http://127.0.0.1:4723/wd/hub"), caps);
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
return driver;
}




@Test
//Scenario: Perform Drag n drop function

//Given I am on the Home screen
//When I tap the 'Views' menu item
//Then I will see the Views menu
//When I am in the 'view menu' I will select 'drag n drop'
//Then I will see 4 dots in the drag n drop page
//When I select the 1st dot and drag it
//Then I will drop it on the dot below

public void DragAndDrop(){

// tap Views from main menu
driver.findElementsById("android:id/text1").get(11).click();


driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);

TouchAction t = new TouchAction (driver);

//Tap Drag and drop from Views Menu
t.tap(driver.findElementByXPath("//android.widget.EditText[@index= '8']")).perform();

t.longPress(driver.findElementById("io.appium.android.apis:id/drag_dot_1")).
moveTo(driver.findElementById("io.appium.android.apis:id/drag_dot_3")).release().perform();
}

}

Eclipse 控制台消息

[RemoteTestNG] detected TestNG version 6.11.0
Aug 20, 2018 12:17:26 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
FAILED: DragAndDrop
org.openqa.selenium.NoSuchElementException: An element could not be located on the page using the given search parameters. (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '3.6.0', revision: '6fbf3ec767', time: '2017-09-27T15:28:36.4Z'
System info: host: 'XXX-MacBook-Air.local', ip: '00.00.0.00', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.13.6', java.version: '1.8.0_71'
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities [{appPackage=com.example.android.apis, deviceScreenSize=1080x1920, networkConnectionEnabled=true, statBarHeight=63, warnings={}, viewportRect={top=63, left=0, width=1080, height=1731}, databaseEnabled=false, deviceName=emulator-5554, platform=LINUX, deviceUDID=emulator-5554, appActivity=ApiDemos, desired={appActivity=ApiDemos, appPackage=com.example.android.apis, platformVersion=8.0, automationName=UiAutomator2, platformName=Android, deviceName=JacquelineNexus5}, platformVersion=8.0.0, pixelRatio=2.625, webStorageEnabled=false, locationContextEnabled=false, automationName=UiAutomator2, takesScreenshot=true, javascriptEnabled=true, deviceScreenDensity=420, deviceModel=Android SDK built for x86, deviceManufacturer=Google, deviceApiLevel=26, platformName=LINUX}]
Session ID: c2726815-8435-4b3d-b3c8-92f6845c616b
*** Element info: {Using=xpath, value=//android.widget.EditText[@index= '8']}
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
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.http.JsonHttpResponseCodec.reconstructValue(JsonHttpResponseCodec.java:40)
at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:80)
at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:44)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:89)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:545)
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:319)
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 org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:421)
at io.appium.java_client.DefaultGenericMobileDriver.findElementByXPath(DefaultGenericMobileDriver.java:140)
at io.appium.java_client.AppiumDriver.findElementByXPath(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.findElementByXPath(AndroidDriver.java:1)
at android.DragnDropTest.DragAndDrop(DragnDropTest.java:71)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:108)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:661)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:869)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1193)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:126)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.privateRun(TestRunner.java:744)
at org.testng.TestRunner.run(TestRunner.java:602)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:380)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:375)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340)
at org.testng.SuiteRunner.run(SuiteRunner.java:289)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1301)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1226)
at org.testng.TestNG.runSuites(TestNG.java:1144)
at org.testng.TestNG.run(TestNG.java:1115)
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)

最佳答案

如果您看到 appium 服务器日志,它表示根据传递的定位器未找到元素

org.openqa.selenium.NoSuchElementException: An element could not be located on the page using the given search parameters. (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 0 milliseconds

由于您已经在测试中添加了 60 秒隐式等待,但 appium 不接受它,因此您必须在代码中传递以下功能。

    caps.setCapability("newCommandTimeout", "2000");

注意 - 确保您的 xpath 正确。

我还有一个建议,您可以在此处查看用于拖放的官方 appium 单元测试功能

关于java - Appium TestNG 测试 : Unable to select from secondary Menu list: NoSuchElementException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51929746/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com