Tuesday, 17 September 2013

What is Inter system testing ?

It means that,sharing the resources of one system with
another. Eg:Suppose u have icici bank debit
card.OK.unfortunately u need a cash very urgent,u found sbi
atm nearby u.OK.U just and insert icici card and enter ur
pin.OK.

what the process will happen is.

The request u made is first it sents to sbibank server and
then transfers to icicibank server and process will do in
iciciserver and again it sents to sbibank server.now u can
get cash from atm.The conclusion is sbibank server is
sharing the resources with icici bank server and performing
the required operations.

Intersystem testing is the process in which wheather the one
system of resources is sharing with another system resources
or not

I hope u clear
 

Friday, 12 July 2013

How to automate onblur through selenium RC .


How to automate onblur through selenium RC .
How to automate lost focus through selenium.


I faced the problem while automating the form submit. All of the form fields are having some action on their lost focus.
The onblur event occurs when an object loses focus.
For example : I have two fields First Name and Last Name. When i enter first name and press tab then it loses its focus and onblur function gets called.
and its calls upperCase and it changes the first name in Upper case.
the same case with Last Name. When i enter last name and press tab it calls blur function lowerCase and changes the letters in lower case.

But the problem in automation is i cant automate lost focus. when we type in first name and last name it simply types in first name and last name text box.
It does not call onblur function upper case and lower case and does not change the letter respectively.

so, fireEvent is a special command in selenium which helps in automating onblur function.

this is html of the element and blur javascript functions


<html>
<head>
<script type="text/javascript">
function upperCase()
{
var x=document.getElementById("fname").value;
document.getElementById("fname").value=x.toUpperCase();
}
function lowerCase()
{
var x=document.getElementById("lname").value;
document.getElementById("lname").value=x.toLowerCase();
}
</script>
</head>
<body>
Enter your First Name: <input type="text" id="fname" onblur="upperCase()" />
<br />
Enter your Last Nast: <input type="text" id="lname" onblur="lowerCase()" />
</body>
</html>


when we write simple selenium RC code

 selenium.type("fname", "niraj");
 selenium.type("lname", "KUMAR");
 
it doest call blur functions to change cases of the first name and last name.

But by using fireEvent fuction of selenium we can call blur function.

 selenium.type("fname", "niraj");
 selenium.fireEvent("fname", "blur");
 selenium.type("lname", "KUMAR");
 selenium.fireEvent("lname", "blur");

How this works is :

First this will type "niraj" in First Name and then selenium.fireEvent("fname", "blur"); this will call the onblur fuction "upperCase()" which changes the First Name in upper case "NIRAJ".
then it types in Last Name and then selenium.fireEvent("lname", "blur"); which means it will press tab and lost the function and on the lost focus it calls
blur function lowerCase which changes the Last Name in lower case.

How to verify the text ignoring cases sensitivity in selenium ?


How to verify the text ignoring cases sensitivity in selenium ?

Some times we need to verify the text on the webpage no matter is upper cases or lower cases or proper.
We just need to verify the text on the web page ignoring their cases sensitivity.
REGEXPI is used to avoid cases sensitive to verify the text on the page.

Lets say i want to verify the text "Automationtricks is good blog for selenium" No matter its in upper cases or lower case or proper case.

Then use REGEXPI in selenium command selenium.isTextPresent or verifyTextPresent.


<tr>
    <td>verifyTextPresent</td>
    <td>regexpi:AUTOMATIONTRICKS IS GOOD BLOG FOR SELENIUM</td>
    <td></td>
</tr>

<tr>
    <td>verifyTextPresent</td>
    <td>regexpi:AUTOMATIONTRICKS is good blog for selenium</td>
    <td></td>
</tr>

<tr>
    <td>verifyTextPresent</td>
    <td>regexpi:AUTOMAtionTRICKS Is GoOd Blog for SELENIUM</td>
    <td></td>
</tr>

<tr>
    <td>verifyTextPresent</td>
    <td>regexpi:automationtricks is good blog for selenium</td>
    <td></td>
</tr>


In Selenium RC

verifyTrue(selenium.isTextPresent("regexpi:AUTOMATIONTRICKS IS GOOD BLOG FOR SELENIUM"));

verifyTrue(selenium.isTextPresent("regexpi:AUTOMATIONTRICKS is good blog for selenium"));

