Sei sulla pagina 1di 27

SeIenium

Prepared By
Naveenraj Soundararajan
2
ntroduction
Selenium is a tool used for functional and regression testing of
web applications.
Works with any browser that supports Javascript
Can simulate a user navigation through pages and then assert for
specific marks on the pages
SeIenium Components
Selenium IDE - To create and debug test scripts
Selenium Remote Control - To run the test on many browsers like
Internet Explorer, Firefox , Chrome and to modify the test
programmatically
Selenium Grid - To run the tests parallely on multiple machines at
the same time
SeIenium Features
CPAN Comprehensive Perl Archive network
One stop shop for perl
t is an archive of over 16,000 perl modules, as well as documentation for it
The CPAN's main purpose is to help programmers locate modules and
programs not included in the Perl standard distribution
Weblink
http://www.cpan.org/
http://www.perl.com/CPAN/
4
5
#unning PerI Scripts #unning PerI Scripts
Windows
Download ActivePerl from ActiveState
Just run the script from a 'Command Prompt' window
perl script_name
&NX
Put the following in the first line of your script
#!/usr/bin/perl
Run the script
% perl script_name

SampIe program
example.pl
#! /usr/sbin/perl
# sample program
$name = <STDN> ; # getting the input from keyboard
chomp ($name);
print "Welcome $name to perl; # printing it on screen
Basic syntax
All the executable statements should end with semi colon
Comments should start with pound sign '#'
No multi line comments in Perl
You don't have to declare a variable before you access it and don't have to
declare a variable's type
utput / input
Print ( ) to print text on the screen
Examples
print "hello world \n ; # hello world followed by new line
a = "perl;
print "Welcome $a; => Welcome perl
print "Welcome \$a; => Welcome $a
Say ( ) - Appends \n at the end
<STDN> - Getting in from keyboard ( like scanf in C)
$a = <STDN>;

Chomp and Chop


chop - t removes the last character in the string
Ex: $a = "abc;
chop($a);
print($a); # prints "ab
chomp t removes only the new line character at the end of the string
Ex: $a = "abc\n;
chomp($a);
print($a); # prints "abc

scape Sequences

scape sequence Meaning


\n New line
\t Tab
\b Backspace
\l Lower case next letter
\u &pper case next letter
\& &pper case all letters until \E
\L Lower case all letters until \E
\E End \& or \L
\\ Back slash
ispIay Warnings
To display warning messages during compilation
#! /usr/local/bin perl w
use warnings;
perl w <perl script name>

ScaIars
Scalar variables stores single value, a string or number
Scalar Variable Syntax
Variable name starts with $, followed by at least one letter, which is
followed by any number of letters, digits, or underscore characters
ex: $sample_data1 = "test;
$sample_data2 = 5 ;
Variable names are case sensitive
$VAR , $var, $Var - Treated as different variables
Strings
Quoting Strings
With SingIe quotes Special meaning of the characters with single quotes
are not interpreted by perl
ex: $lang = "perl " ;
print 'Learning $lang'; # ouput - Learning $lang
With oubIe quotes Special meanings of characters with in double
quotes are interpreted by perl
ex: $lang = "perl " ;
print "Learning $lang; # ouput - Learning perl
2

String operators
perator peration
. (Dot) string concatenation
x string repetition
.= concatenation and assignment
$string1 = "potato";
$string2 = "head";
$newstring = $string1 . $string2; #"potatohead"
$newerstring = $string1 x 2; #"potatopotato"
$string1 .= $string2; #"potatohead"
4
NumericaI operators
perators peration

Addition
-
Subtraction
*
Multiplication
/
Division
=
Assignment
**
Exponentiation
%
Modulo operator

Auto increment
--
Auto decrement
uto conversion b/w num and string
Perl automatically converts between numbers and strings depends on the
operator being used on the scalar value
Examples:
"12 * "3 = 36
"12fred * "3 = 36
"12fred2 * "3 = 36
"fred * "3 = 0
"Fred3 * "3 =0
"fred.3 = fred3
5
Bit manipuIation operators
perator peration
Bitwise AND
| Bitwise OR
^ Bitwise XOR
~ Bitwise NOT
>> Right shift operator
<< Left shift operator
Comparison perators Comparison perators
String peration rithmetic
t less than
t greater than >
eq equal to ==
e less than or equal to =
e greater than or equal to >=
ne not equal to !=
cmp compare, return 1, 0, -1 =>

Comparison perators (Cont) Comparison perators (Cont)


The <=> operator is a special case. &nlike the other integer comparison
operators, <=> returns one of three values:
0, if the two values being compared are equal
1, if the first value is greater
-1, if the second value is greater
Ex: $result = $x <=>10;
String Comparisons
$result = "aaa" lt "baa"; # result is true
$result = "abc gt "bdc # result is false
$result = "aaa" cmp "bbb"; # result is -1
ther perators
ConditionaI operator
The conditional operator requires three operands
A condition to test
A value that is to be used when the test condition is true (evaluates to a nonzero
value)
A value that is to be used when the test condition is false (evaluates to zero)
Matching operator =~ ( Will be discussed in regular expression)
#ange operator ( 1 .. 10) ( Will be discussed in lists)
2
ControI Structures
f
f else
f elsif else
&nless
&nless else
While
&ntil
Do while
Do until
For
Foreach
ControI Structures (Cont)
unIess:
unless (condition) { # statement block is executed, only when the condition
Statement block; # evaluates to false
} ;
unIess eIse
unless (condition) {
Statement block;
}
else {
Statement block
}
2
ControI Structures (Cont)
untiI
until (condition) { # it iterates the loop till the condition evaluates to
statement block true
}
SingIe statement bIocks
print ("a is greater) if ( $a > $b );
print ("a is greater) unless ( $a < $b );
oop controIs
last (like break in C) mmediately ends the execution of loop
next (like continue in C) After next, control continues with the next iteration
of loop
redo it says go to top of the current loop block with out executing
conditional expression or advancing to next iteration
goto <Label> - Takes the control to the label (same as in C)
ogicaI perators ogicaI perators
perator peration
or logical or
and logical and
! not logical not
xor logical xor
ogicaI perators ogicaI perators
|| (Logical OR) || (Logical OR)
ex: ex:
(expression 1) || (expression2); (expression 1) || (expression2); - - t evaluates the expression 2 only if the t evaluates the expression 2 only if the
expression 1 is false expression 1 is false
(Logical AND) (Logical AND)
ex: ex:
(expression 1) (expression2); (expression 1) (expression2); - - t evaluates the expression 2 only if the t evaluates the expression 2 only if the
expression 1 is true expression 1 is true
&sing octaI , Hex and bin notation
octal prefix '0' (zero)
hexadecimal prefix '0x'
binary prefix '0b'
Ex:
$result = 032 # result has decimal equivalent of octal 32 i.e 26
$result = 0xF # result has decimal equivalent of hexadecimal F i.e 15
$result = 0b011 # result has the decimal equivalent of binary 011 i.e 3
END

Potrebbero piacerti anche