-
Notifications
You must be signed in to change notification settings - Fork 0
Cucumber and Ruby keywords and functions
- Cucumber folder structure
- .feature file structure
- Cucumber keywords
- Cucumber functionalities
- Ruby and Appium methods
- Functionalities in Ruby
- Appium commands
- Debugging
- Terminal commands
- UI Automator Viewer
folder_name
features - required folder
area.feature
area2.feature
step_definition - required folder
area_step.rb
area2_step.rb
support
env.rb - file in which we set parameters for testing
hooks.rb - file in which we create hooks Feature: Description
Background: Steps to be executed in every Scenario in this feature file
Scenario: Description
# Steps with keywords --> Steps are reusable accross feature files
Given step
When step
And step
Then step
But stepCucumber keywords are Given, When, Then, And, But. They are userd to make logical sense between steps. We can use any prefix we wan and the step will work because cucumber does not add prefix as part of step.
-
Set parameter in feature file
Given Description "parameter"
-
Make Scenario Outline when you need to execute multiple steps with many values
Scenario Outline: #Steps Given When I type "<value1_name>" Then I should see "<value2_name>" And See also "<value3_name>" Examples: |value1_name|value2_name|value3_name| |val1 |val2 |val3 | |val1 |val2 |val3 |
-
@Tags Are used for grouping tests in Cucumber
@name Scenario or Step or Feature
-
Hooks are used to execute anything we need to do before or after Test Scenario. Two hooks cucumber has are Before and After
Before do # anything that needs to be done before Test Scenario # launch Appium for example end After do |scenario| # anything that needs to be done after Test Scenario # kill Appium for example # Send screenshots of device if test fails for example end After Configuration do #what to do after every scenario end
-
Profiles are placed in same level as features folder. Profiles file is : cucumber.yml.
<!-- Creates profile name and mames report in report.html file and reports to console --> name: -t @tag --format html --out report.html --format pretty
-
puts - command that prints message
puts("message")
-
|arg| - local variable that lives between do and end
|var| puts(var)
-
find_element(id: "id") - find element by resource id
-
find_element(accessibility_id: "content desc") - used when we target element with content description
-
find_elements(id: "id") - find multiple elements by resource id
-
find_elements(accessibility_id: "content desc") - find multiple elements by resource id
-
find_elements(criteria)[index] - finds element that is on INDEX index inside array
-
find_element(id: "id").find_element(xpath: "//class[@text='']") - find element inside container by resourcing its class and then text inside that specific element
-
text("text") - used when we need to find element by text
-
.click - for click event in Appium
-
.send_keys(value) - when we want to write inside element
-
.text - gets text from element
-
fail("Message") - method that executes when test failed. Inside brackets goes optional message
-
.split("criteia") - split any array by any criteria
-
.each - iterate through array of data
-
.enabled? - returns boolean true if state is enabled and false if its state is disabled
-
.failed? - return boolean true if test failed and false if test passed
-
.tap - click on screen
-
.swipe - scroll on screen
-
.times{} - repeat some code number of times
-
.exists{what} - used to check if there is that element on page
-
.get_source - return all values of that page in XML
-
Time.now(strftime("%d-%m-%Y_%H.%M.%S")) - Time function formatting
-
File - Class for File manipulation
-
.to_i - transforms string to integer(for indexes --> .to_i-1)
-
biniding pry - calls pry and pauses test execution and gives control to us
-
Taking parameter as part of step
Then('condition {string} or "([^"]*)"') do |arg| puts("message" + arg) end
-
Taking parameter as part of step ex 1st, 2nd, 3rd
Then('condition (\d+)(?:st|rd|th)?') do |arg| puts("message" + arg) end
-
Set key values that can be accepted
Given(Description (option1|option2|option3)) do |state| end
-
if elsif statement
if state == "option1" do this elsif state == "option2" do this end
-
fail function in multiple lines
if Condition != expected fail("Message") end
-
fail function one line
fail("Message if failed") if Condition != expected
-
Pass variable inside string with #{var}
Then('condition {string} or "([^"]*)"') do |arg| puts("message #{string}") end
-
Arrays [] are data type in ruby that has indexes. Indexing starts at 0.
-
each loop for going through array of data
array.each do |var| end
-
For repeating Ruby code for number X of times we use .times
X.times{code}
-
Loop through data until some condition isn't met
until condition do # what needs to be done every time end
-
Functions are made so one piece of code could be executed multiple times. We make functions inside env.rb file.
def functionName(parameters) # what needs to be executed multiple times end
1.When we need to click on element by its coordinates x and y Z of times we use TouchAction, .tap and .perform event
Appium::TouchAction.new.tap(x:X.xx, y:Y.yy, count: Z).perform-
When we need to scroll on page with Appium we use TouchAction, .swipe and .perform for some duration of time
Appium::TouchAction.new.swipe(start_x:X.xx, start_y:Y.yy, end_x:X.xx, end_y:Y.yy, duration:X ms).perform
Pry is tool that can be called if we want to pause our test execution and take over control over test at any time we want.
- cucumber - executes every test scenario in every .feature file
- cucumber -t @name - executes scenario or feature file with @name tag
- cucumber --dry-run - executes scenarios without Ruby code, checks for step definitions
- cucumber -t @tag1, @tag2 - executes every scenario that either has @tag1 or @tag2
- cucumber -t @tag1 -t @tag2 - executes every scenario that has both @tag1 and @tag2
- cucucmber -p profile-name -executes test scenario with this profile name
- adb device - which device is connected to computer
- uiautomatorviewer - starts automator viewer
- irb - starts ruby console
- Takes screenshot of device. On the right side are elements and their properties. If we don't have any resource_id we can target element by content description. Or in edge cases by text.
Written by Ninna94