Examples:
Category: QA
List of useful commands
1. You can see what is available for instrumentation
adb shell pm list instrumentation
2. List packages:
adb shell pm list packages
3. To get reports with the run:
calabash-android run mytest.apk –format html –out reports.html
4.To see logcat:
adb logcat
Fonts:
7 Possible issues and fixes – Calabash android
-
1. To get rid of warning about ansicolor (windows):
- open cmd and navigate to the unzipped folder
- Navigate to x64 (if you have a 64 bit machine) otherwise navigate to x86
- Execute ‘ansicon.exe -i’ to install and add ansicon to your Windows
- Run your cucumber test and you should
- get the colored output result on Windows
-
2. Warning about gem json ~>1.7.7 (Windows):
- If the above, doesn’t fix it,
- uninstall Ruby.
- Install Ruby 1.9.x again
- Make sure you also install the corresponding Devkit
- gem install json -v 1.7.7
- bundle update json
-
3. Jarsigner: unable to sign jar
- Rename the .apk file to .zip
- Unpack the .zip file and remove the META-INF folder
- Zip the folder again and rename it to .apk (zip -r <xxx.apk> *)
- Sign the apk:
- Copy your “Calabash” folder having “feature” file.
-
4. No MD5 fingerprint found: (RuntimeError)
- Paste it into your android workspace having gen, res, src folder. eg., ~/.android
- Now, Test server will create inside your calabash folder.
- Navigate to new path and again run apk file.
-
5. If the AndroidManifest.xml is missing:
- To create AndroidManifest.xml file: where should this be?
- calabash-android extract-manifest Downloads\mytest.apk
-
6. If adb device not showing up in “adb devices”:
- adb kill-server adb start-server adb devices
-
7.Cannot load such file rspec/expectations:
- Make sure you add the foll. line in your Gemfile
- gem ‘rspec’
Using Excel Sheet as BD – Selenium – (Read)
Hello guys !
Today I will post about how to use Excel Sheet as a database with Selenium.
– First create your BD as this example:
Sheet 1 – Consumers
Sheet 2 – Products: Now, you can create other sheets with information about the products or something that you want.
– Always save as .xls
– Create a class for open the Data base (Sheet) – remember download the lib jxl > Link with download of all versions
import java.io.File;
import java.io.IOException;
import jxl.Sheet;
import jxl.Workbook;
import jxl.WorkbookSettings;
import jxl.read.biff.BiffException;
public class OpenDataBase {
Sheet sheet;
Workbook bddatabase;
public Sheet Open() throws BiffException, IOException, Exception {
WorkbookSettings ws = new WorkbookSettings();
ws.setEncoding("Cp1252");
//Change for the folder of the .xls
bddatabase = Workbook.getWorkbook(new File("BD//BDFile.xls"), ws);
//Change the name of your sheet
sheet = bddatabase.getSheet("tbclient");
return sheet;
}
public void Close(Workbook bddatabase) throws BiffException, IOException, Exception {
bddatabase.close();
}
}
– Create a class to list all the informations inside of the sheet (table):
import org.openqa.selenium.WebDriver;
import java.io.IOException;
import jxl.Cell;
import jxl.read.biff.BiffException;
import org.openqa.selenium.By;
public void TestCase() throws BiffException, IOException, Exception {
// open Data base
opendatabase.Open();
// bring the cells from BD
for (int i = 1; i < opendatabase.sheet.getRows(); i++) {
Cell id_client = opendatabase.sheet.getCell(0, i);
Cell casenameBD = opendatabase.sheet.getCell(1, i);
Cell email = opendatabase.sheet.getCell(2, i);
Cell name = opendatabase.sheet.getCell(3, i);
Cell surname = opendatabase.sheet.getCell(4, i);
Cell date_born = opendatabase.sheet.getCell(5, i);
Cell gender = opendatabase.sheet.getCell(6, i);
Cell discount = opendatabase.sheet.getCell(7, i);
Cell pass = opendatabase.sheet.getCell(8, i);
driver.findElement(By.id("field")).sendKeys(id_client.getContents());
driver.findElement(By.id("field")).sendKeys(casenameBD.getContents());
driver.findElement(By.id("field")).sendKeys(email.getContents());
driver.findElement(By.id("field")).sendKeys(name.getContents());
driver.findElement(By.id("field")).sendKeys(surname.getContents());
driver.findElement(By.id("field")).sendKeys(date_born.getContents());
driver.findElement(By.id("field")).sendKeys(gender.getContents());
driver.findElement(By.id("field")).sendKeys(discount.getContents());
driver.findElement(By.id("field")).sendKeys(pass.getContents());
}
}
If you have any questions, just write below !
Thank you 🙂
Using Dynamic data from a CSV file with JMeter
Hi guys !
Today I will post this tutorial of Jmeter about how use dynamic data from a CSV (Excel or other) file, because a follower asked for some Jmeter’s tutorial.
I did the same here and didn’t have any problem. So, if you have any question/suggestion, just write below !
Thank you 🙂
Testing Ajax application with Selenium
Ajax, an acronym for Asynchronous JavaScript and XML, is a web development technique for creating interactive and more responsive web applications. The Ajax application works more like a desktop application, meaning that user’s request will not cause an entire page to reload every time, the web browser makes an asynchronous call to the web server to obtain the required data and update only specific parts of the current web page. As result the user gets more interactive, speedy, and usable web pages, but testing AJAX with Selenium will be challenging.
Selenium’s ‘assert’ and ‘verify’ commands might occasionally fail thanks to the asynchronous nature of the Ajax. It may happened that the result doesn’t come back from the server immediately and while ‘assert’ and ‘verify’ commands already trying to verify a new value immediately.
Not experienced testers would recommend to add a ‘pause’ command for a few seconds before the verification. The ‘pause’ suggestion may work in certain cases, because Ajax call may be not completed after pausing for a specific time due to slow machines or network. If the tester set the long pause time it will make the test unacceptably slow and drastically increase testing time.
In this type of tests you should use waitForCondition function in Selenium for Ajax testing. The waitForCondition command evaluates a JavaScript snippet repeatedly, until the snippet returns true. As soon as Selenium detects that the condition returns true, it will stop waiting and Ajax testing will resume.
It is important to note that the selenium in selenium.waitForCondition is a Java object in your test code and the selenium in selenium.browserbot is a javascript object running in the web browser.
Examples:
selenium.waitForCondition("selenium.browserbot.getCurrentWindow().loading == false", "20000");
> Condition
> Timeout miliseconds
If you are using AJAX you might find there is an AJAX object on your application. In it will be a activeRequestCount. When the AJAX.activeRequestCount goes to zero, all the AJAX calls are done. So you can wait for an AJAX call to complete with:
selenium.waitForCondition("selenium.browserbot.getCurrentWindow().AJAX.activeRequestCount == 0", "30000");
Thank you 🙂
Fonts: http://www.seleniumguide.com/p/testing-ajax-with-selenium.html
http://darrellgrainger.blogspot.co.uk/2010/03/selenium-rc-java-waitforcondition.html
How take a property inside an element in calabash-ios and calabash-android
query("WebView css:'#testid'")[1]["textContent"]
query("Label index:1",:textContent)
[
[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
},
}
]
query("Label").first["rect"]["y"]
query("WebView css:'#testid'",:textContent)
query("Label index:1",:textContent)
[
[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
},
}
]
query("Label index:1",:rect,:y)
Swipe and Drag – Calabash iOS and Android
def swipe_page_to_left performAction('swipe', 'left') end
def swipe_page_to_right
performAction('swipe', 'right')
end
def scroll_to_right
performAction('drag', 90, 0, 50, 50, 50)
end
def scroll_to_left
performAction('drag', 0, 90, 50, 50, 50)
end
def scroll_to_up performAction('drag', 88, 80, 90, 90, 5) end
def scroll_to_down
performAction('drag', 70, 10, 80, 0, 3)
end
swipe(:up)
Simulate turn off wifi/connection on devices and simulators
Simulate disable network
Device/Simulator – Android:
%x(adb shell am start -a android.intent.action.MAIN -n com.android.settings/.wifi.WifiSettings)
(For selecting Next element on the screen)
%x(adb shell input keyevent 20)
(For selecting previous element on the screen)
%x(adb shell input keyevent 19)
(For clicking on the selected element)
%x(adb shell input keyevent 23)
So you have to use select next or select previous key events and then you the click event to toggel the wifi.
Simulator – Android:
def disable_network
%x(adb shell svc wifi disable)
end
def enable_network
%x(adb shell svc wifi enable)
end
Device/Simulator – IOS:
First, setup a WiFi router that you can use for testing.
You can turn on Airplane mode on the phone, then turn WiFi back on. This will prevent the 3G connection from providing data access.
Launch your application. Now you can simply disconnect your WiFi router to simulate a loss of connectivity.
So the only option available is switch on airplane mode on phone and connect it to the wifi. Once you want to disconnect wifi switch off the wifi router itself. You can use any laptop to create the testing wifi access point.
Summarizing you have to connect your device in a wifi connection that you can control with System commands, the problem is that you will lost the connection of your machine.
def disable_network
%x[ifconfig Wi-Fi down]
%x[ifconfig en4 down]
end
def enable_network
%x[ifconfig Wi-Fi up]
%x[ifconfig en4 up]
end
But if you have an android phone you can easily create a portable wifi Hotspot which can be controlled using adb commands.
15 Expert Tips for Using Cucumber
Hey guys, I found these excellent tips to who are working with Cucumber and Calabash. Try follow each one to get more performance and use the best practices always 🙂
1. Feature Files Should Actually be Features, Not Entire Portions of an App
One feature per well named file, please, and keep the features focused.
2. Avoid Inconsistencies with Domain Language
You’ll get the most benefit out of using Cucumber when your customers are involved. To that end, make sure you use their domain language when you write stories. The best course of action is to have them involved in writing the stories.
3. Organize Your Features and Scenarios with the Same Thought You Give to Organizing Your Code
One useful way to organize things is by how fast they run. Use 2-3 levels of granularity for this:
- Fast: scenarios that run very fast, e.g. under 1/10 of a second
- Slow: scenarios that are slower but not painfully so, maybe under one second each
- Glacial: scenarios that take a really long time to run
You can do this separation several different ways (and even some combination):
- Put them in separate features
- Put them in separate subdirectories
- Tag them
4. Use Tags
Tags are a great way to organize your features and scenarios in non functional ways. You could use @small, @medium and @large, or maybe @hare, @tortoise, and @sloth. Using tags let you keep a feature’s scenarios together structurally, but run them separately. It also makes it easy to move features/scenarios between groups, and to have a given feature’s scenarios split between groups.
The advantage of separating them this way is that you can selectively run scenarios at different times and/or frequencies, i.e. run faster scenarios more often, or run really big/slow scenarios overnight on a schedule.
Tagging has uses beyond separating scenarios into groups based on how fast they are:
- When they should be run: on @checkin, @hourly, @daily
- What external dependencies they have: @local, @database, @network
- Level: @functional, @system, @smoke
- Etc.
5. Use Rake Tasks to Run Features
This provides a consistent environment for running features: this way each run uses the same set of options and parameters. This goes a long way toward maintaining deterministic results.
Another benefit is that this makes for easy integration with continuous integration tools. There is a single point of entry into the spec run, with all options/parameters encapsulated.
6. Don’t Get Carried Away with Backgrounds (Stick to Givens)
The larger the background, the greater the load of understanding for each scenario. Scenarios that contain all the details are self-contained and as such, can be more understandable at a glance.
7. Make Scenarios Independent and Deterministic
There shouldn’t be any sort of coupling between scenarios. The main source of such coupling is state that persists between scenarios. This can be accidental, or worse, by design. For example one scenario could step through adding a record to a database, and subsequent scenarios depend on the existence of that record.
This may work, but will create a problem if the order in which scenarios run changes, or they are run in parallel. Scenarios need to be completely independent.
Each time a scenario runs, it should run the same, giving identical results. The purpose of a scenario is to describe how your system works. If you don’t have confidence that this is always the case, then it isn’t doing its job. If you have non-deterministic scenarios, find out why and fix them.
8. Write Scenarios for the Non-Happy-Path Cases As Well
Happy path tests are easy; edge cases and failure scenarios take more thought and work. Here’s where having some good (and yet pathological) testers on the team can reap rewards.
Use rcov with your full Cucumber runs to find holes in coverage.
9. Be DRY: Refactor and Reuse Step Definitions
Especially look for the opportunity to make reusable step definitions that are not feature specific. As a project proceeds, you should be accumulating a library of step definitions. Ideally, you will end up with step definitions that can be used across projects.
10. Use a Library (Such as Chronic) for Parsing Time in Your Step Definitions
This allows you to use time in scenarios in a natural way. This is especially useful for relative times.
Background:
Given a user signs up for a 30 day account
Scenario: access before expiry
When they login in 29 days
Then they will be let in
Scenario: access after expiry
When they login in 31 days
Then they will be asked to renew
11. Revisit, Refactor, and Improve Your Scenarios and Steps
Look for opportunities to generalize your steps and reuse them. You want to accumulate a reusable library of steps so that writing additional features takes less and less effort over time.
12. Refactor Language and Steps to Reflect Better Understanding of Domain
This is an extension of the previous point; as your understanding of the domain and your customer’s language/terminology improves, update the language used in your scenarios.
13. Use Compound Steps to Build Up Your Language
Compound steps (calling steps from steps) can help make your features more concise while still keeping your steps general—just don’t get too carried away. For example:
Given /^the user (.*) exists$/ do |name|
# ...
end
Given /^I log in as (.*)$/ do |name|
# ...
end
Given /^(.*) is logged in$/ do |name|
Given "the user #{name} exists"
Given "I log in as #{name}"
end
14. Use Parallel Step Definitions to Support Different Implementations for Features
For example, running features against Webrat and Selenium. Put these step definitions somewhere where they won’t be auto-loaded, and require them from the command line or rake task.
15. Avoid Using Conjunctive Steps
Each step should do one thing. You should not generally have step patterns containing “and.” For example:
Given A and B
should be split into two steps:
Given A
And B
Bye 🙂
Font: https://blog.engineyard.com/2009/15-expert-tips-for-using-cucumber/
