Showing posts with label WebDriver. Show all posts
Showing posts with label WebDriver. Show all posts

Road to handle http authentication in webdriver

One of my applications had Http authentication for security purpose and I had need to automate using webdriver. As we know http authentication is not a part of DOM object so we cannot handle it using webdriver. Here is approach to handle such type situation.

We need to pass http credential with URL to skip http popup authentication window. Below is URL format.


User above formatted URL in webdriver get method:


After using above approach, http authentication popup window disappear. But in Internet explorer, it raise error with message “wrong format url”. To accept same type url in internet explorer browser we need to add a DWORD value named exploere.exe and iexplore.exe  with value data 0 in below registry.
To open registry, open "regeidt" from run command.

  1. For all users of the program, set the value in the following registry key: HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_HTTP_USERNAME_PASSWORD_DISABLE
  2. For the current user of the program only, set the value in the following registry key: HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_HTTP_USERNAME_PASSWORD_DISABLE 
  3. If you are using 64 bit machine, set the value in the following registry key. HKEY_CURRENT_USER\Software\WOW6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_HTTP_USERNAME_PASSWORD_DISABLE

Road to verify images using java webdriver

In this post I have explained that how to verify images in webdriver using java. As webdriver does not provide direct any function to image verification, but we can verify images by taking two screen shots of whole web page using “TakesScreenshot” webdriver function, one at script creation time and another at execution time,

In below example I have created a sample script in which first I captured a Google home page screen shot and saved (GoogleInput.jpg) into my project, Another screen shot “GoogleOutput.jpg” captured of same page at test executing time and saved into project. I compared both images if they are not same then test will script fail.

Road to verify 200 response code of web application in java webdriver

This post will help to verify HTTP response code 200 of web application using java webdriver. As webdriver does not support direct any function to verify page response code. But using "WebClient" of HtmlUnit API we can achieve this.

Html unit API is GUI less browser for java developer, using WebClent class we can send request  to application server and verify response header status.

Below code, I used in my webdriver script to verify response 200 of web application

 String url = "http://www.google.com/";
 WebClient webClient = new WebClient();
 HtmlPage htmlPage = webClient.getPage(url);

 //verify response
 Assert.assertEquals(200,htmlPage.getWebResponse().getStatusCode());
 Assert.assertEquals("OK",htmlPage.getWebResponse().getStatusMessage());

Road to accept certificates in internet explorer using webdriver

One of my projects, I need to verify application certificates during test case execution . It was working fine on firefox and google chrome browser as webdriver automatically accept certificate.  But Internet Explorer webdriver was not accepted automatically after doing a lot of observation, finally I got solution by navigating below java script code with webdriver object.

 driver.navigate().to("javascript:document.getElementById('overridelink').click()");

Road to verify PDF file text using java webdriver

In this post I will explain the procedure to verify PDF file content using java webdriver. As  some time we need to verify content of web application pdf file, opened in browser.
Use below code in your test scripts to get pdf file content.

Data driven testing using java webdriver TestNg framework

In this post I implemented that how to perform data driven testing using java Webdriver  TestNg framework. As we know testNg provide @DataProvider annotation, using this I can pass a set of data into our Webdriver test method.  I have created a sample test script for Wikipedia where I use a set of country data, with Wikipedia search functionality and verify searched country.

Screen Recording (Video) of Java Webdriver script

Sauce lab provided screen capturing functionality to test scripts execution, I was looking same type functionality to work on local machine and came up across “Monte Media Library” java based library developed by Werner Randelshofer.. In this post I have described a way to capture screen cast/ Video recording of selenium/webdriver test script execution.

Step to implement Monte Media library to selenium/Webdriver test scripts.
  1. Download “MonteScreenRecorder.jar” from link http://www.randelshofer.ch/monte/
  2. Add this jar file to your selenium/webdriver eclipse project.
  3. This jar file contain “ScreenRecorder” class, we need to create this class object by following way.

Webdriver C# test scripts execution using Grid2

Nunit framework is not support parallel execution of driver test scripts using Grid. If we use MbUuit framework then we can accomplish parallel execution of test scripts against Grid2. For set up MbUnit you can see “MbUnit Framework

Test scripts setup :
  1. Add reference Gallio and  MbUnit ddl file to your Webdriver project from installed Gallio folder.
  2. Add below code in project’s  “AssemblyInfo.cs” file.
using MbUnit.Framework;

[assembly:DegreeOfParallelism(2)]
[assembly:Parallelizable(TestScope.All)]
       3. We need to add below code for MbUnit framework in test scripts.
using MbUnit.Framework;

add [Parallelizable] annotation on test case lavel ass I added in belowtest scripts.
       4. I have created two test one “GridTest1.cs” file for internet explorer and “GridTest2.cs” file for firefox  browser.

C# WebDriver with MbUnit Framework

Set Up C# Webdriver with MbUnit and Gallio:
  1. Download and install Gallio from link ‘http://gallio.org/Downloads.aspx’
  2. Add reference Gallio and  MbUnit ddl files to webdriver project from installed Gallio folder.

Start with C# WebDriver - Procedure to create first test script for the beginners

Prerequisite:
  1. Visual studio should be installed in machine..
  2. Download “Nunit: from link http://nunit.org/index.php?p=download and install in your machine.
  3. Download selenium-dotnet-2.31.0.zip file from link http://docs.seleniumhq.org/download/ and unzip in your machine.
