Skip to content

Commit

Permalink
add browser to system properties (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sérgio Martins committed Apr 18, 2020
1 parent e227508 commit b8c9994
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
19 changes: 11 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,36 +39,39 @@ The goal is to build a solid and generic foundation so that Test Automation Engi
* _[WebDriverManager](https://github.com/bonigarcia/webdrivermanager)_ - Downloads the required driver during runtime. May be configured on `DriverContext` under `/base`
* _[MockServer](https://www.mock-server.com/) 🐳_ - Enables the ability to mock _http_ requests and responses (check [mocking](#mocking-requests-and-responses) section)
* _[ExtentReports](https://extentreports.com/)_ - Provides full test reports. Takes screenshots upon test failure by default (check [reports](#reports) section)
* _[Sonarqube](https://www.sonarqube.org/) 🐳_ - A static analysis tool. Executable through `$ mvn sonar:sonar -Dsonar.host.url=http://<<docker_ip>>:9090`
* _[SonarQube](https://www.sonarqube.org/) 🐳_ - A static analysis tool. Executable through `$ mvn sonar:sonar -Dsonar.host.url=http://<<docker_ip>>:9090`
* _[SeleniumGrid](https://github.com/SeleniumHQ/docker-selenium) 🐳_ - Allows to scale the test executing as well as providing the required browser types
* _[Checkstyle](https://maven.apache.org/plugins/maven-checkstyle-plugin/)_ - Code linter. Executable through `$ mvn validate`

> _🐳 stands for currently dockerized_
> _🐳 stands for dockerized_
## Getting Started

```shell script
$ git clone https://github.com/sergiomartins8/ui-automation-bootstrap.git
$ cd ui-automation-bootstrap/
$ docker-compose up -d
$ mvn test -Dtestnames=Example
```

### Inject runtime properties
### Runtime properties

Configurable on `pom.xml`

````shell script
$ mvn test -Dtestnames=Example [-Dparallel=methods|classes|tests] [-DthreadCount=n] [-Dlistener="utils.listeners.ExampleListener"] [-Denvironment="$env"]
$ mvn test -Dtestnames=Example [-Dbrowser=chrome|firefox] [-Dparallel=methods|classes|tests] [-DthreadCount=n] [-Dlistener="utils.listeners.ExampleListener"] [-Denvironment="$env"]
````

> **testnames** (mandatory) - Tests to be executed (check `testng.xml`)
>
> **browser** (optional, default `chrome`) - Browser to execute tests
>
> **parallel** (optional, default `false`) - Tells testng the method of parallel test execution
>
> **threadCount** (optional, default `1`) - How many threads to use during test execution
>
> **listener** (optional, default `MockListener` and `ExtentReportListener`) - Additional listener to be used during test execution (check `testng.xml`)
>
> **environment** (optional, default `qa`) - Environment configuration to be loaded. However, it's overwritten when `run.tests.local=true`, falling back to default `local`.
## Documentation
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>io.github.sergiomartins8</groupId>
<artifactId>ui-automation-bootstrap</artifactId>
<version>1.0.0</version>
<version>1.1.0</version>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
Expand Down
13 changes: 11 additions & 2 deletions src/test/java/utils/config/ConfigReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static Config populateConfigs() {
private static Config localConfiguration() {
Properties properties = getPropertiesFromResource("config/config.local.properties");

return new Config.Builder(true, BrowserType.valueOf(properties.getProperty("browser.type")))
return new Config.Builder(true, getBrowserType(properties))
.withBaseUrl(properties.getProperty("base.url"))
.withScreenshots(Boolean.parseBoolean(properties.getProperty("screenshots")))
.withHeadless(Boolean.parseBoolean(properties.getProperty("headless")))
Expand All @@ -46,7 +46,7 @@ private static Config remoteConfiguration() {

Properties properties = getPropertiesFromResource("config/config." + environment + ".properties");

return new Config.Builder(false, BrowserType.valueOf(properties.getProperty("browser.type")))
return new Config.Builder(false, getBrowserType(properties))
.withBaseUrl(properties.getProperty("base.url"))
.withScreenshots(Boolean.parseBoolean(properties.getProperty("screenshots")))
.withHeadless(Boolean.parseBoolean(properties.getProperty("headless")))
Expand Down Expand Up @@ -74,4 +74,13 @@ private static Properties getPropertiesFromResource(String resource) {
}
return properties;
}

/**
* @param properties environment configuration
* @return {@link BrowserType} based on system properties or (if null) the environment configuration
*/
private static BrowserType getBrowserType(Properties properties) {
return System.getProperty("browser") != null
? BrowserType.valueOf(System.getProperty("browser")) : BrowserType.valueOf(properties.getProperty("browser.type"));
}
}

0 comments on commit b8c9994

Please sign in to comment.