Mirror your Android Phone on Mac/PC
Vysor is a Chrome add-on that allows you to mirror your Android phone on your Mac or PC when doing presentation through your mobile phone.
So far this is the easiest way as it does not require installation of any application whatsoever, plus it allows you to mirror multiple devices as long as it is connected to your machine.
- Launch your Chrome browser and go to Chrome webstore
2. Search for Vysor and click “Add to Chrome” button
3. Connect your Android phone to your Mac/PC via USB
4. Launch the Vysor via the Chrome webstore or Chrome App Launcher
5. Choose the device that you want to share
6. Now you can navigate through your mobile phone and project all the user actions in your desktop.
Cucumber: Passing Test Data as Table from Scenario
While we can pass test data as table from the feature file through Scenario Outline:
Scenario Outline: User updates user information Given I login to application And I go to user profile page And I enter "<gender>" into field of "gender_element"; And I enter "<age>" into field of "age_element"; And I enter "<location>" into field of "location_element"; Then I verify user updates are saved Examples: | gender | age | location | | Female | 20 | Singapore |
Here’s another option to pass your data in table format through your step definition.
Scenario: User updates user information Given I login to application And I go to user profile page When I update user information with options: | Gender | Female | | Age | 20 | | Location | Singapore | Then I verify user updates are saved
#Step Definitions File
#step definition to populate textfields Then /^I enter "(.*)" into field of "(.*)"$/ do |value, field| textfield(I18n.translate!(field)).click textfield(I18n.translate!(field)).send_keys value end #step definition that accepts test data from the feature file as table When /^I update user information(?: with options:)?$/ do |table| options = table.rows_hash step %Q[I enter "#{options['Gender']}" into field of "gender_element"] step %Q[I enter "#{options['Age']}" into field of "age_element"] step %Q[I enter "#{options['Location']}" into field of "location_element"] step %Q[I press button labelled "bt_address_suggestion_use_this"] #step definition that accepts test data from the feature file as table with default value When /^I update user information(?: with options:)?$/ do |table| default_value = { 'Age' = "18", 'Location' = "United States" } options = default_value.merge(table.rows_hash) step %Q[I enter "#{options['Gender']}" into field of "gender_element"] step %Q[I enter "#{options['Age']}" into field of "age_element"] step %Q[I enter "#{options['Location']}" into field of "location_element"] step %Q[I press button labelled "bt_address_suggestion_use_this"]
Cucumber: Using JSON Parser
JavaScript Object Notation(JSON) is a lightweight data-interchange format useful to generate and parse data
Sample Data:
{‘user’:{‘FirstName’:’User1′, ‘LastName’:’Sample’, ‘Gender’:’Female’, ‘BirthDate’:’01/01/1990′}}
Suppose we are to use the above user data, parse it into an hash and use the array hash as input to a sign up screen.
Here’s a snippet of how to use JSON in this particular scenario
require “json” my_data = "{'user':{'FirstName':'User', 'LastName':'Sample', 'Gender':'Female', 'BirthDate':'01/01/1990'}}" ##method to parse user data def getNewUserData @new_user = JSON.parse my_data { :firstName => new_user['user']['FirstName'], :lastName => new_user['user']['LastName'], :gender => new_user['user']['Gender'], :birthDate => new_user['user']['BirthDate'] } end ##method to populate the sign up screen def fillOutSignUpScreen step %Q[I enter "#{@new_user[:firstName]}" to the "signup.firstname"] step %Q[I enter "#{@new_user[:lastName]}" to the "signup.lastname"] step %Q[I enter "#{@new_user[:gender]}" to the "signup.gender"] step %Q[I enter "#{@new_user[:birthDate]}" to the "signup.birthdate"] end
For more functions and complete library you may refer to http://www.ruby-doc.org/stdlib-2.0/libdoc/json/rdoc/JSON.html
Ruby: Using URI and HTTPClient
HTTPClient provides API library for user to access web resource using HTTP
This would be helpful if you need to access a different web URL other than your base URL that you used in your automation and validate the content of the page.
Here’s a snippet of how to use HTTPClient in this particular scenario
require “httpclient” my_url = “http://CheckThisOut:8080” ##method to access my_url using URI def accessPage begin uri_parsed = URI.parse(my_url) client = HTTPClient.new() client.ssl_config.verify_mode = OpenSSL::SSL::VERIFY_NONE client.no_proxy = uri_parsed.host uri = my_url #invoke url to take the page content puts “Accessing: #{uri}” resp = client.get uri, :header => {’Accept’ =>‘application/json’} rescue puts(“Error encountered: #{$!.inspect}”) end end puts "response: status = #{resp.status}" puts "response: body = #{resp.body}" fail "bad response #{resp.status} #{resp.reason}" unless resp.status == HTTP::Status::OK page_content = resp.body return page_content end
For more functions and complete library you may refer to http://www.rubydoc.info/gems/httpclient/2.1.5.2/HTTPClient
Useful Git Commands
As our project migrated from SVN to GIT repository, I thought of writing a post of the usual git commands which I find helpful where I could easily refer to.
**Set up Local Repository
#clone a repository into a new directory locally
git clone <SSH key>
#checkout a branch or path to the working tree
git checkout <branch name>
**Working with Branches
#display all the available branches in your local, highlighting the active branch
git branch
#download all/new branches
git fetch
#switch working branch
git checkout <branch name>
#create new branch locally
git checkout -b <branch name>
#push newly created branch to remote
git push -u origin <branch name>
**Committing Local Changes to remote
#show staged files for commit, not staged files for commit and untracked files.
git status
#include what will be committed, stage the changes
git add <file>
#discard changes
git checkout — <file>
#to add message for commit
git commit -m “message here”
#take latest commits on the mentioned branch
git pull origin <branch name>
#push local changes to the remote
git push origin <branch name>
Introduction to Cucumber
More than a testing tool, Cucumber is a collaboration tool.
It is designed to accommodate both the technical(developers, automation testers) and non-technical(stakeholders, product owners) members of the software development team.
Cucumber supports behavior-driven development(BDD). In BDD, users(business analysts, product owners) first write scenarios or acceptance tests that describes the behavior of the system from the customer’s perspective, for review and sign-off by the product owners before developers write their codes.
When you run your test, Cucumber reads through user-readable files called features, parse it to scenarios which contains set of steps that are then matched to a step definitions of Ruby code using a regular expression.
Feature files could be deceiving. It may look simple and plain in the outside. But complex in the inside, within step definition or the ruby files which controls the flow of actions and where all the magic happens.
In order for Cucumber to understand the feature files, it uses a basic syntax called Gherkin. Gherkin makes use of the following keywords for documentation and readability — Feature, Background, Scenario, Given, When, Then, And, But, *, Scenario Outline and Examples.
To dive more information about Cucumber, I would recommend you read The Cucumber Book which have valuable information you would need in learning this new technology.
In preparation to your Cucumber testing experience, will be needing to setup the following in your local machine.
1. Java installation – JRE will do, mine is Java(TM) SE Runtime Environment 1.6
2. Ruby installation – visit their Downloads page. I have Jruby 1.6.7.2 installed in my box.
Don’t forget to define Java and Ruby Path in your system’s environment variables as well.
3. RubyGems installation – use “gem install <name of gem>” command. Here are some of the basic, helpful gems:
– Cucumber
– Capybara
– Rspec
If you’re all setup, feel free to jump to the next post – Automated Testing with Cucumber + Capybara
Reference: The Cucumber Book by Matt Wynne and Aslak Hellesoy
Recent Comments