Step To create new project.

    1. Open Visual studio in your machine.
    2. Go to and click on  File > New > Project.
    3. Select visual C# from left panel and select class library


     4. Enter project name  chose location and click on OK button.
     5. A default class created with named “Class1.cs” under your project         
     6. Rename this class or create new class for your test script.

Start with Ruby WebDriver - Procedure to create first test script for the beginners

Setup of Ruby and Selenium 2
  1. Download ruby setup file  from url http://rubyinstaller.org/downloads . Install the executable file into your system and set Ruby as Environmental variable into your system.
  2. Open command prompt and check “ruby  -v “ to verify ruby installation and path setup.
  3. After ruby installation run below command for selenium2 installation.
gem install selenium-webdriver

Create First Test Scripts:

Capture your test scenario using selenium Ide. import test script into Ruby/ Test::Unit /Webdriver and save as a .rb file in your machine. I have created below a sample Google search script.

Start with PHP WebDriver - Procedure to create first test script for the beginners

Prerequisite:
  1. PHP should be installed and set up path in your machine. 
  2. PHPUnit Should be installed in machine.
  3. Java should be install and setup path in machine.
  4. Selenium2 jar(selenium-server-standalone-2.**.0.jar) file should in your machine.
Procedure & Setup of PHP and PHPUnit

If PHP and PHPunit are not installed in machine. We need to follow to installed them using below steps:
  1. Download PHP exe file from download and install in machine.
  2. Setup PHP path in environment variable if by default not path set. As if I installed in C:\\PHP drive the we need to setup path  “C:\\PHP”
  3. Now we need to install PEAR for this we open command prompt and go to PHP installation directory and run command
php.exe PEAR/go-pear.phar
     4.  After pear installed check version using command “pear  –V” . run below command to update pear.
  pear upgrade pear

How to run java test scripts using Grid2

Prerequisites. 
  1. Java should be install and setup path in system.
  2. Eclipse should be configured TestNG plugin 
  3. Download the selenium-server-standalone-version.jar from the below location.
  4. TestNG jar file.
Steps to  create and execute test scripts:

1. Launch Grid 2 console(Hub ) and Nodes using below commands:

    Hub:
       java -jar selenium-server-standalone-2.29.0.jar -host localhost -port 4444 -role hub

    Nodes:
       java -jar selenium-server-standalone-2.29.0.jar -host localhost -port 5555 -role webdriver -hub http://localhost:4444/grid/register -browser browserName=iexplore,platform=XP,version=8

        java -jar selenium-server-standalone-2.29.0.jar -host localhost -port 5556 -role webdriver -hub http://localhost:4444/grid/register -browser browserName=firefox,platform=XP,version=13
       
2. Run test case parallel:  This “WebDriverGrid2Test “ example will be run test case on firefox and  internet explorer on version 8 and 13 respectively.

How to run python webdriver test scripts using Grid2

Prerequisite:
  1. Java and python should be installed and setup path in your machine..
  2. Download xmlrunner.py from below url: http://pypi.python.org/pypi/XmlTestRunner/0.16654
  3. Download and install “setuptools 0.6c11” from below link: http://pypi.python.org/pypi/setuptools
  4. Install selenium 2 in your system using command: > easy_install selenium
  5. Selenium server file should be in machine
Set up and launching Selenium Grid:

      1. Run below command in on your console to launch Grid hub console:
java -jar selenium-server-standalone-2.21.0.jar -host localhost -port 4444 -role hub
       2. Open two console and run below command to launch and register node with Grid hub.
java -jar selenium-server-standalone-2.21.0.jar -host localhost -port 5555 -role webdriver -hub http://localhost:4444/grid/register -browser browserName=firefox,platform=WINDOWS

java -jar selenium-server-standalone-2.21.0.jar -host localhost -port 5556 -role webdriver -hub http://192.168.1.22:4444/grid/register -browser browserName=iexplore,platform=WINDOWS
           Replace local host to system IP of Hob machine. If you want to launch node in different machine.

Start with Python WebDriver - Procedure to create first test script for the beginners

Prerequisite:

   1. Python should be installed and set up path in your machine.Download Python from here “ClickHere
   2. Install easy_install using code from link "Click to download" .Just copy code from url and past in a new      created python file like “setup.py”
  3. Put “setup.py” file in where python installed and run “setup.py” file as below command
      >python setup.py
  4. After successfully execution a Scripts folder created under Pyhon installed directory. setup “Script”    folder path in your machine.
  5. Install selenium 2 in your system using command: > easy_install selenium

How to Set up and launching Selenium Grid?

Download selenium latest jar file from Webdriver

Launching Hub:

Open command prompt and got to your selenium server jar file and run command:

java -jar selenium-server-standalone-2.21.0.jar -host localhost -port 4444 -role hub
screen should be displayed like below.


Start with Java Webdriver - Procedure to create first test script for the beginners

Prerequisites:
  1. Download Selenium2 jar file from http://seleniumhq.org/download/.
  2. Download TestNG jar file from http://testng.org/doc/download.html
  3. Download and Install JDK and setup java path 
  4. Download Eclipse IDE from http://www.eclipse.org/downloads/
  5. Install TestNG plugin in downloaded eclipse
  6. Firefox should be install with selenium IDE plugin.