Pre-Defined Steps List

Predefined steps are cucumber ready steps that will ship with Shamisen. The steps are ready so you can start writing automation in no time.

The document consist of the following:

  • Information about the steps
  • Common steps for iOS and Android
  • Android only steps
  • iOS only steps
  • Steps available inside of the Web View of hybrid apps
  • Tips for custom predefined steps

 

How these steps were written:

All steps will contain of the step part and input part. input for strings is in quotes but for element types and digits it's not in quotes.

Most of the steps are the same for all of the element types. to get a list of element types scroll to
iOS or Android sections below. You can modify most of the steps by adding : not, or the element type to make the step more specific. Example:
Sample step
Then I should see "Hello" - step will pass if any element on the page matches the exact text 'Hello'
We could add the not to the step
Then I should not see "Hello" - step will pass if none of the element on the page matches the text 'Hello'
If we want to specify the element type of the we are looking for, we will have to find it in the list of available element and add it to the end of the step:
Then I should not see "Hello" button  - now this will pass only if a button does not exists with the text "Hello"
We can also do:
Then I should not see "Hello" check box

What I mean by "Element Name"? - for Android it will be content description, or placeholder of textfield.

for iOS it will be Accessibility Label. if element type provided, Name will also try to match text and placeholder.

 

Android and iOS steps 

 

 Input
