Skip to content

lzinga/AutoWeb

Repository files navigation

AutoWeb

Created by: Lucas Elzinga

This library wraps the Selenium library into an easy to use library for any automated tasks you may require in the browser.

Why?

There were many times I wanted to create a quick project that would automate a process I do often, or tasks that are cumbersome and annoying. However from my experience Selenium had quite a bit of overhead and can feel clunky/messy if you wanted to spin up something quickly. So here we are.

As an example I have to open tickets in part of my job in a system that is not user friendly, does not give access to API, nor was it built with my group in mind. Alas we are still required to open tickets in said system. So... I will be using this library to automate the process to be much simpler and quicker for my team. I leave you with the hopes that this library can help in some way or another.

Quick Links

  1. Wiki Documentation

Usage

Only basic usage is the readme, view the wiki for more detailed information.

To properly load and open a browser you will need to include a web driver, by default AutoWeb uses Selenium.WebDriver.MSEdgeDriver as the default driver but you can view the [#tested-browsers](Tested Browsers). I have not tested with other browsers but it should be possible with some slight modifications.

AutoWeb uses a PageCollection object to add and manage your pages.

// Creates a default page collection. (uses msedgedriver)
new PageCollection();

// Creates a page collection with configured options.
new PageCollection(options => {

    // Option #1
    // Option to specify a different browser.
    options.Browser<IBrowser>("chromedriver.exe")

    // Option #2
    // Option to specify all options for the browser
    options.Browser<ChromeBrowser>(opts => {
        opts.Driver = "chromedriver.exe";
        opts.Timeout = new TimeSpan(0, 0, 30);
        opts.Arguments = new string[] {
            "--headless"
        };
    });

    // At times the driver will remain running in the background, this will
    // attempt to clear them before starting a new one.
    options.CleanOrphanedDrivers = true,
});

Once created you can add pages later or directly off the new object itself. Either of these methods are fine.

new PageCollection()
    .AddPage<LoginPage>()
    .AddPage<RepositoryPage>();

var pages = new PageCollection();
pages.Add<LoginPage>();

Once you have pages added to your collection you can execute them individually, or all in the order they were added.

// This will execute all pages starting at LoginPage and continuing to RepositoryPage
new PageCollection()
    .AddPage<LoginPage>()
    .AddPage<RepositoryPage>()
    .Execute()

// If executing against the variable itself you can execute a singular page.
pages.Execute<LoginPage>();

Fluent Control

When writing automation for a page things can get messy pretty quickly if the website has you jump around a lot. You can chain commands like in the example below.

browser.FindElement(Where.XPath, "//*[@id='sp_formfield_search']")
    .SendKeys("TicketVM01")
    .Wait(1000)
    .ThenFindElement(Where.XPath, "//*[@id='Add']/div/span/div/div/div[2]/input[2]")
    .Click();

Supported Drivers

The following browser drivers have been tested and currently built into unit tests.

  1. Selenium.WebDriver.MSEdgeDriver
  2. Selenium.WebDriver.ChromeDriver