Skip to main content

SeeTestAutomation- Using Mobile Listeners In Ruby

info

Please note that this tool is classified as a Legacy tool. We recommend transitioning to our updated solutions to maintain optimal performance and security in your workflows. For more information on this matter, please reach out to technical support .

Description

This feature allows handling an unexpected UI interrupts without compromising the test execution speed.

Once a MobileListener is registered, it would be notified about any relevant event and an action may be taken by the client.

Parameters

  • Type: method of detecting the element

  • Element: element to detect

  • MobileListener: mobile listener object

Return value:

Whether recovered or not.

  • true 

  • false

tip
  • You can register multiple listeners for different XPath's representing elements which might appear on the screen
client.addMobileListener("NATIVE","//*[@text='Dismiss]",listener1)
client.addMobileListener("NATIVE","//*[@text='OK]",listener2)
client.addMobileListener("NATIVE","//*[@text='Cancel]",listener3)
client.addMobileListener(<Zone>,<xpath of the element you wish identify>,<listener object>)

Adding listener example:

  1. Create a MobileListener Class 

    my_listener.rb - Mobile Listener Class

    load "Client.rb"

    module Support
    class MyListener < Mobile::Listener
    def recover(type, xpath)
    begin
    @client.click(<zone>,<xpath of the element the recovery action will be performed on>,0,1)
    warn 'Identified the element, and Recovered!'
    return true
    rescue => e
    warn 'Failed to recover'
    puts e.cause
    return false
    end
    end
    end
    end

2. Init your Mobile Listener in your test script, and add it as a mobile listener to you client

init my listener, wait for xpath=//*[@text='Dismiss'] element

load "Client.rb"
load 'my_listener.rb'
 
client = Mobile::Client.new('127.0.0.1', 8889,true)
listener = Support::MyListener.new()
client.addMobileListener("NATIVE","//*[@text='Dismiss]",listener)
client.click("NATIVE","//*[@text='OK' and @class='android.widget.Button'],0,1)

Assuming that in the above example, clicking on the OK Button failed, due to the fact that a blocking pop-up with text=Dismiss was visible on the screen

Then :

  1. The recovery method from the mobile listener will be invoked, and the Pop-up will be dismissed from the screen
  2. If the recovery method succeed, then the client will execute the original method yet again (click on Button with Text=OK)

3. Remove a mobile Listener 

How To remove a mobile Listener

client.addMobileListener("NATIVE","//*[@text='Dismiss]",nil)

To Remove a mobile listener, use the addMobileListener method, and pass nil as the third parameter