verifyTrue(selenium.isTextPresent("regexpi:AUTOMAtionTRICKS Is GoOd Blog for SELENIUM"));

verifyTrue(selenium.isTextPresent("regexpi:automationtricks is good blog for selenium"));

How to locate an element which have same name and same atrributes in selenium


Automation using selenium is a great experience. It provides many way to identif an object or element on the web page.
But sometime we face the problems of idenfying the objects on a page which have same attributes. When we get more than
one element which are same in attribute and name like multiple checkboxes with same name and same id. More than one button having
same name and ids. There are no way to distingues those element. In this case we have problem to instruct selenium to identify a perticular
object on a web page.
I am giving you a simple example . In the below html source there are 6 checkboxes are there having same type and same name.
It is really tough to select third or fifth.

<html>
<body>
<input type='checkbox' name='chk'>first
<br><input type='checkbox' name='chk'>second
<br><input type='checkbox' name='chk'>third
<br><input type='checkbox' name='chk'>forth
<br><input type='checkbox' name='chk'>fifth
<br><input type='checkbox' name='chk'>sixth
</body>
</html>


Thare are some function we can use in Xpath to identify the abject in above cases.
An XPath expression can return one of four basic XPath data types:

* String
* Number
* Boolean
* Node-set

XPath Type : Functions
Node set : last(), position(), count(), id(), local-name(), namespace-uri(), name()
String : string(), concat(), starts-with(), contains(), substring-before(), substring-after(), substring(), string-length(), normalize-space(), translate()
Boolean : boolean(), not(), true(), false(), lang()
Number : number(), sum(), floor(), ceiling(), round()

I will show you how we can use some of these above functions in xpath to identify the objects.

Node Set : last()


In the above html file there are six checkboxes and all are having same attributes (same type and name)
How we can select the last checkbox based on the position. We can use last() function to indentify the last object among all similar objects.
Below code will check or uncheck the last checkbox.

selenium.click("xpath=(//input[@type='checkbox'])[last()]");

How we can select the second last checkbox and third last checkbox. We can use last()- function to indentify the last object among all similar objects.
Below code will check or uncheck the second last checkbox and thrid last checkbox respectively.

selenium.click("xpath=(//input[@type='submit'])[last()-1]");
selenium.click("xpath=(//input[@type='submit'])[last()-2]");


Node Set : position() 

If you want to select any object based on their position using xpath then you can useposition() function in xpath.
You want to select second checkbox and forth checkbox then use below command

selenium.click("xpath=(//input[@type='checkbox'])[position()=2]");
selenium.click("xpath=(//input[@type='checkbox'])[position()=4]");

above code will select second and forth checkbox respectively.

String : starts-with() 

Many web sites create dynamic element on their web pages where Ids of the elements gets generated dynamically.
Each time id gets generated differently. So to handle this situation we use some JavaScript functions.

XPath: //button[starts-with(@id, 'continue-')]  


Sometimes an element gets identfied by a value that could be surrounded by other text, then contains function can be used.
To demonstrate, the element  can be located based on the ‘suggest’ class without having
to couple it with the ‘top’ and ‘business’ classes using the following

XPath: //input[contains(@class, 'suggest')].



Example: How to click on link on the page which has many links with same name and attributes.
Below is the example of your html which has 3 links with same name and same attributes


<html>
<body>
<a href="http://www.google.com" name="a1">Link</a>
<a href="http://www.yahoo.com" name="a1">Link</a>
<a href="http://www.gmail.com" name="a1">Link</a>
</body>
</html>



If you want to click on first link then use below command

