TC_StoreVars | ||
store | ABD:XYZ:123 | v |
echo | ${v} | |
echo | javascript{storedVars['v'].split(':').length} | |
echo | javascript{storedVars['v'].split(':')[2]} |
Sharing my learnings on Selenium, I share as I learn and I learn as I share..
Saturday, April 9, 2011
Stored Vars in IDE (Array like functionality)
Screen capture on Google Maps
- Go to the below URL:http://maps.google.com/maps
- Type or Cut and Paste the below Address:
- 90 Hamilton Street, Cambridge, MA-02139
- Verify the Text Present “Lim Consultants Inc”
- Verify the Title “90 Hamilton Street, Cambridge, MA-02139 - Google Maps”
- Click on the “Lim Consultants Inc” link
- VerifyText Present “limconsultants.com” on the right side inline popup window.
- AssertText “Lim Consultants Inc” present within the inline popup window.
- Stop the Recoding in Selenium IDE
- Add screen capture at start and end of the Test, save the images as Test01.jpg and Test02.jpg resp.
CSV Format JS for IDE
comma: ",",
tab: "\t"
};
function formatCommands(commands) {
var result = '';
var sep = SEPARATORS[options['separator']];
for (var i = 0; i < commands.length; i++) {
var command = commands[i];
if (command.type == 'command') {
result += command.command + sep + command.target + sep + command.value + "\n";
}
}
return result;
}
function parse(testCase, source) {
var doc = source;
var commands = [];
var sep = SEPARATORS[options['separator']];
while (doc.length > 0) {
var line = /(.*)(\r\n|[\r\n])?/.exec(doc);
var array = line[1].split(sep);
if (array.length >= 3) {
var command = new Command();
command.command = array[0];
command.target = array[1];
command.value = array[2];
commands.push(command);
}
doc = doc.substr(line[0].length);
}
testCase.setCommands(commands);
}
function format(testCase, name) {
return formatCommands(testCase.commands);
}
options = {separator: 'comma'};
configForm =
'
'
'
'' +
'' +
'
'
STIQ-Pipe Format JS for IDE
comma: ",",
Pipe: "|",
tab: "\t",
Tilde: '~~'
};
function formatCommands(commands) {
var result = '';
var sep = SEPARATORS[options['separator']];
for (var i = 0; i < commands.length; i++) {
var command = commands[i];
if (command.type == 'command') {
switch (sep) {
case '|':
result += sep+command.command + sep + command.target + sep + command.value + sep+ "\r\n";
break;
case '~~':
result += sep+command.command + sep + command.target + sep + command.value + sep+ "\r\n";
break;
default:
result += command.command + sep + command.target + sep + command.value + "\r\n";
}
}
}
//alert(result);
return result;
}
function parse(testCase, source) {
var doc = source;
var commands = [];
var sep = SEPARATORS[options['separator']];
//alert("sep"+sep)
while (doc.length > 0) {
var line = /(.*)(\r\n|[\r\n])?/.exec(doc);
var array = line[1].split(sep);
if (array.length >= 3) {
var command = new Command();
switch (sep) {
case '|':
command.command = array[1];
command.target = array[2];
command.value = array[3];
break;
case '~~':
command.command = array[1];
command.target = array[2];
command.value = array[3];
break;
default:
command.command = array[0];
command.target = array[1];
command.value = array[2];
}
commands.push(command);
}
doc = doc.substr(line[0].length);
}
testCase.setCommands(commands);
}
function format(testCase, name) {
return formatCommands(testCase.commands);
}
options = {separator: 'comma',separator: 'Pipe',separator: 'Tilde'};
configForm =
'
'
'
'' +
'' +
'' +
'' +
'
'
Friday, April 8, 2011
JUnit 4 Vs TestNG
JUnit 4 and TestNG are both very popular unit test framework in Java. Both frameworks look very similar in functionality. Which one is better? Which unit test framework should i use in Java project?
Feature comparison between JUnit 4 and TestNG:
Regular Expressions
Regular Expression Is used by adding the regexp prefix to your pattern: regexp:pattern
Selenium uses the JavaScript implementation of regular expressions (Perl-based):
· any character matches its literal representation: abc will match abc
· [ starts a class, which is any number of characters specified in the class
o [a-z] will match any number of lowercase alphabetical characters without spaces: hello, pizza, world
o [A-Z] does the same with uppercase characters
o [a-zA-Z] will do the same with either uppercase of lowercase characters
o [abc] will match either a, b or c
o [0-9] will match numeric characters
o ^ negates the character class is just after [: [^a-z] will match all but lowercase alphabetic characters
o \d, \w and \s are shortcuts to match respectively digits, word characters (letters, digits and underscores) and spaces
o \D, \W and \S are the negations of the previous shortcuts
· . matches any single characters excepts line breaks \r and \n
· ^ matches the start of the string the pattern is applied to: ^. matches a in abcdef
· $ is like ^ but for the end of the string: .$ matches f in abcdef
· | is equivalent to a logical OR: abc|def|xyz matches abc, def or xyz
· | has the lowest priority so abc(def|xyz) will match either abcdef or abcxyz
· ? makes the last character of the match optional: abc? matches ab or abc
· ? works in a greedy way: it will include the last character if possible
· repeats the preceding item at least zero or more times: ".*" matches "def" and "ghi" in abc "def" "ghi" jkl
· *? is the lazy star: matches only "def" in the previous example
· + matches the previous item at least once or more times.
· {n} will match the previous item exactly n times: a{3} will match aaa
o {n,m} will match the previous item between n and m times with m >= n and is greedy so it will try to match m items first: a{2,4} will match aaaa, aaa and aa
o {n,m}? is the same but in a lazy way: will start by matching at least n times and increase the number of matches to m
o {n,} will match the previous item at least n times
· Common regexps:
o \d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3} matches an ip adress but will also match 999.999.999.999.
o (25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?) will match a real ip adress. Can be shortened to: (?:\d{1,3}\.){3}\d{1,3}
o [A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4} matches an email adress
Selenium IDE - UI-Elements Reference
Useful Add-Ons for Firefox (from Test Automation perspective)
b) DOM Inspector (https://addons.mozilla.org/en-US/firefox/addon/6622 )
c) X-Path Checker (https://addons.mozilla.org/en-US/firefox/addon/1095 )
d) Firebug (https://addons.mozilla.org/en-US/firefox/addon/1843 )
e) Venkman - JS Debugger (https://addons.mozilla.org/en-US/firefox/addon/216 )
f) Web Developer (https://addons.mozilla.org/en-US/firefox/addon/60 )
g) Regular Expression Tester (https://addons.mozilla.org/en-US/firefox/addon/2077 )
h) HTML Validator (https://addons.mozilla.org/en-US/firefox/addon/249 )
i) XPather (https://addons.mozilla.org/en-US/firefox/addon/1192 )
j) ColorZilla (https://addons.mozilla.org/en-US/firefox/addon/271 )
Sunday, April 3, 2011
Changing the default time-out in IDE and RC
You go to the menu Option >> Option >> General Tab >> Second field on the form, change the value to the miliseconds of default time-out.
In RC:
open("http://www.google.com"); // Default timeout being used
setTimeout(new timeout val);
open("http://www.google.com"); // Now Specified timeout being used
Handling JQuery Modal window using Selenium IDE/RC and Selenium 2
New Test | ||
open | http://www.queness.com/resources/html/modal/jquery-modal-window.html | |
click | link=Simple Window Modal | |
click | link=Close it |
Selenium 1 or 2
Selenium 1 has been there for long time and most of the people I know working in this tool have been working on Selenium 1. The Selenium 2 has also been in news since last one year, more so after knowing it will be merging the two projects Webdriver (by Google) and Selenium 1. This seems like a great news as this overcomes the major drawback on Seleniuim 1, the "same origin" problem (rather than running as a Javascript application within the browser), WebDriver controls the browser itself. This means that it can take advantage of any facilities offered by the native platform.
As I have been observing the Selenium 2 project very closely, I noticed that they are not following the "bing bang" integration approach, i.e. the features of Selenium 2 (which have its origin into Webdriver) started to creep into the Selenium RC server over the last one year.
Now Selenium 2 is officially out there, still not very stable and also the lack of documentation is a challenge. However whatever I got to test using the Selenium 2 has been very encouraging, gives you a lot of control and the "same origin" problem is completely avoided.
Now the big question, Selenium 1 or 2?
There in no Selenium IDE or GRID for Selenium 2 yet and that could be the deciding factor for many.
If you are hands-on programmer (esp. java) then you can directly start with Selenium 2. Otherwise, I will recommend that you start with IDE, record and run the formatted code in RC (Selenium 1) and then slowly migrate to Selenium 2.
Another deciding factor, since Selenium 2, even though released officially, it is still a beta release and it might be risky affair to run your client's test scripts on a beta release. So, definitely practice and learn Selenium 2, however wait up for it's official "full-blown" release at a later date.
Also if you need to use GRID then you need to stick to Selenium 1... at least for the time being.
Platforms Supported by Selenium - Browsers, Languages and OS
Browsers
Browser | Selenium IDE | Selenium Remote Control | Selenium Core |
Firefox 3 | Record and playback tests | Start browser, run tests | Run tests |
Firefox 2 | Record and playback tests | Start browser, run tests | Run tests |
IE 8 | not supported | Start browser, run tests | Run tests |
IE 7 | not supported | Start browser, run tests | Run tests |
Safari 3 | not supported | Start browser, run tests | Run tests |
Safari 2 | not supported | Start browser, run tests | Run tests |
Opera 9 | not supported | Start browser, run tests | Run tests |
Opera 8 | not supported | Start browser, run tests | Run tests |
Others | not supported | Partial support possible | Run tests |
OS | Selenium IDE | Selenium Remote Control | Selenium Core |
Windows | Works in Firefox 2+ | Start browser, run tests | Run tests |
OS X | Works in Firefox 2+ | Start browser, run tests | Run tests |
Linux | Works in Firefox 2+ | Start browser, run tests | Run tests |
Solaris | Works in Firefox 2+ | Start browser, run tests | Run tests |
Others | Should work in Firefox 2+ | Start browser, run tests | Run tests |
Programming Languages
Programming languages are supported through Selenium Remote Control "drivers." These are libraries made for each language that expose commands from the Selenium API natively in the form of methods/functions.
Language | Selenium IDE | Selenium Remote Control | Selenium Core |
C# | Generate code | Library ("driver") support | n/a |
Java | Generate code | Library ("driver") support | n/a |
Perl | Generate code | Library ("driver") support | n/a |
PHP | Generate code | Library ("driver") support | n/a |
Python | Generate code | Library ("driver") support | n/a |
Ruby | Generate code | Library ("driver") support | n/a |
Others | Generate custom code | Commands via HTTP requests | n/a |
What is Selenium?
Selenium is a portable software testing framework for web applications.
Selenium is used for UAT (User Acceptance Test).
The tests can be written as HTML tables or coded in a number of popular programming languages (Java, Perl, PHP, Python, C#, Ruby) and can be run directly in most modern web browsers (Firefox, IE, Safari, Opera).
Selenium can be deployed on platforms like Windows, Linux, and Macintosh.
Components of Selenium:
- IDE (Record & Playback - Firefox Addon)
- RC (Remote Control) - Multi-Browser, Multi-Language, Multi-Platform
- GRID - Architecture of RC server enabling parallel execution of Tests
Selenium is open source software, released under the Apache 2.0 license and can be downloaded and used without charge. For more details visit http://www.gnu.org/licenses/gpl.html