Tutorials

Tutorials

A Minimal OttoMagic Smoke Test

The smallest possible OttoMagic workflow: turn on the engine, launch a maximized Chrome browser, navigate, and close. Useful as a first check that OttoMagic is installed and wired up correctly before building anything more elaborate on top of it.

Complete Program

Here's the whole workflow, start to finish. Each piece is broken down and explained below.

using GenerallyPositive;

using GenerallyPositive.Browser;

using static GenerallyPositive.Enums;

GPAL

.WithUseOttoMagic(@"C:OttoMagic")

.WithPublishToConsole();

IBrowser browser = GPAL.Browser

.WithBrowserType(BrowserType.Chrome)

.WithUseAutomationEngine(AutomationEngine.OttoMagic)

.Maximize

.ToGPALObject();

browser.GoTo("www.example.com");

browser.Close(true);

Turn On OttoMagic Globally

WithUseOttoMagic points GPAL at your OttoMagic install directory. This is a global setting - set it once before building any browsers, and every browser that asks for AutomationEngine.OttoMagic (or OttoMagicHW) will use that install.

GPAL

.WithUseOttoMagic(@"C:OttoMagic")

.WithPublishToConsole();

TIP

WithUseOttoMagic lives at the global GPAL level, not on an individual browser. If you create several browsers in the same run, they all share the OttoMagic install path you set here. See Configuration Hierarchy.

Build a Maximized OttoMagic Browser

WithUseAutomationEngine(AutomationEngine.OttoMagic) tells this specific browser to drive itself through OttoMagic rather than Selenium or Puppeteer. Maximize is a fluent property - chain it onto the builder before ToGPALObject() and the window opens full-size instead of at its default dimensions.

IBrowser browser = GPAL.Browser

.WithBrowserType(BrowserType.Chrome)

.WithUseAutomationEngine(AutomationEngine.OttoMagic)

.Maximize

.ToGPALObject();

TIP

Everything below ToGPALObject() works the same regardless of which AutomationEngine you picked - GoTo, Close, and the rest of the IBrowser surface don't change. See Automation Engines.

Navigate and Close

GoTo opens the URL in the visible browser window. Close(true) shuts down the underlying driver process once the test is done.

browser.GoTo("www.example.com");

browser.Close(true);

WARNING

Passing true kills the running driver process for this browser. If a smoke test like this passes - the window opens, the page loads, and it closes cleanly - that's a good sign your OttoMagic install path and driver setup are correct.

About the Real Test Program

The actual MagicTester project in the repo wraps this same workflow in nested loops over BrowserType, AutomationEngine, and headless/headful mode, skipping combinations that don't apply, so it can regression-test every valid OttoMagic configuration in one run. The single-pass version above is what each iteration of that loop boils down to.

TIP

When you see a test program in the repo iterating over BrowserType and AutomationEngine with switch statements that mostly continue, it's testing every valid browser/engine/headless combination for regression purposes - not something you need in a normal workflow. See Automation Engines.