Wednesday, 25 October 2017

Launch Microsoft Edge Browser in Selenium 3


Edge Browser in Brief:  Edge Browser is coming as an inbuilt browser with Microsoft Windows 10 Operating System. Prior to this, Microsoft was providing Internet Explorer Browser up to windows 7. Internet Explorer was not in competition with other browsers like Google Chrome, Mozilla Firefox etc. These browsers were very flexible, fast; good look and feel and also they are supporting lots of add-ons, which make user life very easy while working. Because of this growing competition Microsoft also decided to move on something, which will be rich in features and at the same time very easy to use. So they decided to come up with Microsoft Edge browser. This Edge browser is comparatively good looking and fast compare to Internet Explorer.
Since there is a rise in demand to automate a web application on different platforms and in different browsers Microsoft Edge browser is becoming very popular. To perform these cross-browser automation testing we need the following software. This software would help to launch the application in Microsoft Edge Browser and to perform various automation activities on the web application based on the requirements.
1.    Software Required: 
a)     Sharp Develop 5.1.0.5216
b)     C# Selenium Web Driver Client (3.6.0)
c)     Microsoft Web Driver
d)     Microsoft Edge Browser with Windows 10 operating system

2.    Configure Selenium in Sharp Develop IDE:
a) Follow the link and download Sharp Develop IDE http://filehippo.com/download_sharpdevelop/
    

  b) Go to the download location and double-click on Sharp Develop setup.exe file and click Next.

 c) Accept the License Agreement and keep on clicking Next until installation gets finished.


 d) Once the Installation gets over then launch the IDE. Click on New Solution and try to create the project.


  e) Select category as Windows Application and then select Console Application. Enter Name and Location where the project will get created and then click on Create.

 f) Once the project got created, the screen will be populated with some code as shown below.

g) In Sharp Develop IDE go to Project-> Manage Packages and enter Selenium in the search box and hit Enter. 
h) Select all the marked packages as shown in the image and add them to your project. 
i) Once again go to Project->Manage Packages and enter Microsoft Driver and Search. Add the selected package to the project as shown in the image.

j) Type following codes and save it.
using System.Threading;
using OpenQA.Selenium;
using OpenQA.Selenium.Edge;
using System;
using System.Linq;

namespace SeleniumBasics
{
    class Programs
    {
            
       static void Main(string[] args)
       {
              // Instantiating WebDriver
              IWebDriver driver = new EdgeDriver();
      
           //MAXIMIZE THE BROWSER
           driver.Manage().Window.Maximize();

           //Enter the URL
           driver.Navigate().GoToUrl("https://www.google.co.in/");
    
           //Refresh the browser
           driver.Navigate().Refresh();
    
           //Wait for few seconds
           Thread.Sleep(10);
    
           //Close the browser
           driver.Quit();

       }

    }
}
k) Now you are ready to launch Microsoft Edge Browser. Click on Run button and it should launch Edge browser with google homepage.
I hope you would find this article simple and helpful if you are a beginner in C# automation. I also hope that this article would have helped you to do all the required setup to kick start with Selenium first script i.e. launching the browser this tutorial. In my next article, I will discuss how to add Selenium without using NuGet Package Manager. I will be coming with my new article very soon. Till then bye.
I would appreciate your comments. You can contact me anytime through email at jharakesh1991@gmail.com.

Configure Selenium In Visual Studio Using NUget


An Introduction to Selenium WebDriver: WebDriver is an open source automating web application testing tool which is very popular in software testing field right now.
This provides APIs that easily integrate with any programming language such as C#, Java, Python. In simple words, it is an API that’s easy to explore and understand, which help us to make our tests easier to read and maintain.” The use of Selenium WebDriver is to basically test any web application.
Features of Selenium WebDriver:
A well-designed Object-Oriented API that provides improved support for web-app testing problems.
Supports dynamic web pages where the element of a Page may change without the Page itself being reloaded.
All the limitations of SELENIUM RC rectified in this Selenium WebDriver
It supports all the major programming and scripting languages like Java, C#, Python, Ruby, PHP, Perl and JavaScript.
It also supports all the major and popular browsers available in the market like Google Chrome, Mozilla Firefox, Safari, Opera, Internet Explorer.
Selenium WebDriver supports multiple platforms to test web application like Windows, Mac, Linux, IOS, Android.