<tr>
 <td>clickAndWait</td>
 <td>xpath=(//a[@name='a1'])[position()=1]</td>
 <td></td>
</tr>

If you want to click on second link then use below command

<tr>
 <td>clickAndWait</td>
 <td>xpath=(//a[@name='a1'])[position()=2]</td>
 <td></td>
</tr>

If you want to click on last link or third link then use below command

<tr>
 <td>clickAndWait</td>
 <td>xpath=(//a[@name='a1'])[last()]</td>
 <td></td>
</tr>

OR

<tr>
 <td>clickAndWait</td>
 <td>xpath=(//a[@name='a1'])[position()=3]</td>
 <td></td>
</tr>

Selenium RC. 

Click on first link
selenium.click("xpath=(//a[@name='a1'])[position()=1]");
selenium.waitForPageToLoad("80000");
Click on second link
selenium.click("xpath=(//a[@name='a1'])[position()=2]");
selenium.waitForPageToLoad("80000");
Click on last link
selenium.click("xpath=(//a[@name='a1'])[last()]");
selenium.waitForPageToLoad("80000");
Click on thrid link
selenium.click("xpath=(//a[@name='a1'])[position()=3]");
selenium.waitForPageToLoad("80000");

How to handle the input promt dialog in selenium


There are some scenarios where we need to input when our web application need external input data by opening input prompt dialog box. To handle these dialog boxes in automation is tricky task. We can handle these situation with below codes.
Html file is at the bottom

selenium.open("Input_prompt_TestCase.html");

Verify there is no input dilog present while opening this file


assertTrue(!selenium.isPromptPresent());

When then Input prompts select NO first time by the command answerOnNextPrompt|no|

selenium.answerOnNextPrompt("no");

Now click to open the input dialog by clicking the link "Click here to open input dialog"

selenium.click("promptdialog");

Now verify prompt presents or not with the command verifyPromptPresent||
assertTrue(selenium.isPromptPresent());
If it takes time to open the prompt then we can wait till 1 minute with the below code.

boolean Bool = false;
for (int second = 0; second < 60; second++) { 
try { 
if ((selenium.isPromptPresent())) {
Bool = true;
break; 
}
}
catch (Exception ignore) {
}
pause(1000);
}
assertTrue(Bool);


Now after 1 minute verify the prompt presents or not with the command assertPromptPresent||


assertTrue(selenium.isPromptPresent());

If it verifies prompt is there then verify the text what is on prompt with the command
verifyPrompt|Type 'automationtricks' and click OK|


verifyEquals("Type 'automationtricks' and click OK", selenium.getPrompt());

You can also verify the title of input prompt with the command verifyTitle|Test Prompt|


verifyEquals("*Testcases for input Prompt", selenium.getTitle());

Now you just enter automationtricks in input promt with this command
answerOnNextPrompt|automationtricks|


selenium.answerOnNextPrompt("automationtricks");

and then click on ok with command clickAndWait|promptdialog|


selenium.click("promptdialog");

Now you can see the result based on your input


selenium.waitForPageToLoad("5000");
verifyTrue(selenium.isTextPresent("You have entered automationtricks!"));



For Selenium IDE user : How to handle prompt in selenium IDE 


<tr>
<td>open</td>
<td>Input_prompt_TestCase.html</td>
<td></td>
</tr>
<tr>
<td>answerOnNextPrompt</td>
<td>automationtricks</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>promptdialog</td>
<td></td>
</tr>
<tr>
<td>verifyTextPresent</td>
<td>You have entered automationtricks!</td>
<td></td>
</tr>
<tr>
<td>open</td>
<td>Input_prompt_TestCase.html</td>
<td></td>
</tr>
<tr>
<td>answerOnNextPrompt</td>
<td>niraj</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>promptdialog</td>
<td></td>
</tr>
<tr>
<td>verifyTextPresent</td>
<td>You have not entered automationtricks!</td>
<td></td>
</tr>


For the above code find Html file below 


<html>
<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html">
<script type="text/javascript">
function opendialog() {
if (prompt("Type 'automationtricks' and click OK") == 'automationtricks') {
document.write("You have entered automationtricks!");
}
else{
document.write("You have not entered automationtricks!");
}
}
</script>
<title>Testcases for input Prompt</title>
</head>
<body>
<img style="width: 644px; height: 41px;" alt="banner" src="banner.gif"><br>
<a id="promptdialog" href="javascript:opendialog();">Click here to open input dialog</a>
</body>
</html>

How to get current page url in selenium


There are some situations where we need to know the url of current page.

selenium IDE

<tr>
<td>storeLocation</td>
<td>url</td>
<td></td>
</tr>
<tr>
<td>echo</td>
<td>${url}</td>
<td></td>
</tr>



Selenium RC

String url = selenium.getLocation();
System.out.println(url);

Selenium Regular Expression and pattern matching


Like locators, patterns are a type of parameter frequently required by Selenese commands. Examples
of commands which require patterns are verifyTextPresent, verifyTitle, verifyAlert, assertConfirmation,
verifyText, and verifyPrompt.Patterns allow one to describe, via the use of special characters, what text is expected rather
than having to specify that text exactly

  • Global Patterns 

    * which translates to “match anything,” i.e., nothing, a single character, or many characters.
    [ ] (character class) which translates to “match any single character found inside the square
    brackets.” A dash (hyphen) can be used as a shorthand to specify a range of characters
    (which are contiguous in the ASCII character set). A few examples will make the functionality
    of a character class clear:
    [aeiou] matches any lowercase vowel
    [0-9] matches any digit
    [a-zA-Z0-9] matches any alphanumeric character
    In most other contexts, globbing includes a third special character, the ?. However, Selenium globbing
    patterns only support the asterisk and character class.
    To specify a globbing pattern parameter for a Selenese command, one can prefix the pattern with a glob:
    label. However, because globbing patterns are the default, one can also omit the label and specify just
    the pattern itself.
    Below is an example of two commands that use globbing patterns. The actual link text onthe page
    being tested was “Film/Television Department”; by using a pattern rather than the exact text, the click
    command will work even if the link text is changed to “Film & Television Department” or “Film and
    Television Department”. The glob pattern’s asterisk will match “anything or nothing” between the word
    “Film” and the word “Television”.
    click link=glob:Film*Television Department
    verifyTitle glob:*Film*Television*
    The actual title of the page reached by clicking on the link was “De Anza Film And Television Department
    - Menu”. By using a pattern rather than the exact text, the verifyTitle will pass as long as
    the two words “Film” and “Television” appear (in that order) anywhere in the page’s title. For example,
    if the page’s owner should shorten the title to just “Film & Television Department,” the test would still
    pass. Using a pattern for both a link and a simple test that the link worked (such as the verifyTitle
    above does) can greatly reduce the maintenance for such test cases.

    Some examples for global pattern

    Lets say your element looks like

    <input class="foo" value="the text value" name="theText">

    verifyEquals("*text*", selenium.getValue("theText"));

    <input type="hidden" value="the hidden value" name="theHidden">

    verifyEquals("* hidden value", selenium.getValue("theHidden"));

    If you have drop down combo box then you can use global pattern matching .

    <select id="theSelect">
    <option id="o1" value="option1">first option</option>
    <option selected="selected" id="o2" value="option2">second option</option>
    <option id="o3" value="option3">third,,option</option>
    </select>

    select the second option and verify like this

    assertEquals("second *", selenium.getSelectedLabel("theSelect"));
    or,
    String[] arr = {"first*", "second*", "third*"};

    verifyEquals(arr, selenium.getSelectOptions("theSelect"));
  • The question mark ? indicates there is zero or one of the preceding element. For example, colo?r matches both "color" and "colour".

    If your element is like
    <input class="foo" value="the text value" name="theText">

    verifyEquals("?oo", selenium.getAttribute("theText@class"));

  • Regular expression 
    Regular expression patterns are the most powerful of the three types of patterns that Selenese supports.
    Regular expressions are also supported by most high-level programming languages, manytext editors and a host of tools, including the Linux/Unix command-line utilities grep, sed, and awk.

    regexp (wildcard) matching


    <input class="foo" value="the text value" name="theText">

    verifyEquals("regexp:^[a-z ]+$", selenium.getValue("theText"));

    <input type="hidden" value="the hidden value" name="theHidden">

    verifyEquals("regexp:dd", selenium.getValue("theHidden"));


    <select id="theSelect">
    <option id="o1" value="option1">first option</option>
    <option selected="selected" id="o2" value="option2">second option</option>
    <option id="o3" value="option3">third,,option</option>
    </select>

    assertEquals("regexp:second .*", selenium.getSelectedLabel("theSelect"));
  • verify Attributes using regular expression 

    <input class="foo" value="the text value" name="theText">

    verifyEquals("regexp:^f", selenium.getAttribute("theText@class"));

    verifyEquals("regex:^[a-z ]+$", selenium.getValue("theText"));

    <select id="theSelect">
    <option id="o1" value="option1">first option</option>
    <option selected="selected" id="o2" value="option2">second option</option>
    <option id="o3" value="option3">third,,option</option>
    </select>

    assertEquals("exact:second option", selenium.getSelectedLabel("theSelect"));

    String[] arr = {"regexp:^first.*?", "second option", "third*"};
    verifyEquals(arr, selenium.getSelectOptions("theSelect"));
  • Angular JS Protractor Installation process - Tutorial Part 1

                         Protractor, formally known as E2E testing framework, is an open source functional automation framework designed spe...