Appium ruby: метод прокрутки не работает и в некоторых случаях не возвращает ошибок - PullRequest
0 голосов
/ 27 апреля 2020

Проблема:

Я занимаюсь разработкой автоматизированных тестов E2E для мобильных приложений Appium в ruby в качестве интерфейса. Мне нужно прокрутить для навигации по меню приложения, но я не смог прокрутить, пытаясь несколькими различными способами.

.env Файл полезная информация:

require "cucumber"
require "appium_lib"
require 'em/pure_ruby'
require 'json'
require "faker"
require "cpf_faker"

def caps 
    {
    caps: {
        platformName: "Android",
        deviceName: "@Nexus_5",
        appPackage: "com.mgensuite.airfox.recharge",
        appActivity: "com.mgensuite.airfoxsdk.activity.AirfoxLendingActivity",
        app: (File.join(File.dirname(__FILE__), "APK/android_banQi-7.0.0-RC-03-stg.apk")),
        newCommandTimeout: "3600"
    }
}
end

Я использую объекты страницы архитектура и создание тестов в BDD с помощью инструмента Cucumber. Метод, который я хочу сделать, заключается в том, что после доступа к меню я хочу, чтобы код прокручивался до тех пор, пока не найдет элемент и не щелкнет по нему, чтобы получить доступ к этому элементу, поэтому я вызываю метод access_XXXXXXXX. После попыток прокрутки страницы (ни одна не удалась):

  1. Tentei passo-a-passo:
def access_about_app()
    #until exists { text ("About the app") } do
    @test_touch_Actions = Appium::TouchAction.new
    wait_for_xpath(main_menu_elements[:helpCenterSection])
    @@el0 = find_element(:xpath, main_menu_elements[:helpCenterSection])
    @@el1 = find_element(:xpath, main_menu_elements[:accountSettingsSection])
    @test_touch_Actions.press(@@el0);
    @test_touch_Actions.moveTo(@@el1);
    @test_touch_Actions.release();
    @test_touch_Actions.perform();
    click_xpath(main_menu_elements[:aboutAppSection])
end

Я знаю, что это не в лучшем случае, но это была попытка после долгого времени с ошибкой сделать шаг за шагом, чтобы попытаться решить и понять. Я получил следующую ошибку:

'select' attribute is unknown for the element. Only the following attributes are supported: [checkable, checked, {class,className}, clickable, {content-desc,contentDescription}, enabled, focusable, focused, {long-clickable,longClickable}, package, password, {resource-id,resourceId}, scrollable, selection-start, selection-end, selected, {text,name}, bounds, displayed, contentSize] (Selenium::WebDriver::Error::UnknownCommandError)
      io.appium.uiautomator2.common.exceptions.NoSuchAttributeException: 'select' attribute is unknown for the element. Only the following attributes are supported: [checkable, checked, {class,className}, clickable, {content-desc,contentDescription}, enabled, focusable, focused, {long-clickable,longClickable}, package, password, {resource-id,resourceId}, scrollable, selection-start, selection-end, selected, {text,name}, bounds, displayed, contentSize]
        at io.appium.uiautomator2.utils.ElementHelpers.generateNoAttributeException(ElementHelpers.java:210)
        at io.appium.uiautomator2.model.UiObject2Element.getAttribute(UiObject2Element.java:93)
        at io.appium.uiautomator2.handler.GetElementAttribute.safeHandle(GetElementAttribute.java:30)
        at io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:38)
        at io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:252)
        at io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(AppiumServlet.java:242)
        at io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:44)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)
        at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)
        at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:435)
        at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:293)
        at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:267)
        at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:250)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)
        at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1294)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
        at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:911)
        at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:131)
        at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:611)
        at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:552)
        at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:466)
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:438)
        at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:140)
        at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:144)
        at java.lang.Thread.run(Thread.java:761)
      ./features/screens/main_menu_screens.rb:35:in `access_about_app'
      ./features/step_definitions/main_menu_steps.rb:41:in `"I go to About App through menu"'
      features/specs/main_menu.feature:26:in `When I go to About App through menu'
Метод, найденный в Stackoverflow с использованием UiSelector:
def access_about_app2()
    scroll_to_exact('About the app')
    click_xpath(main_menu_elements[:aboutAppSection])
end

def scroll_to_exact(text, scrollable_index = 0)
    text = %("#{text}")
    rid  = resource_id(text, "new UiSelector().resourceId(#{text});")
    args = rid.empty? ? ["new UiSelector().text(#{text})", "new UiSelector().description(#{text})"] : [rid]
    args.each_with_index do |arg, index|
        elem = find_element :uiautomator, scroll_uiselector(arg, scrollable_index)
        return elem
        rescue => e
        if index == args.size - 1
            raise e
        end
    end
end

Полученная ошибка:

An element could not be located on the page using the given search parameters. (Selenium::WebDriver::Error::NoSuchElementError)
      NoSuchElementError: An element could not be located on the page using the given search parameters.
          at AndroidUiautomator2Driver.findElOrEls (C:\Program Files\Appium\resources\app\node_modules\appium\node_modules\appium-android-driver\lib\commands\find.js:75:11)
      ./features/support/base_methods.rb:53:in `block in scroll_to_exact'
      ./features/support/base_methods.rb:52:in `each'
      ./features/support/base_methods.rb:52:in `each_with_index'
      ./features/support/base_methods.rb:52:in `scroll_to_exact'
      ./features/screens/main_menu_screens.rb:43:in `access_about_app2'
      ./features/step_definitions/main_menu_steps.rb:41:in `"I go to About App through menu"'
      features/specs/main_menu.feature:26:in `When I go to About App through menu'
