Golem.WebDriver, Getting Started - ProtoTest/ProtoTest.Golem GitHub Wiki

===== ###Guide Navigation

  1. Overview
  2. Test Creation
  3. Test Configuration
  4. Test Execution

=====

###Selenium WebDriver C# Framework

Selenium WebDriver is collection of language specific bindings used to drive browser actions natively the way a real user would. Combined with the Golem’s Core functionality, you now have a powerful tool to create and execute robust, browser-based test automation scripts.

By default, the framework will automatically launch Firefox on your local browser before each test, and instantiates a WebDriver instance. The Config class or an App.Config file can be used to control which browsers are used during testing.

Golem includes a variety of features that can globally enabled for every test. For example, having each WebDriver command written to the test log.

=====

###Creating a Test

Test classes are C# classes which contain test methods.

To write a test using Golem, create a test class that inherits WebDriverTestBase, and and mark test methods with the [Test] attribute. The WebDriverTestBase takes care of configuring the test case and managing the Selenium WebDriver and browser lifecycles. See "Configuring Tests" below.

An example test class looks like:

using MbUnit.Framework;
using OpenQA.Selenium;

namespace ProtoTest.Golem.Tests
{
   class Test : WebDriverTestBase
   {
      [Test]
      public void TestGoogle()
      {
         driver.Navigate.GoToUrl("http://www.google.com/");
         var searchField = driver.findElement(By.Name("q"));
         searchField.SendKeys("ProtoTest");
      }
   }
}

In addition, the framework is built to support the page object design pattern. For an example of how to write a page object class, see the GoogleHomePage class within the Golem tests directory.

Here's an example of a test built on top of the GoogleHomePage class:

using MbUnit.Framework;
using ProtoTest.Golem.Tests.PageObjects.Google;
using ProtoTest.Golem.WebDriver;

namespace ProtoTest.Golem.Tests
{
    class Test : WebDriverTestBase
    {
        [Test]
        public void TestGoogle()
        {
            OpenPage<GoogleHomePage>("http://www.google.com/")
               .SearchFor("Selenium")
               .VerifyResult("Web Browser Automation");
        }
	}
}

=====

Configuring Tests

Through an App.Config:

  • Add an "Application Configuration File"
  • Edit the App.config -> Set browser using key “Browser1” value=”Firefox”
<?xml version="1.0"?>
<configuration>
  <appSettings>
    <add key="Browser1" value="Firefox"/>
   </appSettings>
</configuration>
  • Execute Test - Should open Firefox instead of Chrome
  • Supports Firefox, Chrome, IE, Safari, HtmlUnit, and Android (remote only)

Through code:

Any Config value can be set either in the App.Config file, or directly in code. This means you can override the global setting temporarily, and change it back later.

[FixtureInitializer]
        public void init()
        {
            Config.Settings.httpProxy.startProxy = false;
            Config.Settings.httpProxy.useProxy = false;
        }

=====

Executing a Test

From Within Visual Studio:

  • TestDriven.net plugin is required
  • Right Click on Test > Run Test (Should open browser and close it)
  • Right Click on Class or project to run all tests within

From Gallio Icarus:

  • Open Gallio Icarus
  • Click "Add" and navigate to our ProjectName.dll file located in the /bin/release or /bin/debug/ directory
  • Select tests to execute
  • Click Run

####Executing on a Remote Computer:

  • Modify App Config, set host to IP or Hostname of remote computer
<?xml version="1.0"?>
<configuration>
  <appSettings>
    <add key="Browser1" value="Chrome"/>
    <add key="RunOnRemoteHost" value="True"/>
    <add key="HostIp" value="10.10.1.151"/>
   </appSettings>
</configuration>

####Desired Capibilities

  • Can be passed in as a single string via app.config. The format is : "key1=value1,key2=value2,..."
<?xml version="1.0"?>
<configuration>
  <appSettings>
    <add key="Browser1" value="Chrome"/>
    <add key="Browser1Capibilities" value="version=35,platform=Windows 8"/>
    <add key="RunOnRemoteHost" value="True"/>
    <add key="HostIp" value="10.10.1.151"/>
   </appSettings>
</configuration>