How to Configure Browsers in Ocaramba Using appsettings.json
Set the appSettings:browser key in your appsettings.json file to a valid BrowserType enum value such as Chrome, Firefox, or RemoteWebDriver, and Ocaramba's BaseConfiguration.TestBrowser property will automatically instantiate the correct driver at runtime.
The Ocaramba test automation framework, maintained by Accenture, simplifies cross-browser testing through JSON-based configuration. To configure browsers in Ocaramba using appsettings.json, you modify the browser key under appSettings, which the framework reads via the BaseConfiguration class. This approach eliminates hardcoded driver instantiation and enables environment-specific testing strategies without recompiling your test suite.
Understanding the Configuration Architecture
The BaseConfiguration Class
The central configuration hub resides in OcarambaLite/BaseConfiguration.cs. The static property TestBrowser (lines 72-78) retrieves the browser identifier from the configuration builder using the key appSettings:browser:
public static BrowserType TestBrowser
{
get
{
string setting = Builder["appSettings:browser"];
Logger.Trace(CultureInfo.CurrentCulture,
"Browser value from settings file '{0}'", setting);
return Enum.TryParse(setting, out BrowserType browserType)
? browserType
: BrowserType.None;
}
}
Configuration Builder Setup
The ConfigurationBuilder instance (lines 49-52) merges the base appsettings.json with environment-specific overrides:
public static readonly IConfigurationRoot Builder = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", true, true)
.AddJsonFile($"appsettings.{Env}.json", true, true)
.Build();
Supported Browser Types in Ocaramba
The BrowserType enum defines all supported driver configurations. Valid values for the browser key include:
- Chrome – Local Google Chrome instance (default)
- Firefox – Local Mozilla Firefox with optional profile support
- Edge – Local Microsoft Edge browser
- RemoteWebDriver – Selenium Grid or custom remote hub
- BrowserStack – Cloud testing via BrowserStack infrastructure
- Appium – Mobile device testing through Appium server
- None – Fallback when no browser is configured
How to Configure Browsers in appsettings.json
Local Browser Configuration
For local execution, set the browser value to Chrome or Firefox. Create an appsettings.json file in your test project root:
{
"appSettings": {
"protocol": "http",
"host": "the-internet.herokuapp.com",
"browser": "Chrome",
"url": "",
"RemoteWebDriverHub": "http://localhost:4444/wd/hub"
}
}
To switch to Firefox, change the value and optionally specify a profile path:
{
"appSettings": {
"protocol": "http",
"host": "the-internet.herokuapp.com",
"browser": "Firefox",
"PathToFirefoxProfile": "C:\\Users\\Me\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\default",
"RemoteWebDriverHub": "http://localhost:4444/wd/hub"
}
}
Remote WebDriver and Selenium Grid Setup
For Selenium Grid execution, use RemoteWebDriver and specify the hub URL:
{
"appSettings": {
"protocol": "http",
"host": "the-internet.herokuapp.com",
"browser": "RemoteWebDriver",
"RemoteWebDriverHub": "http://grid.mycompany.com:4444/wd/hub",
"DriverCapabilities": "Chrome"
}
}
The DriverCapabilities key determines which browser the grid node will launch.
Cloud Testing with BrowserStack
Configure BrowserStack by setting the browser type and hub endpoint:
{
"appSettings": {
"protocol": "https",
"host": "the-internet.herokuapp.com",
"browser": "BrowserStack",
"RemoteWebDriverHub": "http://hub.browserstack.com/wd/hub"
}
}
Ocaramba retrieves your BrowserStack credentials from the environment variables BROWSERSTACK_USERNAME and BROWSERSTACK_ACCESS_KEY.
Environment-Specific Overrides
The framework supports environment-specific configuration files. Create appsettings.Linux.json (or match your ASPNETCORE_ENVIRONMENT value) to override base settings:
{
"appSettings": {
"browser": "Chrome",
"PathToChromeDriverDirectory": "/usr/local/bin"
}
}
When ASPNETCORE_ENVIRONMENT is set to Linux, the ConfigurationBuilder automatically merges this file with the base appsettings.json.
Key Configuration Files Reference
Understanding the source structure helps when troubleshooting configuration issues:
| File | Purpose | Location |
|---|---|---|
BaseConfiguration.cs |
Contains TestBrowser property and ConfigurationBuilder logic |
OcarambaLite/BaseConfiguration.cs |
appsettings.json |
Default local browser settings | Ocaramba.UnitTests/appsettings.json |
appsettings.json |
BrowserStack cloud configuration example | Ocaramba.Tests.BrowserStack/appsettings.json |
appsettings.json |
Cross-browser grid testing setup | Ocaramba.Tests.CloudProviderCrossBrowser/appsettings.json |
appsettings.json |
Mobile testing via Appium | Ocaramba.Tests.Appium/appsettings.json |
Summary
- Primary configuration key: Set
appSettings:browserinappsettings.jsonto control which driver Ocaramba instantiates. - Supported browsers: Chrome, Firefox, Edge, RemoteWebDriver, BrowserStack, and Appium are all valid
BrowserTypeenum values. - Environment flexibility: Use
appsettings.{Env}.jsonfiles to override settings for different operating systems or deployment targets without code changes. - Source reference: The
BaseConfiguration.TestBrowserproperty inOcarambaLite/BaseConfiguration.cshandles all runtime browser resolution.
Frequently Asked Questions
What is the default browser if I don't specify one in appsettings.json?
If the browser key is missing or contains an invalid value, the BaseConfiguration.TestBrowser property returns BrowserType.None. This typically causes the test initialization to fail unless your code explicitly handles the None case. Always ensure the browser value matches a valid enum name such as Chrome or Firefox.
Can I run tests on multiple browsers without changing the JSON file?
Yes. While the static TestBrowser property reads from configuration at startup, you can override the browser selection programmatically by manipulating the BaseConfiguration.Builder or by using environment-specific JSON files. For true multi-browser execution in a single test run, consider using the Ocaramba.Tests.CloudProviderCrossBrowser approach, which iterates over multiple capability sets defined in configuration.
How do I configure ChromeDriver or GeckoDriver paths in appsettings.json?
Use the PathToChromeDriverDirectory or PathToFirefoxDriverDirectory keys under appSettings. For example, setting "PathToChromeDriverDirectory": "/usr/local/bin" tells Ocaramba where to locate the chromedriver executable. This is particularly useful for Linux environments or when drivers are not in the system PATH.
Does Ocaramba support headless browser configuration through appsettings.json?
While the browser key accepts standard browser names, headless mode is typically controlled through driver-specific capabilities or options classes in your test code. However, you can influence driver behavior by setting the DriverCapabilities key when using RemoteWebDriver, which passes the specified capabilities to the grid node. For local headless execution, you would typically extend the driver initialization logic to append --headless arguments based on a custom configuration flag.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →