Home > Programming, QA, Test and Automation Stuffs, Uncategorized > How take a property inside an element in calabash-ios and calabash-android

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 !

 

Advertisements
  1. Rodrigo
    February 10, 2015 at 7:30 pm

    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

    • February 11, 2015 at 9:50 am

      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 🙂

      • Rodrigo
        February 11, 2015 at 12:23 pm

        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!

      • February 11, 2015 at 12:36 pm

        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. Rodrigo
    February 11, 2015 at 1:55 pm

    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

    • February 11, 2015 at 1:59 pm

      Hi Rodrigo,

      Great ! I will take a note this ! Thank you 🙂

  1. September 30, 2014 at 10:50 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: