Текст предиката iOS не находит элемента, но работает с Xpath в Java приложения - PullRequest
0 голосов
/ 02 октября 2019

Я новичок в тестировании автоматизации iOS через appium Java. Я написал этот код для включения текста предиката. по какой-то причине xpath работает нормально, но когда я использую текст предиката, я не получаю такого исключения элемента

Iam с использованием Eclipse, maven appium 1.7.2 и я использую симулятор ioS

Мой appiumсервер установлен на последнюю версию

protected IOSDriver<IOSElement> driver = null;

DesiredCapabilities dc = new DesiredCapabilities();

@BeforeMethod
public void setUp() throws MalformedURLException {


    dc.setCapability("deviceName", "iPhone X");
    dc.setCapability("platformName", "iOS");
    dc.setCapability("app", "xxx.app";
    dc.setCapability("platformVersion", "12.2");
    dc.setCapability("automationName", "XCUITest");
    dc.setCapability("useNewWDA", true);
    dc.setCapability("fullReset", false);
    dc.setCapability("appiumVersion", "1.7.2");
    //dc.setCapability("automationName", "XCUITest");
    driver = new iOSDriver<>(new URL("http://localhost:4723/wd/hub"), dc);
    driver.setLogLevel(Level.INFO);
}

@Test
public void testUntitled() throws InterruptedException {


driver.findElement(By.xpath("//XCUIElementTypeButton[@name='Allow']")).click();
        Thread.sleep(10000);
        String selector= "type == 'XCUIElementTypeTextField' AND value == 

'Email'";
driver.findElement(MobileBy.iOSNsPredicateString(selector)).sendKeys("gjghhj");   driver.findElement(By.xpath("//XCUIElementTypeTextField[@value='Email']")).sendKeys("dssss");

}

Я ожидаю, что он обнаружит поле электронной почты с помощью текста предиката iOS

Я получаю исключение ниже pls help

org.openqa.selenium.NoSuchElementException: An element could not be located on the page using the given search parameters.
*** Element info: {Using=-ios predicate string, value=type == 'XCUIElementTypeTextField' AND value == 'Email'}
    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:423)
    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:41)
    at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:323)
    at io.appium.java_client.DefaultGenericMobileDriver.findElement(DefaultGenericMobileDriver.java:61)
    at io.appium.java_client.AppiumDriver.findElement(AppiumDriver.java:1)
    at io.appium.java_client.MobileBy.findElement(MobileBy.java:61)
    at io.appium.java_client.MobileBy$ByIosNsPredicate.findElement(MobileBy.java:458)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:315)
    at io.appium.java_client.DefaultGenericMobileDriver.findElement(DefaultGenericMobileDriver.java:57)
    at io.appium.java_client.AppiumDriver.findElement(AppiumDriver.java:1)
    at com.gtl.probatio.tests.iosLeap.testUntitled(iosLeap.java:54)
    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:498)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:583)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:719)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:989)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
    at org.testng.TestRunner.privateRun(TestRunner.java:648)
    at org.testng.TestRunner.run(TestRunner.java:505)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
    at org.testng.SuiteRunner.run(SuiteRunner.java:364)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
    at org.testng.TestNG.runSuites(TestNG.java:1049)
    at org.testng.TestNG.run(TestNG.java:1017)
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)

Ответы [ 2 ]

0 голосов
/ 28 октября 2019

Попробуйте на classChain. (https://github.com/facebookarchive/WebDriverAgent/wiki/Class-Chain-Queries-Construction-Rules).

MobileBy.iOSClassChain ("** / XCUIElementTypeTextField [` value == 'Email'`] ")

0 голосов
/ 18 октября 2019

Ваш предикат, вероятно, неверен. Попробуйте использовать name вместо value

String selector= "type == 'XCUIElementTypeTextField' AND name == 'Email'";

PS Вы не должны использовать Thread.sleep();, если не знаете точного времени ожидания. Попробуйте эту служебную функцию:

public void waitForExistence(final String predicate) {
        for (int attempt = 0; attempt < 10; attempt++) {
            try {
                driver.findElementByIosNsPredicate(predicate);
                break;
            } catch (Exception e) {
                driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS);
            }
        }
    }
...