Identifying Each IOS Screen As Unique

Hi
I’m developing a test platform with appium for IOS.
And I’ve a specific requirement in my platform software which is :

I want to identify each screen(window) with a unique id (or something else as long as I can identify it as a unique screen) so each time when I test a screen I will have knowledge about which screen I’m testing
Its impossible for me to make IOS application developers to give some id or name to their screens(windows) so I should find a way to uniquely identify each screen by using appium APIs

Is something like that possible with appium?
Or did anyone use something similar

Thanks
Tolga

Hi tolga
I would challenge the above assumption. Mobile applications really should be made from the get go with accessibility in mind. If your developers are using stock ui kits, it shouldn’t be that hard.

If that’s not doable, there are other identifiers (although not as powerful as Id) such as:
iOS ui automation
Ui Automator (android)
xpath
Text and text_exact methods for finding elements by text value.

There’s tons of examples here on this board as well as the sauce labs appium boot camp

Good luck!

Continuing the discussion from Identifying Each IOS Screen As Unique:

Hi
Thanks for answering, my above assumptions is a must actuallally.
Because in the platform we are trying to develop we are not focusing on testing our own application
We are focusing on testing applications from developers worldwide.
So I have no opportunity to tell that developers “Please put an id or name to your screens”
So I should find a way to uniquely identify each screen even if the developer of application didn’t assign anything on it.

About your other suggestions I didn’t understand what you actually mean by:
iOS ui automation
Ui Automator (android)
xpath

  1. About your IOS UI Automation and UI Automator suggestion, they are the platform tools that appium uses in background. How can I achieve to identify each unique screen by using them?
  2. about xpath variable is there any xpath variable for screens, I saw it in the output xml of appium when we call driver.getPageSource() method, but as far as I seen the path variable is only defined for UI Elements (Such as textfield, buttons etc) is there any xpath variable which is for the current window?
    If something like that possible? How can I get that xpath variable

Thanks
Tolga

Hi tolga. I would go through the appium tutorials online to help with your questions.
For good topics on your specific locator strategies, I pulled these links.

Good luck!

Ui automation

Xpath

Uiautomator general info
https://docs.saucelabs.com/tutorials/appium/

Sherman

Thanks for the info but
The links that you send doesn’t contain the information that I’m looking for
What I’m actually looking is like in the below example

I’ve 2 separate xml output of my tested applications current screens

How can I Separate these 2 screens from each other. I mean how can I understand that I switched to 2nd screen?
When I Press the UIAButton in 1st screen the application pushes the 2nd screen so what I’m actually looking for is how can I understand that I switched from 1st screen to 2nd

