Skip to content
Lucas edited this page Apr 8, 2021 · 3 revisions

All usages will be using the Microsoft Edge Web Driver unless otherwise specified.

Basic

Creating a new page collection is the entry point for all things AutoWeb. The code below will create a new page collection in which you can add pages or manage the browser driver directly.

var site = new PageCollection();

You can add pages to the collection and when you are ready to execute them you can either call Execute on all pages in the collection or select an individual page to execute.

The following code will: Add the pages and execute them (sequentially) until the last one unless it fails.

site.AddPage<LoginPage>();
site.AddPage<RepositoryPage>();
site.Execute()

The following code will: Execute ONLY the LoginPage and nothing else.

site.Execute<LoginPage>();

You may also execute everything in one command if required. The following code will do everything mentioned above in one clean command.

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

Options

Using one of the example above you can configure the PageCollection with custom options as you see fit.

var site = new PageCollection(options => 
{
    // Sets the browser type and the path of where the driver is located.
    // Default: msedgedriver.exe
    options.Browser<IBrowser>()
    
    // At times the driver will remain running in the background, this will
    // attempt to clear them before starting a new one.
    options.CleanOrphanedDrivers = true
});

Browser Options

options.SetBrowser<IBrowser>(Action<BrowserOptions> options)

There are two ways to use the SetBrowser method inside the PageCollectionOptions. Which one you use depends on what you want to change.

The easy way that lets you specify a custom driver with the other settings as default. More overloads will be added with time that allows to configure without having to specify the driver information and keep the default.

var site = new PageCollection(options => 
{
    // Changes the browser to chrome and specifies the path to the driver.
    options.Browser<ChromeBrowser>("chromedriver.exe")
});

The more robust way which allows you to change all settings for the browser. If using this method you will need to specify Browser<EdgeBrowser> if you want to remain using the default browser. This will be made easier in a future update.

var site = new PageCollection(options => 
{
    options.Browser<ChromeBrowser>(opts => {
        // The path to the driver you want to use.
        opts.Driver = "chromedriver.exe";

        // The timeout to use for each page. This can be specified for each page if required.
        // Default: new TimeSpan(0, 0, 10)
        opts.Timeout = new TimeSpan(0, 0, 10);

        // Browser arguments that are used when executing the browser itself. For example "--headless"
        // Default: new string[] { }
        opts.Arguments = new string[] {
            
        };


    })
});
Clone this wiki locally