tapping element methods for iOS (Will scroll only for ios to an element if it's not displayed)

tap checkbox | radio button | image button | button | toggle button
you can tap any element by name :

  • Then I tap "Choice One"

optional you can provide the type of the element:

  • Then I tap "Choice One" <element type>
  • Then I tap "Choice One" radio button
  • Then I tap "Cancel" button

click element by the type and number

Note: clicking buttons by number may not be consistent on iOS7 and iOS8, please try to avoid this.

  • Then I tap image button #this will click the first image button
  • Then I tap image button number 2 #this will click image button using the number


Touch coordinates

  • Then I touch on screen 100 from the left and 250 from the top

Entering text:  For Android it's recommended to clear the field before entering in it, if something is already in the field

  • Then I fill in "accessibility label, name, or content description" with "text to write"
  • Then I enter "12" into "name of element"
  • Then I type "Hello Automation" into input field number 2

iOS placeholder friendly step:

  • Then I type "text to write" into the "Placeholder text" input field

 

type in element using the element name, placeholder(hint text), or text inside.

  • Then I type "hello" in "hint text"
  • Then I type "hello" in field with id "someID"


clear text using name/text of the text field, note: not a recommended strategy for android emulator, if using Android emulator, clear text fields using text field number.

  • Then I clear "hello"

clear text using a number of the text field

  • Then I clear input field number 1

clear text using a id of the text field

  • Then I clear input field with id "someID"


 Validations

Validation work a little different on iOS and Android. on iOS if element exists somewhere but may not be visible on the screen, the element is considered present. For 
Android, if element is not displayed on the screen it is considered to be missing, even if it's somewhere we can scroll to.


Check if element with name,  is present and actually visible to the user using exact value

  • Then I should see "Kittens"

Check if specific exact text is present as text

  • Then I see the text "Hello user"


Check for partial text on the page, choose weather to check the text only or the whole page, makes sure element is actually visible to the user

  • Then I should see text containing "Controls"
  • Then I should see page containing "Controls"
  • Then I should see text starting with "prefix"
  • Then I should see text ending with "suffix"

Check if missing the same as above

  • Then I should not see text "S"

check the number of elements is correct or no such element is present

  • Then I should see 5 buttons
  • Then I should not see buttons

Check if specific element with exact text/name is present
Note: please do not use this method for text, but use the one above instead.

  • Then I should see "Checkbox 1" checkbox

Check if element is not present on the page for iOS, or not visible on the screen for Android

  • Then I should not see "Checkbox 5" checkbox

 

check that an element is checked or set by type and number, this works for radio button, checkbox, and toggle button

  • Then radio button is set # will check first radio button
  • Then radio button number 1 is set
  • Then checkbox number 1 is set

check not set

  • Then "RadioButton 2" is not set
  • Then "RadioButton 2" radio button is not set
  • Then "RadioButton 2" <element name> is not set
  • Then the radio button number 2 is not set

 

 Using IDs:
Enters the specified text into the input field with the specified id.

  • Then I type text "kittens" into field with id "/android/someid"
  • Then I clear input field with id "someID"

Taps the anything with the give id

  • Then I press using id "/someid/"
  • Then I press view with id "/someid/"

Validation check present

  • Then I wait to see view with id "some id"

check that missing

  • Then I wait for view with id "some id"

 


Waiting

  • Then I wait for 1.1 second

Waits for a anything with the specified id to appear.

  • Then I wait to see view with id "someid/"

Will wait until there are no more progress bars or activity loaders.

  • Then I wait for progress bar
  • Then I wait for activity   # activity is only for iOS, it is a spinning circle loading icon


Waiting for an element to disappear

  • Then I wait for "Hello"
  • Then I wait for "label"
  • Then I wait for "text" text
  • Then I wait for "text or label" button
  • Then I wait for "text or label" radio button
  • Then I wait for partial text "text"

Type only

  • Then I wait for progress bar

Optional you can add time all of the waits above

  • Then I up to 5 seconds for "Hello"


Waiting for an element to appear, the same as above

  • Then I wait to see Hello"
  • Then I wait to see "text or label"
  • Then I wait to see "Hello" text
  • Then I wait to see "Hello" button
  • Then I wait to see "hello" radio button
  • Then I wait to see partial text "hello" 

waiting using element type only

  • Then I wait to see progress bar
  • Then I wait to see 2 input fields

Optional you can add time all of the waits above

  • Then I up to 5 seconds to see "Hello"

Waits for the specified element to appear, with a custom timeout

  • Then I wait up to 1 seconds to see "text"
  • Then I wait upto 5 seconds to see "hello"
  • Then I wait up to 5 seconds to see "text or label" button


 Gestures

Note: Gestures for iOS simulators are not yet working. work around or will be available soon


Swipes, 

  • Then I swipe left
  • Then I swipe right
  • Then I swipe up
  • Then I swipe down


Scroll and find a specific element by name/text. (up/down direction is optional)

  • Then I scroll to "FarAwayItem"
  • Then I scroll down to "Toolbars"

Scroll and find a specific element by id

  • Then I scroll to id "Action"
  • Then I scroll to id "Action" on the table number 1
  • Then I scroll to id "com.grove.android:id/booknow" on the view with id "com.grove.android:id/slotlist"

Scroll to element with name inside of the element with class and index (up/down/left/right direction is optional) 

  • Then I scroll to "Item 4" on the table number 2
  • Then I scroll down to "Toolbars" on the table number 1
  • Then I scroll up to id "Action" on the table number 1
  • Then I scroll right to "Toolbars" on the table number 1
  • Then I scroll right to id "Toolbars" on the table number 1
 

 Navigation

  • Then I go back
  • Then I go back if I see "Hello"
  • Then I go back if I see "Hello" button
  • Then I go back if I don't see "Hello"
  • Then I go back if I don't see "Hello" button

Other

Manage implicit wait for custom steps, default is 30 seconds

  • Then I set implicit wait to be 4 seconds

Set the time of explicit wait for the custom wait, will also make sure that it's not longer than the implicit wait

  • Then I set wait time to be 5 seconds

Restart the app

  • Then I restart the app

Rotate:

  • Then I rotate to landscape
  • Then I rotate to portrait

Screenshot:

  • Then I take a screenshot

Hide the keyboard. more options available for iOS, see iOS section

  • Then I hide keyboard

Debug

  • Then let me debug

lock, unlock

  • Then I lock the screen
  • Then I lock the screen for 10 seconds
  • Then I unlock the screen

Webview elements are available as default elements if they are basic elements. if you are loading a web page with web specific elements, you will have to switch to the webview and use webview methods to access them.

Switching to the Webview Note: for the iOS device, you will have to have ios-webkit-debugger-proxy setup  if running locally. 

  • Then I switch to the web view
  • Then I switch to the native view

You can build your steps for the WebView using @browser variable and Watir commands. For the list of available steps see the WebView section below.

#### Android only steps ######

Available Android elements:

button : 'android.widget.Button'
text :'android.widget.TextView'
checkbox 'android.widget.CheckBox'
toggle button 'android.widget.ToggleButton'
spinner, dropdown 'android.widget.Spinner'
radio group 'android.widget.RadioGroup'
radio button 'android.widget.RadioButton'
textbox, inputfield, textfield 'android.widget.EditText'
imagebutton 'android.widget.ImageButton'
scrollview 'android.widget.ScrollView'
datepicker 'android.widget.DatePicker'
timepicker 'android.widget.TimePicker'
numberpicker 'android.widget.NumberPicker'
image,imageview 'android.widget.ImageView'
progressbar 'android.widget.ProgressBar'
switch 'android.widget.Switch'
seekbar 'android.widget.SeekBar'
tab 'android.widget.TabWidget'
linearlayout : 'android.widget.LinearLayout'


 Input

Select from a drop-down or spinner

  • Then I select "Earth" from "Planets"
  • Then I select "Earth" from a dropdown number (\d+)

Select from a seek bar the value between 0 and 1, 0 = 0% 1 - 100%

  • Then I set seek bar number 1 to 0.8


 Data and Time ppickers

Set the date and time using using first picker or with the number of picker:

  • Then I set the date to "03-21-2000" on the DatePicker
  • Then I set the date to "03-21-2000" on the DatePicker number 1
  • Then I set the time to 6:15 pm on TimePicker
  • Then I set the time to 5:22 am on the TimePicker number 2

Set the date and time using the name of the picker element:

  • Then I set the "report starting" date to "01-01-2015"
  • Then I set the "Meeting ends at" time to 12:30 am

 Network connection

Change and verify network connections:

  • Then I go to Airplane mode
  • Then I go to Wifi only mode
  • Then I go to Data mode
  • Then I go to wifi and data mode
  • Then I should be in Airplane mode
  • Then I should be in Wifi only mode
  • Then I should be in Data mode
  • Then I should be in wifi and data mode

Working with Hybrid apps and web elements
API 19 or higher os 4.4 or higher
To enable webview elements so that they are accessible as normal elements use this command. It will click into the webview.
In order to enable webview elements we have to tap somewhere on the webview.

  • Then I enable Web View elements

If you have a web page or elements that you cannot access as normal elements, switch to the webview and use WebView methods. You can write your own methods with Watir using @browser variable 


 Other


Open package: this will work only on a device. not working on emulator yet and packages may be different on different APIs

  • Then I open package "com.android.contacts" activity ".Activity"

#Waits for a particular screen (Android Activity) to appear with a timeout.

  • Then I wait up to 5 seconds for the ".HelloActivity" screen to appear
  • Then I wait for the ".hello" screen to appear



long press

  • Then I long press "Save"
  • Then I long press "menu" and select "copy"

notifications

  • Then I open notifications

 


#### iOS only steps ######
Note in ios, there are usually 2 more buttons in addition to all visible buttons, it's a back button.

Available iOS elements:

button, image button: 'UIAButton'
text: 'UIAStaticText'
slider: 'UIASlider'
textbox, input field, text field: 'UIATextField'
secure textbox, secure input, secure inputfield, secure textfield, password field, password: 'UIASecureTextField'
number picker, picker: 'UIAPicker'
picker wheel: 'UIAPickerWheel'
image, image view: 'UIAImage'
switch: 'UIASwitch'
control, segmented control: 'UIASegmentedControl'
## NOTE: Element will get all elements on the page
element : 'UIAElement'
status bar, status: 'UIAStatusBar'
search bar,search : 'UIASearchBar'
activity, activity bar: 'UIAActivityIndicator'
progress bar, progress indicator: 'UIAProgressIndicator'
table, table view: 'UIATableView'
list item: 'UIATableCell'
navitagion bar: 'UIANavigationBar'
link: 'UIALink'


Click element by partial text and the element element type

  • Then I tap text using partial text "Switch"
  • Then I tap a button using partial text "submi"

Sliders:

  • Then I set "0.5" in slider number 1
  • Then I set "0" in slider number 1
  • Then I set "1" in slider number 1
  • Then I set "0.5" in "Volume"


Text by table (fields are by "placeholder")

  • Then I fill in text fields as follows:

| field | text | type
| Last Name | Krukow | text
| Email | a@b.c | text
| Username | krukow | text
| Password | 123 | password
| Confirm | 123 | password

Working with alerts examples

  • Then I accept the alert
  • Then I dismiss the alert
  • Then I tap 'OK' Button   (is also ok for alerts)
  • Then the alert title should be "A Short Title Is Best"
  • Then the alert text should be "A message should be a short, complete sentence."
  • Then the alert text should contain "message"
  • Then the alert title should contain "Title"

List items (UITableViewCells) by number. this should scroll to to the item it's not displayed.
tap item from the list

  • Then I touch list item number 1

Enter a password into a password field

  • Then I enter "some password" into password field number 1

Built-in keyboard. Touching button to hide keyboard

  • Then I touch Done on the keyboard
  • Then I touch Search on the keyboard
  • Then I touch Go on the keyboard

Web View iOS webview elements can be use as normal elements without switching to webveiw.
Switch to webveiw for complex interactions and there you can find elements by css or xpath with $driver, or you can use Watir with @browser variable.

 

Web View predefined steps iOS and Android

  • I go to the url "url"
  • I click the button "text"
  • I click the element with "attribute" "value"
  • I should see "text" on the webview
  • I should not see "text" on the webview
  • I fill in "field Label" with "text to fill" on the webview
  • I should see "([^"]*)" but proceed if not present
  • I click the "element type" with "attribute" "value"
  • I enter "text" in text field with "attribute" "value"
  • I select the value "value" in select list with "attribute" "value"
  • I select the option "option" in select list with "attribute" "value"
  • I check that the "element" with "attribute" "value" contains "value"
  • I wait until "Element" with "attribute" "value" is ready

 

 More examples here

 

Building custom predefined steps

When writing you custom predefined steps,

  • Make sure to pick Appium methods that will work on all mobile OS that you need to test because some new Appium methods do not work on every old OS version. (building tests on the lowest OS version solves this.)
  • Build your test on a device with the smallest screen size  that you need to test to ensure elements are accessible and scrolling performed as needed.
  • Wrap steps around the selenium wait block because sometimes elements become invalid seconds after being located, and some other appium errors may occur. that can fail your test. @wait variable is available which is a custom wait we have in predefined steps. Example: @wait.until {true} (This also recommended by Appium)
  • Consider available helper methods that are available in predefined steps files before writing your own. What you need may already be there.
Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.
Powered by Zendesk