1.Screen(Privacy Policy Screen)

    <UIAApplication name="MTOSApp" label="MTOSApp" value="" dom="" enabled="true" valid="true" visible="true" hint="" path="/0" x="0" y="20" width="375" height="647">
    <UIAWindow name="" label="" value="" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/0" x="0" y="0" width="375" height="667">
        <UIANavigationBar name="Kullan?c? So?zles?mesi" label="" value="" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/0/0" x="0" y="20" width="375" height="44">
            <UIAImage name="" label="" value="" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/0/0" x="0" y="0" width="375" height="64">
                <UIAImage name="" label="" value="" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/0/0/0" x="0" y="64" width="375" height="0.5">
                </UIAImage>
            </UIAImage>
            <UIAButton name="Back" label="Back" value="" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/0/1" x="8" y="31.5" width="21" height="21">
            </UIAButton>
            <UIAStaticText name="Kullan?c? So?zles?mesi" label="Kullan?c? So?zles?mesi" value="Kullan?c? So?zles?mesi" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/0/0/2" x="107" y="28" width="161" height="27">
            </UIAStaticText>
        </UIANavigationBar>
        <UIATextView name="" label="" value="Some privacy policy text." dom="" enabled="true" valid="true" visible="true" hint="" path="/0/0/1" x="0" y="0" width="375" height="585">
        </UIATextView>
        <UIAButton name="Kabul Et ve Devam Et" label="Kabul Et ve Devam Et" value="" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/0/2" x="82" y="617" width="211" height="30">
        </UIAButton>
        <UIAToolbar name="" label="" value="" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/3" x="0" y="667" width="375" height="44">
            <UIAImage name="" label="" value="" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/3/0" x="0" y="666.5" width="375" height="0.5">
            </UIAImage>
            <UIAImage name="" label="" value="" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/3/1" x="0" y="667" width="375" height="44">
            </UIAImage>
        </UIAToolbar>
    </UIAWindow>
    <UIAWindow name="" label="" value="" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/1" x="0" y="0" width="375" height="667">
    </UIAWindow>
  1. Second screen(Login Screen)

     <UIAApplication name="MTOSApp" label="MTOSApp" value="" dom="" enabled="true" valid="true" visible="true" hint="" path="/0" x="0" y="20" width="375" height="647">
     <UIAWindow name="" label="" value="" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/0" x="0" y="0" width="375" height="667">
         <UIANavigationBar name="Giris? Ekran?" label="" value="" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/0/0" x="0" y="20" width="375" height="44">
             <UIAImage name="" label="" value="" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/0/0" x="0" y="0" width="375" height="64">
                 <UIAImage name="" label="" value="" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/0/0/0" x="0" y="64" width="375" height="0.5">
                 </UIAImage>
             </UIAImage>
             <UIAButton name="Back" label="Back" value="" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/0/0/1" x="8" y="26" width="58" height="30">
             </UIAButton>
             <UIAButton name="Back" label="Back" value="" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/0/0/2" x="8" y="31.5" width="21" height="21">
             </UIAButton>
             <UIAStaticText name="Giris? Ekran?" label="Giris? Ekran?" value="Giris? Ekran?" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/0/0/3" x="142.5" y="28" width="90" height="27">
             </UIAStaticText>
         </UIANavigationBar>
         <UIATextField name="" label="" value="" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/0/1" x="184" y="145" width="187" height="30">
         </UIATextField>
         <UIAStaticText name="Kullan?c? Ad?" label="Kullan?c? Ad?" value="Kullan?c? Ad?" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/0/2" x="64" y="154" width="118" height="21">
         </UIAStaticText>
         <UIASecureTextField name="" label="" value="" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/0/3" x="184" y="239" width="187" height="30">
         </UIASecureTextField>
         <UIAStaticText name="S?ifre" label="S?ifre" value="S?ifre" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/0/4" x="64" y="248.5" width="112" height="20.5">
         </UIAStaticText>
         <UIAButton name="Giris?" label="Giris?" value="" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/0/5" x="120" y="418" width="32" height="30">
         </UIAButton>
         <UIAToolbar name="" label="" value="" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/6" x="0" y="667" width="375" height="44">
             <UIAImage name="" label="" value="" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/6/0" x="0" y="666.5" width="375" height="0.5">
             </UIAImage>
             <UIAImage name="" label="" value="" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/6/1" x="0" y="667" width="375" height="44">
             </UIAImage>
         </UIAToolbar>
     </UIAWindow>
    

Thanks
Tolga

Hi Tolga,

I’m curious why you are not using ARC or the appium inspector? This would make identifying your elements quite a bit easier than the raw xml.

It’s hard to tell what identifier to use based on this xml. It really comes down to answering the question: “what makes window 2 truly unique from window 1?”. this can be anything, really.

The key is, you want to key on an element that won’t change over time. The label is usually the best for that.

I can’t tell for sure, but it looks like your UIAStaticText name= values between windows 1 and 2 differ. So you can do an assertion based on the text command:

Examples. I’m using Ruby but translate to whichever language makes sense for you. set my_timeout to any integer (# of seconds) you want.

A possible excerpt from your page object for window 1

def assert_exists 
   wait = Selenium::WebDriver::Wait.new :timeout => my_timeout
   wait.until { text("Kabul Et ve Devam Et"}
end

def assert
        self.assert_exists
end

A possible excerpt from your page object for window 2

def assert_exists 
   wait = Selenium::WebDriver::Wait.new :timeout => my_timeout
   wait.until { text("Giris? Ekran?"}
end

def assert
        self.assert_exists
end

Hope this helps.

What I’m trying to say here is:

I don’t know any static value about the application that I’m going to test.
The test platform we are going to develop will have no knowledge on what can be the name or value of a text field in a window

So what I’m trying to achieve is understanding the 2 separate windows
In android driver class of appium there is a method called driver.currentActivity()
But there is no equivalent method in IOSDriver, what I need is exactly that method for IOS

Is there something like that which I may be missin

I don’t believe there is an appActivity in iOS. Maybe someone else can chime in, but looking through the docs such as these (http://appium.io/slate/en/master/?ruby#server-flags), it seems android specific.

You mention you don’t know the names and values of the separate windows. Would you happen to know anything about the positioning? (like window 2 has 3 table cells, for example. ) just a thought.

Good luck with things. Hopefully someone else can help you! I don’t know what else to recommend.

So you are saying on IOS platform there is no easy way to identify which screen I’m in.
So I should find a way to identify screen from its contents.
Such as getting hash key of all the items in that screen(textview,button,labels etc…) and then compare it each time I tap a button so when the hash key changes it means that I’ve changed the screen
Is your suggestion something smilar to that?

That’s essentially correct Tolga.
You may not need to get all the elements in each window to identify uniqueness but you need to get enough of the elements to make an assertion that you have indeed switched windows. Storing it as a hash is a good idea.

I’m curious when you know which screen you are in, what are you gonna do?
We have a system based on UI layout to identify exact screens.