Использование touch_actions.swipe:
def access_about_app3()
    @test_touch_Actions = Appium::TouchAction.new
    @test_touch_Actions.swipe(start_x: 0.5, start_y: 0.2, end_x: 0.5, end_y: 0.8, duration: 600).perform
    click_xpath(main_menu_elements[:aboutAppSection])
end

Не было получено ни одной ошибки, но действие прокрутки не было выполнено.

Снова использовать touch_actions.swipe, но без создания для него класса:
def access_about_app4
    Appium::TouchAction.new.swipe(start_x: 0.5, start_y: 0.2, end_x: 0.5, end_y: 0.8, duration: 600).perform
    click_xpath(main_menu_elements[:aboutAppSection])
end
Использование скрипта:
def access_about_app5
    execute_script 'mobile: swipe', direction: 'down'
    click_xpath(main_menu_elements[:aboutAppSection])
end

Ошибка возвращается:

      UnknownCommandError: Unknown mobile command "swipe". Only shell,scrollBackTo,viewportScreenshot,deepLink,startLogsBroadcast,stopLogsBroadcast,acceptAlert,dismissAlert,batteryInfo,deviceInfo,changePermissions,getPermissions,performEditorAction commands are supported.
          at AndroidUiautomator2Driver.extensions.executeMobile (C:\Program Files\Appium\resources\app\node_modules\appium\node_modules\appium-uiautomator2-driver\lib\commands\general.js:124:11)
          at AndroidUiautomator2Driver.executeMobile [as execute] (C:\Program Files\Appium\resources\app\node_modules\appium\node_modules\appium-android-driver\lib\commands\execute.js:11:23)
          at curCommandCancellable._bluebird.default.resolve.then (C:\Program Files\Appium\resources\app\node_modules\appium\node_modules\appium-base-driver\lib\basedriver\driver.js:353:75)
          at tryCatcher (C:\Program Files\Appium\resources\app\node_modules\appium\node_modules\bluebird\js\release\util.js:16:23)
          at Promise._settlePromiseFromHandler (C:\Program Files\Appium\resources\app\node_modules\appium\node_modules\bluebird\js\release\promise.js:547:31)
          at Promise._settlePromise (C:\Program Files\Appium\resources\app\node_modules\appium\node_modules\bluebird\js\release\promise.js:604:18)
          at Promise._settlePromiseCtx (C:\Program Files\Appium\resources\app\node_modules\appium\node_modules\bluebird\js\release\promise.js:641:10)
          at _drainQueueStep (C:\Program Files\Appium\resources\app\node_modules\appium\node_modules\bluebird\js\release\async.js:97:12)
          at _drainQueue (C:\Program Files\Appium\resources\app\node_modules\appium\node_modules\bluebird\js\release\async.js:86:9)
          at Async._drainQueues (C:\Program Files\Appium\resources\app\node_modules\appium\node_modules\bluebird\js\release\async.js:102:5)
          at Immediate.Async.drainQueues (C:\Program Files\Appium\resources\app\node_modules\appium\node_modules\bluebird\js\release\async.js:15:14)
          at runCallback (timers.js:696:18)
          at tryOnImmediate (timers.js:667:5)
          at processImmediate (timers.js:649:5)
      ./features/screens/main_menu_screens.rb:60:in `access_about_app5'
      ./features/step_definitions/main_menu_steps.rb:41:in `"I go to About App through menu"'
      features/specs/main_menu.feature:26:in `When I go to About App through menu'```

I don't get any errors but I don't do the scroll action either. I imagine that solution 4 within an until element_is_visible is the ideal solution but I need the scroll function to work first. In these cases without error I tried running with an android simulator from android studio with the model Nexus 5 and tried with a physical device, the Mi 8 Lite from Xiaomi.
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...