Automation framework / solution implemented in Java to support web browser as well as mobile browser / App automation
Automation framework / solution implemented in Java to support web browser as well as mobile browser / App automation. This includes
To use this automation framework in your test suite:
Inherit from unifiedbdd-automation-parent
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.github.kripaliz</groupId>
<artifactId>unifiedbdd-automation-parent</artifactId>
<version>0.1.6</version>
</parent>
<groupId>com.company.testing</groupId>
<artifactId>uiautomation-suite</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<cucumber.execution.parallel.enabled>true</cucumber.execution.parallel.enabled>
<cucumber.glue>com.company.testing.step</cucumber.glue>
<cucumber.plugin>json:target/cucumber-reports/result.json,junit:target/cucumber-reports/result.xml</cucumber.plugin>
</properties>
</project>
Create an application.yml file for spring boot
spring.main.sources: com.company.testing
spring.profiles.active: chrome
---
spring.config.activate.on-profile: chrome
webdriver:
type: chrome
---
spring.config.activate.on-profile: saucelabs
webdriver:
type: remote
url: http://user:[email protected]:80/wd/hub
desiredCapabilities:
browserName: chrome
browserVersion: latest
platformName: macOS 10.13
Create logback xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoders are assigned the type ch.qos.logback.classic.encoder.PatternLayoutEncoder
by default -->
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<logger name="org.apache.http" level="INFO" />
<logger name="org.springframework" level="INFO" />
<root level="debug">
<appender-ref ref="STDOUT" />
</root>
</configuration>
Create a Test suite class
@Suite
@IncludeEngines("cucumber")
@SelectClasspathResource("features")
public class AutomationTests {
}
Create PageObject classes that extend com.github.kripaliz.automation.pageobject.AbstractPage
and use the marker interface com.github.kripaliz.automation.pageobject.PageObject
.
@PageObject
public class AnukoHomePage extends AbstractPage {
@FindBy(css = AnukoHomePageConstants.LOGIN_LINK_CSS)
private WebElement loginLink;
public void visitUrl() {
webDriver.get("https://timetracker.anuko.com/");
}
}
Create StepDef classes that use spring dependency injection to get pageObjects. (under a package you configured in cucumber.glue
in pom.xml)
public class SignInSteps {
@Autowired
private AnukoHomePage anukoHomePage;
@Given("^I visit Anuko Home Page$")
public void i_visit_Anuko_Home_Page() throws Exception {
anukoHomePage.visitUrl();
}
}
Create gherkin feature files in src/test/resources/features
To run the suite
mvn clean test \
-Dcucumber.execution.parallel.config.fixed.parallelism=10 \
-Dgroups="!wip" \
-Dspring.profiles.active=chrome \
-Dsurefire.rerunFailingTestsCount=0
options:
cucumber.execution.parallel.config.fixed.parallelism
: specify the number of concurrent scenarios to executegroups
: junit tag expressions to limit scope of test executionspring.profiles.active
: switch between spring profiles created in application.ymlsurefire.rerunFailingTestsCount
: reruns for any failed testsTo view the allure report
mvn allure:serve
To re-run failed tests
mvn test -Dcucumber.options=@target/rerun.txt -Dspring.profiles.active=chrome -DthreadCount=4
Cucumber 3+ provides TypeRegistryConfigurer
to configure custom parameter types and data table types. The framework already defines one to setup a default DataTable Transformer using Jackson library.
To extend it, please use ServiceLoader mechanism:
DataTableTypeProvider
or ParameterTypeProvider
META-INF/services/com.github.kripaliz.automation.cucumber.DataTableTypeProvider
META-INF/services/com.github.kripaliz.automation.cucumber.ParameterTypeProvider
Here's some more info on ServiceLoader; https://www.baeldung.com/java-spi