An Introduction to C#: C# is an Object-Oriented Language, introduced in the .NET framework developed by Anders Hejlsberg as a Microsoft initiative to develop a Common Language Interface environment. C# is a Simple, Powerful, general purpose and Type-Safe language.
We can develop C# projects in Visual Studio Environment, a powerful tool-rich programming environment from Microsoft. We can create console based applications as well as windows based applications from the C# environment. C# Coding style is very similar to C++ and JAVA so the developers who are familiar with those languages can pick up C# coding quickly.



Software Required: 

Visual Studio (Preferably 2013 or higher version)
C# Selenium WebDriver Client (2.53)
C# NuGet package manager
Chrome Driver.exe to launch Chrome Browser
IE Driver.exe to launch Internet Explorer Browser

Steps to Download Visual Studio Community
Visit the below mentioned link and download Visual Studio 2015 community edition as shown in screenshot https://www.visualstudio.com/enus/downloads/download-visual-studio-vs.aspx.


Save the .exe file that needs to install and configure Visual Studio 2015 Community edition.



 Steps to Install Visual Studio Community
Double click on the saved file to start the installation.


Click on the Run button.



Click ‘Install. Be sure to read and agree to the License Terms and Privacy Policy.

Note: Change the default location if you like to and let the ‘Type of Installation’ be default as Typical, unless you know what you are doing.
Wait for the install to complete.

Note: Installation would take around 10 to 15 mins.
Click on Launch button to start the Visual Studio.



Steps to Create a New Project
1) Click on New Project.

 2)  Select Visual C# from the left, then select Console Application from the middle. It will give the option to mention the Project name, location & solution name. Give the sensible name to the project, just for the sake of simplicity, enter ProjectQA and give the preferred location to the project. Click on OK button to proceed.

Note: Let the solution name be same as FirstSeleniumProgram.
Now you will end up with the below screens on your machine.

 

Steps to add Selenium .dll files to the new project
1) Right click on Solution Name on right-hand side panel and select Manage NuGet Package Manager as shown in screenshot

2) Nuget Package Manager Screen will be displayed. Notice under installed tab “No Package “text. It means nothing has been added from Nuget package manager to this project.



3) Click on Browse tab and you will notice all the popular packages available as shown in screenshot.

Type selenium in the search box and hit Enter. You will find all the Selenium related packages available in NuGet Package Manager. You need to install all the packages present under yellow boundary as shown in the screenshot in order to run your first selenium script.

 


Click on one of the package just say Selenium Webdriver, then click on install button. Next click on Ok button in next pop up window. Follow the same for other packages too.

  



Once you will click on Ok button, NuGet Package Manager will start installing Selenium Web driver for your project as shown in screen shot. Notice output window in your visual studio. It is saying Selenium Web driver has been installed with all the details like URL, version, time etc.

 



After installing all the packages as mentioned in step 4, Click on Installed tab once again. This time you will see all the installed packages are listed there.

 



To verify whether Selenium Web Driver has been installed or not. Notice the solution pane on right hand side where you will notice Web Driver and Web Driver Support packages are attached with your project or solution. For details see attached screenshot.

 



To launch the Firefox browser and navigate to a URL, write below code in your program.cs (Note file name can be anything. It’s your wish what name you choose.). I have used default program file created by VS 2015.

using System;
using OpenQA.Selenium.Firefox;

namespace FirstSeleniumProgram
{
    public class Program
    {
        public void LaunchBrowser
        {
            // 1. Launch Firefox Browser
            FirefoxDriver firefox = new FirefoxDriver();

            // 2. Go to Google Home Page

            firefox.Url = "https://www.google.co.in";

            // 3. Print Page Title

            Console.WriteLine("Page Title is {0}", Firefox. Title);

            // 4. Print Current URL Open in Browser

            Console.WriteLine("Current URL is {0}", firefox.Url);

            // 5. Print Length of the page Source Code

            IWebElementl length=firefox.PageSource.Length);

            Console.WriteLine("Page Contains {0} characters in it", length.

            // 6. Close the Browser

            firefox.Quit();

            // ALTERNATE of Step 6
            // firefox.Close();
        }

    }
}


I hope you would find this article simple and helpful if you are beginner in C# automation. I also hope that this article would have helped you to do all the required setup to kick start with Selenium first script i.e. launching the browser this tutorial. In my next article, I will discuss how to add Selenium without using NuGet Package Manager. I will be coming with my new article very soon. Till then bye.
I would appreciate your comments. You can contact me any time through email at jharakesh1991@gmail.com.

Appium Chapter-3: Understanding the Desired Capabilities

  Desired Capabilities help us to configure the Appium server and provide the criteria which we wish to use for running our automation scrip...