Sunday, 2 August 2015

Interaction with Windows Dialog box using Selenium Web-Driver C#

Agenda for this blog:To discuss about  handling Window based Dialogue/popup box in Selenium C# .

What is Window Dialogue/Pop-Up:Its a dialogue box which is not a part of  webpage but are the domain of the Operating System.

As it does not belong the web property so Selenium web-driver is unable to interact directly with this type of popup/dialogue.However its possible to perform actions on dialog windows using 
"SendKeys" class's method "SendWait()" of name space System.Windows.Forms.

Detailed reference of SendKeys Class can be found in https://msdn.microsoft.com/en-au/library/system.windows.forms.sendkeys.aspx


Sample Scenario

1.Uploading File:


In this scenario we will handle window dialogue for uploading File in Selenium.


 static void Main(string[] args)
        {

            IWebDriver driver = new FirefoxDriver();
            driver.Manage().Window.Maximize();
            driver.Navigate().GoToUrl("https://www.newocr.com/");
            driver.FindElement(By.XPath("//input[@id='userfile']")).Click();
            Thread.Sleep(3000);
            String pathToFile = "C:\\Users\\Admin\\Desktop\\434765";
            System.Windows.Forms.SendKeys.SendWait("^a");
            Thread.Sleep(2000);
            System.Windows.Forms.SendKeys.SendWait("{BACKSPACE}");
            Thread.Sleep(2000);
            System.Windows.Forms.SendKeys.SendWait(pathToFile);
            Thread.Sleep(2000);
            System.Windows.Forms.SendKeys.SendWait("{ENTER}");
            Thread.Sleep(3000);
            driver.Quit();
         
        }


2. Saving/Downloading Files:



static void Main(string[] args)

        {

            IWebDriver driver = new FirefoxDriver();
            driver.Manage().Window.Maximize();
            driver.Navigate().GoToUrl("http://www.seleniumhq.org/projects/webdriver/");
            Thread.Sleep(3000);
            System.Windows.Forms.SendKeys.SendWait("^s");
            Thread.Sleep(2000);
            String pathToSaveFile="C:\\Users\\Admin\\Desktop\\II";
            System.Windows.Forms.SendKeys.SendWait("^a");
            Thread.Sleep(2000);
            System.Windows.Forms.SendKeys.SendWait("{BACKSPACE}");
            Thread.Sleep(2000);
            System.Windows.Forms.SendKeys.SendWait(pathToSaveFile);
            Thread.Sleep(2000);
            System.Windows.Forms.SendKeys.SendWait("{ENTER}");
            Thread.Sleep(2000);
            System.Windows.Forms.SendKeys.SendWait("{ENTER}");
            Thread.Sleep(3000);
            driver.Quit();


        }


3.Printing Page:


class Program

    {
        static void Main(string[] args)
        {

            IWebDriver driver = new FirefoxDriver();
            driver.Manage().Window.Maximize();
            driver.Navigate().GoToUrl("https://www.newocr.com/");
            Thread.Sleep(3000);
            System.Windows.Forms.SendKeys.SendWait("^p");
            Thread.Sleep(2000);
            System.Windows.Forms.SendKeys.SendWait("{ENTER}");
            Thread.Sleep(3000);
            driver.Quit();
         
        }


By the above approach interaction with windows dialogue box /pop-up is handled properly with Selenium WebDriver.





Visit for More Automation Related Discussion:


https://www.youtube.com/channel/UCKSk4gkmO3LXcW17hFUkmcQ/videos




Thursday, 16 July 2015

Parallel Testing with Nunit for SpecFlow(Selenium C#)

Agenda for this blog: To achieve Parallel Testing using NUnit for SpecFlow- Cucumber for .NET.

Why we need parallel testing :  There are several use of Parallel testing,In case of Selenium, parallel testing gives us many benefits like:



    • Cross -browser testing.
    • Less execution time (as the script gets segregated )
    • Testing with Different platforms using GRID many more.


Does NUnit supports Parallel testing : The answer to this question in a single word is NO.
Till date it does not support parallel testing in true way ,but there are way we can achieve parallel execution with NUnit by creating category and with the help of NUnit console

How to Do:



  • Step1: Create category in Feature file:  In Spec-flow which is a BDD framework from Selenium C# we need to create feature file and write the test case in ENGLISH-LIKE language called Gherkin,there in every feature file we need to mention "@CategoryName"


NOTE: Here @CategoryName can be anything relevant like @SmokeTest or @RegressionTest or  @SuiteName.

                      Now when you build your project you can see category wise segregation in the  Test Explorer in Visual Studio.


  • Step2:  Create a Batch file and call project .dll(compiled code) file for test execution mentioning categories by using nunit-console like:



nunit-console /result:TestResults1.xml pathToDllFile /include:CategoryName1
nunit-console /result:TestResults2.xml pathToDllFile /include:CategoryName2
nunit-console /result:TestResults3.xml pathToDllFile /include:CategoryName3


You will able to see parallel execution by category wise with multiple browser instances.


Visit for More Automation Related Discussion:

https://www.youtube.com/channel/UCKSk4gkmO3LXcW17hFUkmcQ/videos






Monday, 13 April 2015

Selenium with OCR Technology for Image Verification With Text

Agenda for this blog:To discuss the verification of IMAGE in Selenium c# with the OCR technology.

What is OCR:Optical character recognition (OCR) is the mechanical or electronic conversion of images of typewritten or printed text into machine-encoded text.It is a common method of digitizing printed texts so that it can be electronically edited, searched, stored more compactly, displayed on-line, and used in machine processes.

Where and When OCR technology is required for Selenium:

When we are automating our application with Selenium and C# as a language.There  might be some scenario where we need to verify images,In this type of situation tampering images won't give good result,and also Selenium c# is not that much compatible with SIKULI which does a decent job for Selenium JAVA in this kind of image processing/verification etc etc. There OCR technology comes in to the picture which serves the purpose well.

What we can Do with OCR:
We can extract text from the images and can verify the same from our Selenium C# application Under test.

HOW:
           We need to download the required image locally and perform the action in following two ways:

A. Using "https://www.newocr.com/" we can upload the image and can extract the text from the image.

B. Using "tesseract-ocr"  we can achieve the purpose very well.


What is Tesseract-Ocr:

Tesseract is probably the most accurate open source OCR engine available. Combined with the Leptonica Image Processing Library it can read a wide variety of image formats and convert them to text in over 60 languages.

How: We need to install tesseract-ocr in our system and through cmd prompt we can extract text from the image.



Visit for More Automation Related Discussion:

https://www.youtube.com/channel/UCKSk4gkmO3LXcW17hFUkmcQ/videos






Saturday, 11 April 2015

SpecFlow-Cucumber for .NET & Selenium with C#

Agenda for this Blog: To discuss about SpecFlow which is Cucumber for .Net.

SpecFlow supports the concepts of Acceptance Test Driven Development (ATDD) and Behaviour Driven Development (BDD), which are often used synonymously filling the gap between domain experts and Developers by binding business readable behaviour specifications,it uses  Gherkin.

What is Gherkin:
Gherkin is the language that Cucumber understands. It is a Business Readable, Domain Specific Language that lets you describe software’s behaviour without detailing how that behaviour is implemented.

Gherkin Syntax example:

Feature: To Cover regression of some application
                and its business values
 
        Scenario:   To test the Login Scenario
          Given           User needs to be on the Login Page of the Application
          And               some other precondition
          When           enter text as Username and Password
          And               click on the sign in button
          Then             verification of the login (Such as Home page should be displayed)


Which Unit Test Provider is acceptable :

We can use Unit Test Provider  as per the  need and choice such as we can use NUNit,MsTest or we can use SpecRun along with SpecFlow to run our Test Scripts.


Unit Test Provider can be configured in app.config file in the Unit Test Project like:

<specFlow>
  <unitTestProvider name="SpecRun" />
</specFlow>


We need to create separate feature file and we need to use gherkin syntax there,we can generate the the step definition for the same and we need to incorporate the Selenium C# code for writing Test Script.

Sample for SpecRun Report:







Visit for More Automation Related Discussion:

https://www.youtube.com/channel/UCKSk4gkmO3LXcW17hFUkmcQ/videos

Friday, 20 March 2015

C#-Selenium Code Snippets

Agenda:
The agenda for this blog is to Discuss various scenario based concept and code used in C# Selenium.

Highlighting Web Element in Script Run-Time:
There are some Scenarios where we need to verify/Identify WebElements in the Page ,We can do them in multiple approaches,We can High Light the Element which we are looking for and set the color with different colors for that element , in the Test Run time so we can Identify/verify that the same:

public void HighlightToVerify(By locator)

        {
        try{
               string AttributeValue = "border:3px solid green;";
               string Attribute = Driver.FindElement(locator).GetAttribute("style");
IJavaScriptExecutor JsDriver = ((IJavaScriptExecutor)Driver);
JsDriver.ExecuteScript("arguments[0].setAttribute('style', arguments[1]);", Driver.FindElement(locator), AttributeValue);
               Thread.Sleep(100);
               JsDriver.ExecuteScript("arguments[0].setAttribute('style', arguments[1]);", Driver.FindElement(locator), Attribute);
           }
        catch(Exception){

             }
        }


SendKeys using JavaScript:

There are scenarios where we need to use JavaScript for Entering Text in the Input field,the same can be achieved in the following way:

public void SendData(By Locator, String Text, int TimePeriod = 30)
        {
            try
            {
                IJavaScriptExecutor js = ((IJavaScriptExecutor)Driver);
                js.ExecuteScript("arguments[0].innerHTML='" + Text + "';", Driver.FindElement(Locator, TimePeriod));
            }
            catch (Exception ex)
            {
                Log.Error("Unable to Enter Text using IJavaScriptExecutor for Element with Locator: "+Locator);
                
            }
        }



Presence Of Certain Text in The Page Source:

In some cases we need to check the presence of some text in the Page Source,Here we can achieve the same:

public bool IsTextPresentOnPage(String Text)

        {
            try
            {
                return Driver.PageSource.Contains(Text);
            }
            catch (Exception)
            {
                Log.Info("The Text "+ Text +"is not Present in the Page Source ");
                return false;
            }

        }



Zoom -IN and Zoom Out :


In Selenium you might face some issues like interacting with elements that goes under task bar due to improper layout. 



In this scenario WebElement will not be visible ,for this scenario you need to zoom out the page again zoom in once action is performed successfully :



class Program

    {
        static void Main(string[] args)
        {

            IWebDriver driver = new FirefoxDriver();

            driver.Navigate().GoToUrl("https://www.google.co.in/?gfe_rd=cr&ei=fxQ6VeiZNJTDuASzrYHQAg");
            driver.Manage().Window.Maximize();
            Thread.Sleep(3000);
            System.Windows.Forms.SendKeys.SendWait("^{ADD}");
            Thread.Sleep(3000);
            System.Windows.Forms.SendKeys.SendWait("^{SUBTRACT}");
            Thread.Sleep(3000);
            driver.Quit();

            

        }
    }

Download or Save Files :



In selenium sometimes we need to download or save files,we can achieve it by the below approach:


static void Main(string[] args)

        {

            IWebDriver driver = new FirefoxDriver();

            driver.Manage().Window.Maximize();
            driver.Navigate().GoToUrl("http://www.seleniumhq.org/projects/webdriver/");
            Thread.Sleep(3000);
            System.Windows.Forms.SendKeys.SendWait("^s");
            Thread.Sleep(2000);
            String pathToSaveFile="C:\\Users\\Admin\\Desktop\\II";
            System.Windows.Forms.SendKeys.SendWait("^a");
            Thread.Sleep(2000);
            System.Windows.Forms.SendKeys.SendWait("{BACKSPACE}");
            Thread.Sleep(2000);
            System.Windows.Forms.SendKeys.SendWait(pathToSaveFile);
            Thread.Sleep(2000);
            System.Windows.Forms.SendKeys.SendWait("{ENTER}");
            Thread.Sleep(2000);
            System.Windows.Forms.SendKeys.SendWait("{ENTER}");
            Thread.Sleep(3000);
            driver.Quit();

            


        }


Visit for More Automation Related Discussion:


https://www.youtube.com/channel/UCKSk4gkmO3LXcW17hFUkmcQ/videos






Gallio-Automation Platform with MbUnit- C#-Selenium

Agenda Of the Blog: Introduction of  Gallio -an open source platform for .NET,  which provides run-time services and tools.

What is Gallio?

The Gallio Automation Platform is an open, extensible, and neutral system for .NET that provides a common object model, run-time services and tools (such as test runners) that may be leveraged by any number of test frameworks.

Features and use of Gallio


·         Tools Support

·         Frameworks supported by Gallio: MbUnit, NUnit, MSTest, NBehave, XUnit
·         Different Gallio Runners: GUI (Icarus), Command-line (Echo) etc.

·         Gallio can be used for the multiple purposes:




Why to use Gallio for Automation Testing with Selenium C#:


To control and manipulate the Test execution approach:    To run the Selenium C# code we need to compile the full project and get the .dll file and we need to use that generated .dll file as a input to any Test Runner (framework) to execute the automation script, and Gallio serves the purpose in robust manner with multiple approaches, like:


(a)    Running all suites as a whole binding:

(i)      Whole automation Project can be run as a whole by using “Gallio Echo” Runner tool with .dll file as input to it. Detailed Reports are generated after the execution of whole Automation project with XML and HTML format.

(b)   Execution of All or Few selected Test Suites and Test cases:

(i)      We can perform selection of Test Suites and Test cases from whole Test Automation suites and execute them. This can be achieved by using “Gallio Icarus” Runner tool which is basically an UI, the generated .dll file has to be added through the UI “Add Files” option to use the Compiled project’s Test Case and, we can select all or few test suites and test cases from the UI tree format to execute. Please refer the below screenshot for the Gallio Icarus UI with Test Report.





(i)       Detailed Reports are generated and visible from the UI (in Execution Log tab) itself and we can see the report after the execution of test case, we don’t need to wait until the Whole suite execution.


(b)     Gallio can be integrated with Build Tool like NAnt to build the full automation process.

(c)     Gallio can be integrated with CI tool like Jenkins. 







What is MbUnit?


The MbUnit is an extensible unit testing framework for the .Net Framework. MbUnit is a part of the Gallio bundle. It provides below rich features apart from the other generic features which is available for any other unit test framework for .Net Framework:

1.       We can perform Parallel Testing with MbUnit for C# Selenium with multiple instances of the browser.

2.       MbUnit Supports Retry option which is basically automatic triggering of failed test cases for the next time.


Visit for More Automation Related Discussion:


https://www.youtube.com/channel/UCKSk4gkmO3LXcW17hFUkmcQ/videos




Thursday, 26 February 2015

Automation Testing Parallelism-Different Approaches

Agenda:Achieving parallelism with different Approaches.

How:We can achieve parallelism using multiple ways:


1. Through TestNg: Using Testng.xml we can achieve parallelism.


<suite name="Parallel test runs" parallel="tests" thread-count="2">


<test name="TestOne">

    <classes>
        <class name="com.sample.TestOneExample" ></class>
    </classes>
</test>

<test name="TestTwo">

    <classes>
        <class name="com.sample.TestOneExample" ></class>
    </classes>
</test>
</suite>

2. Through Maven and JUnit/TestNg: Using Maven and JUnit 4.7 onwards / TestNg you can run your tests in parallel with the help of surefire Plugin.For achieving this you must set the parallel parameter, and change the threadCount attribute in pom.xml. 


<plugins>

    [...]
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.18.1</version>
        <configuration>
          <parallel>methods</parallel>
            <threadCount>10</threadCount>
          </configuration>
      </plugin>
    [...]

</plugins>


3. Using Gradle:


Once we apply the Java plugin we can run our tests with the test task,we can also run tests in parallel though by default it runs sequentially.


We need to configure "maxParallelForks" property to more a number more than 1,By default its "1".

The "forkEvery" property specifies the maximum number of test classes to execute in a test process,so that your test process will not be using a very large heap,and can be restarted after it has executed specific number of test classes.The default is to execute an unlimited number of tests in each test process.


4. using MbUnit for C#-Selenium:


For .net Application while working with C# and Selenium if We use NUnit then we can not achieve Parallel Testing,so we can achieve parallelism using MBunit,which provides a way to run the Automation Scripts parallely  in the following way:


In the Assembly file we need to mention the below lines:


[assembly: DegreeOfParallelism(2)]

[assembly: Parallelizable(TestScope.All)]

Here "2" is the number of instances of browser.


5. Using NOSE for Python-Selenium:


In Order to run Test Parallel for Python -Selenium we can use nose:


After installing NOSE we can write the following :



nosetests --processes=2

this means you are going to run 2 tests at the same time. If you get TimedOutException  then you can increase the TimeOut  for the Process as:



nosetests --processes=2 --process-timeout=10000


By this way We can achieve parallel testing using Selenium and with Multiple Unit Test Frameworks.





Visit for More Automation Related Discussion:

https://www.youtube.com/channel/UCKSk4gkmO3LXcW17hFUkmcQ/videos




Saturday, 14 February 2015

WebDriverJS -Selenium Runner On Node with Promise Mechanism

Agenda Of the Blog: Introduction of  WebDriverJS (not WebDriver)-A Selenium Runner on Node

What is WebDriverJS: A selenium Runner on NODE,Highly extendible,compatible with all common JavaScript Testing Framework,hugely used for Angular JS application.

WebDriverJS & WebDriver are Same:NO.
The above two are related but not the same.

How both are related but not the same:
A. WebDriverJS is the JavaScript Language bindings for WebDriver,It runs on NODE,It uses an own chain API to execute and handle Asynchronous Calls in specific and in right order.

B.In Addition to NODE, WebDriverJS may also be used directly in the browser by JSonWire Protocol Communication as the Other Language binding of WebDriver(i.e Java,Python,Ruby etc. etc.).One of The Advantages for running WebDriverJS in the browser is that it can control the browser running the Script,as long as The URL for the server and Session ID for the browser are known.

C.Unlike other language bindings,which all provide blocking APIs,WebDriverJS is purely Asynchronous,In order to track handle exceptions WebDriverJS makes extensive use of "Promises."
While there are various promise implementations are there for JS,the WebDriverJS promise is based on the proposal from CommonJS,which defines a promise as any object with a "then" function property.

Asynchronous Computation:Its a concept of passing a callback function that is called when the result becomes available at some later time ,rather than a function returning a result value immediately.

Example:
Browser Offers a primarily single thread runtime environment,so if you request your browser to fetch some information which takes 3 seconds,then the browser will not be able to do anything else than to wait for HTTP call.

So, Asynchronous call came to the picture to overcome this kind of scenarios.

Concept of Promise:The promise object is used for deferred and Asynchronous computation.

A promise is in one of three different states:
1.Pending: Promise's initial state.
2.Fulfilled: Representing promise's state of successful operation.
3.Rejected: Represents promises's failed operation.

How WebDriverJS works with Asynchronous calls:
WebDriverJS uses a wrapper for Promise called ControlFlow Class

A.It maintains a list of scheduled actions
B.The exposed functions in WebDriverJS do not actually do their stuffs,they just push the required actions into ControlFlow Class.

Example:
With Simple WebDriver with Java we write :

driver.get("www.xyzabc.com");
driver.findElement(By.id("k1")).sendKeys("WebDriver");


Using Promise we need to write the same like:

driver.get("www.xyzabc.com").   then(function() {
     return driver.findElement(By.id("k1"));
   }).
   then(function(k1) {
     return k1.sendKeys("WebDriver");   }).


By this way WebDriverJS is related with WebDriver,uses Promise,JSON Wire Protocol and handles Asynchronous Calls very efficiently.



Visit for More Automation Related Discussion:


https://www.youtube.com/channel/UCKSk4gkmO3LXcW17hFUkmcQ/videos



Sunday, 8 February 2015

GEB-Page Object Modelling with Power Of Selenium WebDriver and Groovy's expressiveness

                            
Agenda of this Blog: Introduction of GEB as a Solution of Browser Automation.

What is GEB: GEB is browser automation solution,which is a wrapper over Selenium WebDriver. It uses:


1. groovy's expressiveness to deal with the Browser Automation.
2. JQuery to deal with the WebElements.
3. Robust Page Object Modelling  Framework.

It can be Integrated with different Unit Test Framework such as JUnit,TestNg,Spock as well as different build tools like Maven,Gradle and CI tool like Jenkins.

Is it Really Useful when we have Selenium for Automation :
The answer to the above is YES, because it comes with few very good features along with it.

1. GEB uses Groovy language which itself is very powerful having features like Closure, GroovyMarkup and GPath support,dynamic and static typing is supported and many more.
2.As it is supported by Groovy,so less coding is required to write automation scripts compared to JAVA.
3. GEB supports JQuery to handle WebElements,so Scripts become more faster.
4.Asynchronous Content Lookup.
5.Selenium API can be used easily if need arises.

Structure of  Framework:

If we are using GEB then generally we follow 3 main building blocks of it:
1.Module:Where we keep our WebElements/Locators/JQuery Contents as static contents.
2.Pages:Place for the re-usable methods of Page/Module functionalities .
3.Specs: Where the Test Classes are kept.

Please refer the below screenshot for the Core framework structure.






Sample of Module given below:




Sample for Page :




GEB provides few methods like "at" which is used to verify whether we are on the stated page or not and "to" method to redirect the driver to the stated page.
If we are in certain page then to access the reusable methods of that page class i.e Page Functionalities we Don't need to create Object for that class,we can simple call the method.

Sample of a Test method :




Geb can be very effective and robust as a solution to the browser Automation.



Visit for More Automation Related Discussion:

https://www.youtube.com/channel/UCKSk4gkmO3LXcW17hFUkmcQ/videos