Browse Month: May 2013

Google Chrome and ChromeDriver with Selenium

Google Chrome and ChromeDriver with Selenium

Before going in details about google chrome and ChromeDriver lets learn some terminology.

Wire Protocol: defined as RESTful web services using JSON over HTTP that is being used by webdriver/RemoteWebDriver, to communicate with browser.

ChromeDriver is a standalone server developed by Chromium team(Google) which implements wire protocol.
ChromeDriver consist of three separate pieces,
a. Chrome Browser.
b. Selenium Project code (driver) AND
c.  An Executable that helps code to communicate with chrome browser (lets call it server for ease)

server expects you to have chrome installed in the default location of computer.

Before start, make sure that you add the location of ChromeDriver.exe aka server into the PATH system variable so you do not need to specify during the execution.
WebDriver driver = new ChromeDriver();
WebDriver driver = new ChromeDriver(“PATH To ChromeDriver.exe”);

if you execute your test with ChromeDriver, you will notice that server will start and shut down when driver.quit is being called. server is small and light weighted but this will start and stop every time while executing multiple tests which may add noticeable delay to a larger test suite. To handle this, you can control the life and death of the server by ChromeDriverService.

1. Start ChromeDriverService in [TestFixtureSetup] before any test starts.
service = ChromeDriverService.CreateDefaultService();
service.Start();
option = new ChromeOptions();

2. Stop this service in [TestFixtureTearDown] once all test suite executed.
service.Dispose();

Full Code:

using System;
using System.Linq;
using System.Text;
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;
using OpenQA.Selenium.Chrome;
namespace NUnitTest1 {
    [TestFixture]
    public class TestBasicSteps {
        OpenQA.Selenium.IWebDriver driver = null;
        ChromeDriverService service = null;
        ChromeOptions option = null;
        [TestFixtureSetUp]
        public void TestFixtureSetup() {
            service = ChromeDriverService.CreateDefaultService();
            service.Start();
            option = new ChromeOptions();
			}
        [SetUp]
        public void setup() {
            driver = new ChromeDriver(service, option);
			}
        [Test]
        public void TestCase1() {
            driver.Navigate().GoToUrl("http: //www.google.com");
            System.Threading.Thread.Sleep(5000);
			}
        [Test]
        public void TestCase2() {
            driver.Navigate().GoToUrl("http: //learnseleniumtesting.com");
            System.Threading.Thread.Sleep(5000);
			}
        [TearDown]
        public void CleanUp() {
            driver.Quit();
            }
        [TestFixtureTearDown]
        public void dispose() {
            service.Dispose();
            }
        }
    }

Known Issue:

Typing does not work with rich-text enabled page.
Cannot specify a custom profile.
HTML 5 API not implemented yet.

Working with Firefox Profile

Firefox Profile:

Firefox profile is a special folder where you actually save all your settings and configurations like bookmarks, your homepage, your extensions which you installed on your Firefox. Your profile folder is kept in a separate folder so in case if anything goes wrong with your FFox you will not lose your data. To check the folder in your computer, type “about:support” in your address bar without double quote or Click on Troubleshooting Information in Help Menu. Firefox will load all information related to the profile. You will find a button in Application Basic table which will take you to the profile folder.

How to create a new one:

Go to Run (Window+R) and type following: (make sure no Firefox instance opened) image ORprofile Click OK that will take you to the following screen. image Click on Create button that will take you following screen. image image You can choose the name of new Profile says AutomationTestFireFoxProfile and select the profile location says D:\ProfileForAutomation image Click on finish and your new profile will create. As below: image Now you can start the browser with one of them. In the newly created folder you can add various settings, save password or you can add plugins also which will be ready for you. You can launch FirefoxDriver using this one so you temporary profile will not create in your temp folder and you driver browser will have all kind setting and plugin will be there to debug your test.



Notice: Undefined variable: font_family in /home/chyqruxavcln/public_html/learnseleniumtesting.com/wp-content/plugins/gdpr-cookie-compliance/moove-modules.php on line 282