How take a property inside an element in calabash-ios and calabash-android

Hello mate !

 

I am writing about “How take a property inside an element in calabash-ios”, look the examples:
 

IOS

– This query is taking the property :TextContent for the element in a web page.

 

 query("WebView css:'#testid'")[1]["textContent"]

 
– This query is taking the property :TextContent for the element.

 

 query("Label index:1",:textContent)
 

– Look when you want a sub-property:

 

[

[0] {

     "id" => "login_button",

     "enabled" => true,

     "contentDescription" => nil,

     "class" => "android.widget.Button",

     "text" => "Login",

     "rect" => {

     "center_y" => 545.0,

     "center_x" => 639.5,

     "height" => 64,

     "y" => 513,

     "width" => 195,

     "x" => 542

               },

     }

]

– This query is taking the property inside the group of properties.

 

 query("Label").first["rect"]["y"]

 

 
Android

– This query is taking the property :TextContent for the element in a web page.

 query("WebView css:'#testid'",:textContent)
 
– This query is taking the property :TextContent for the element.

 

 query("Label index:1",:textContent)
 

– Look when you want a sub-property:

 

 [

[0] {

     "id" => "login_button",

     "enabled" => true,

     "contentDescription" => nil,

     "class" => "android.widget.Button",

     "text" => "Login",

     "rect" => {

     "center_y" => 545.0,

     "center_x" => 639.5,

     "height" => 64,

     "y" => 513,

     "width" => 195,

     "x" => 542

               },

     }

]

 

– This query is taking the property inside the group of properties.

 

 query("Label index:1",:rect,:y)
 

If you need help or have some comment to do, please write below 🙂
 
Thank you !

 

7 thoughts on “How take a property inside an element in calabash-ios and calabash-android

  1. Hi Rafaela, I have set up a Calabash iOS framework for a Native product and I found really useful some of your tips and info. Thanks for that! Now I need to run my tests for iphone and iPad as well, and because our product interfaz has many differences I need to get the device name from my Ruby code, So I will have different behavior depending on that. Do you know how to ask Calabash that info?

    Thanks a lot!
    Rodrigo

    1. Hi Rodrigo, Thank you for sending me this message. It is a good question, I have never used before, but I tried this and worked 🙂

      You can send this command through your terminal and try as well.
      system_profiler -detailLevel basic SPUSBDataType

      OR

      diskutil list

      After this, you will receive a lot of infos about the devices connected, in the middle of this list you can find the name of the device, probably you will have treat the strings to get the name.

      They are system commands, so in your code of ruby/calabash you will need use the %x()

      Hope this helps you !

      Bye 🙂

      1. Hi Rafaela, thanks for your quick answer. I think my description of the problem was not the best. I am running my tests in iPhone and iPad simulators (not in physical devices), So my code should have behaviors for both simulators. What I need to do from my code is something like this: If (device==iPhone) do ….. else if (device== iPad) do …. . But I did not find the way to get the simulator who is running. Any idea?
        Thanks again!

      2. Hi Rodrigo,
        Ah ok 🙂 So, if you are using simulators device, you can figure out this in the command that you are sending in the calabash. Because when you send the command, you need to send the parameter device, ipad or iphone… So you can create a script (script.sh) and export the variables to set your environment in your starter, and after you can just verify if is ipad or iphone. ENV['DEVICE'].include? "iphone"

        Like this one:

        #!/bin/bash
        export DEVICE='iPad Retina'
        export APP_BRANCH=develop
        export BUNDLE_ID="path"

        CUCUMBER_COMMAND="BUNDLE_ID=$BUNDLE_ID DEVICE=$DEVICE APP_BRANCH=$APP_BRANCH cucumber features/ -t @ios -f html"

        echo $CUCUMBER_COMMAND
        eval $CUCUMBER_COMMAND

        Let me know if this helps you.

  2. Hi Rafaela, Thanks for your response. I already found an easy way:
    From ruby code:

    device = server_version[‘simulator_device’]

    then you can ask:

    if (device == “iPhone”)
    ..
    if (device == “iPad”)
    ..

    Good to contact you 🙂
    Keep in touch

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.