mirror of
https://github.com/hmalik144/Automation-Test-Framework.git
synced 2025-12-10 03:05:35 +00:00
Initial commit
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
# Project exclude paths
|
||||
/target/
|
||||
2
.idea/.gitignore
generated
vendored
Normal file
2
.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
# Default ignored files
|
||||
/workspace.xml
|
||||
22
.idea/codeStyles/Project.xml
generated
Normal file
22
.idea/codeStyles/Project.xml
generated
Normal file
@@ -0,0 +1,22 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<code_scheme name="Project" version="173">
|
||||
<JetCodeStyleSettings>
|
||||
<option name="PACKAGES_TO_USE_STAR_IMPORTS">
|
||||
<value>
|
||||
<package name="java.util" alias="false" withSubpackages="false" />
|
||||
<package name="kotlinx.android.synthetic" alias="false" withSubpackages="true" />
|
||||
<package name="io.ktor" alias="false" withSubpackages="true" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="PACKAGES_IMPORT_LAYOUT">
|
||||
<value>
|
||||
<package name="" alias="false" withSubpackages="true" />
|
||||
<package name="java" alias="false" withSubpackages="true" />
|
||||
<package name="javax" alias="false" withSubpackages="true" />
|
||||
<package name="kotlin" alias="false" withSubpackages="true" />
|
||||
<package name="" alias="true" withSubpackages="true" />
|
||||
</value>
|
||||
</option>
|
||||
</JetCodeStyleSettings>
|
||||
</code_scheme>
|
||||
</component>
|
||||
13
.idea/compiler.xml
generated
Normal file
13
.idea/compiler.xml
generated
Normal file
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<annotationProcessing>
|
||||
<profile name="Maven default annotation processors profile" enabled="true">
|
||||
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||
<outputRelativeToContentRoot value="true" />
|
||||
<module name="Automation-Test-Framework" />
|
||||
</profile>
|
||||
</annotationProcessing>
|
||||
</component>
|
||||
</project>
|
||||
14
.idea/misc.xml
generated
Normal file
14
.idea/misc.xml
generated
Normal file
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="MavenProjectsManager">
|
||||
<option name="originalFiles">
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/pom.xml" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" project-jdk-name="11" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
2
Automation-Test-Framework.iml
Normal file
2
Automation-Test-Framework.iml
Normal file
@@ -0,0 +1,2 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4" />
|
||||
102
pom.xml
Normal file
102
pom.xml
Normal file
@@ -0,0 +1,102 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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>
|
||||
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>Automation-Test-Framework</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<kotlin.version>1.4.0</kotlin.version>
|
||||
<cucumber.version>6.8.1</cucumber.version>
|
||||
<maven.compiler.source>1.7</maven.compiler.source>
|
||||
<maven.compiler.target>1.7</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- cucumber -->
|
||||
<dependency>
|
||||
<groupId>io.cucumber</groupId>
|
||||
<artifactId>cucumber-java</artifactId>
|
||||
<version>${cucumber.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!-- cucumber-junit -->
|
||||
<dependency>
|
||||
<groupId>io.cucumber</groupId>
|
||||
<artifactId>cucumber-junit</artifactId>
|
||||
<version>${cucumber.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!-- jUnit -->
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-params</artifactId>
|
||||
<version>5.0.0</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
|
||||
<dependency>
|
||||
<groupId>org.seleniumhq.selenium</groupId>
|
||||
<artifactId>selenium-java</artifactId>
|
||||
<version>3.141.59</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.cucumber</groupId>
|
||||
<artifactId>cucumber-java</artifactId>
|
||||
<version>6.8.1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.cucumber</groupId>
|
||||
<artifactId>cucumber-junit</artifactId>
|
||||
<version>6.8.1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
|
||||
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-maven-plugin</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
|
||||
<executions>
|
||||
<execution>
|
||||
<id>compile</id>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
|
||||
<execution>
|
||||
<id>test-compile</id>
|
||||
<goals>
|
||||
<goal>test-compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
3
src/main/kotlin/HelloWorld.kt
Normal file
3
src/main/kotlin/HelloWorld.kt
Normal file
@@ -0,0 +1,3 @@
|
||||
public fun main(args: Array<String>){
|
||||
print("Hello World!")
|
||||
}
|
||||
8
src/test/kotlin/constants/Drivers.kt
Normal file
8
src/test/kotlin/constants/Drivers.kt
Normal file
@@ -0,0 +1,8 @@
|
||||
package constants
|
||||
|
||||
enum class Drivers(
|
||||
val driverProperty: String,
|
||||
val driverFileName: String
|
||||
){
|
||||
Chrome("webdriver.chrome.driver", "chromedriver.exe")
|
||||
}
|
||||
7
src/test/kotlin/constants/Gender.kt
Normal file
7
src/test/kotlin/constants/Gender.kt
Normal file
@@ -0,0 +1,7 @@
|
||||
package constants
|
||||
|
||||
enum class Gender{
|
||||
Male,
|
||||
Female,
|
||||
Other
|
||||
}
|
||||
3
src/test/kotlin/constants/WebDriverConstans.kt
Normal file
3
src/test/kotlin/constants/WebDriverConstans.kt
Normal file
@@ -0,0 +1,3 @@
|
||||
package constants
|
||||
|
||||
const val TIMEOUT_DURATION = 30L
|
||||
63
src/test/kotlin/pages/FormPageFactory.kt
Normal file
63
src/test/kotlin/pages/FormPageFactory.kt
Normal file
@@ -0,0 +1,63 @@
|
||||
package pages
|
||||
|
||||
import org.openqa.selenium.WebDriver
|
||||
import org.openqa.selenium.WebElement
|
||||
import org.openqa.selenium.support.FindBy
|
||||
import org.openqa.selenium.support.PageFactory
|
||||
import utils.scrollTo
|
||||
|
||||
class FormPageFactory(
|
||||
val driver: WebDriver
|
||||
){
|
||||
|
||||
@FindBy(id = "firstName")
|
||||
lateinit var firstName: WebElement
|
||||
|
||||
@FindBy(id = "lastName")
|
||||
lateinit var lastName: WebElement
|
||||
|
||||
@FindBy(id = "userEmail")
|
||||
lateinit var userEmail: WebElement
|
||||
|
||||
@FindBy(xpath = "//*[@id=\"genterWrapper\"]/div[2]/div[1]/label")
|
||||
lateinit var male: WebElement
|
||||
@FindBy(xpath = "//*[@id=\"genterWrapper\"]/div[2]/div[2]/label")
|
||||
lateinit var female: WebElement
|
||||
@FindBy(xpath = "//*[@id=\"genterWrapper\"]/div[2]/div[3]/label")
|
||||
lateinit var other: WebElement
|
||||
|
||||
@FindBy(id = "userNumber")
|
||||
lateinit var mobileNumber: WebElement
|
||||
|
||||
@FindBy(xpath = "//*[@id=\"submit\"]")
|
||||
lateinit var submit: WebElement
|
||||
|
||||
init {
|
||||
PageFactory.initElements(driver, this)
|
||||
}
|
||||
|
||||
|
||||
fun enterFirstName(first: String) = firstName.sendKeys(first)
|
||||
|
||||
fun enterLastName(last: String) = lastName.sendKeys(last)
|
||||
|
||||
fun enterEmailAddress(email: String) = userEmail.sendKeys(email)
|
||||
|
||||
fun selectGender(gender: String) = when(gender){
|
||||
"Male"-> male.click()
|
||||
"Female"-> female.click()
|
||||
"Other"-> other.click()
|
||||
else -> {}
|
||||
}
|
||||
|
||||
fun enterMobileNumber(mobile: String) = mobileNumber.sendKeys(mobile)
|
||||
|
||||
fun submit(){
|
||||
|
||||
submit.apply {
|
||||
scrollTo(driver)
|
||||
click()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
21
src/test/kotlin/pages/SubmittedFormFactory.kt
Normal file
21
src/test/kotlin/pages/SubmittedFormFactory.kt
Normal file
@@ -0,0 +1,21 @@
|
||||
package pages
|
||||
|
||||
import org.openqa.selenium.WebDriver
|
||||
import org.openqa.selenium.WebElement
|
||||
import org.openqa.selenium.support.FindBy
|
||||
import org.openqa.selenium.support.PageFactory
|
||||
|
||||
class SubmittedFormFactory(
|
||||
driver: WebDriver
|
||||
) {
|
||||
|
||||
@FindBy(id = "example-modal-sizes-title-lg")
|
||||
lateinit var tableHeader: WebElement
|
||||
|
||||
init {
|
||||
PageFactory.initElements(driver, this)
|
||||
}
|
||||
|
||||
fun checkTableIsDisplayed() = tableHeader.isDisplayed
|
||||
|
||||
}
|
||||
77
src/test/kotlin/stepDefinition/PracticeFormPageSteps.kt
Normal file
77
src/test/kotlin/stepDefinition/PracticeFormPageSteps.kt
Normal file
@@ -0,0 +1,77 @@
|
||||
package stepDefinition
|
||||
|
||||
import constants.Drivers
|
||||
import io.cucumber.java.After
|
||||
import io.cucumber.java.Before
|
||||
import io.cucumber.java.en.Given
|
||||
import io.cucumber.java.en.Then
|
||||
import io.cucumber.java.en.When
|
||||
import org.openqa.selenium.WebDriver
|
||||
import pages.FormPageFactory
|
||||
import pages.SubmittedFormFactory
|
||||
import stepDefinition.baseSteps.Driver
|
||||
import stepDefinition.baseSteps.DriverSteps
|
||||
import java.lang.AssertionError
|
||||
|
||||
|
||||
class PracticeFormPageSteps: DriverSteps() {
|
||||
|
||||
lateinit var webDriver: WebDriver
|
||||
|
||||
lateinit var formPageFactory: FormPageFactory
|
||||
lateinit var submittedFormFactory: SubmittedFormFactory
|
||||
|
||||
@Before
|
||||
fun setup(){
|
||||
webDriver = createWebDriver(Drivers.Chrome)
|
||||
|
||||
formPageFactory = FormPageFactory(webDriver)
|
||||
submittedFormFactory = SubmittedFormFactory(webDriver)
|
||||
}
|
||||
|
||||
@After
|
||||
fun tearDown(){
|
||||
webDriver.finish()
|
||||
}
|
||||
|
||||
@Given("user is on practice form")
|
||||
fun user_is_on_practice_form() {
|
||||
webDriver.launchUrl("https://demoqa.com/automation-practice-form")
|
||||
}
|
||||
|
||||
@When("user enters first name {string} and last name {string}")
|
||||
fun user_enters_first_name_and_last_name(firstName: String?, lastName: String?) {
|
||||
formPageFactory.apply {
|
||||
firstName?.let { enterFirstName(it) }
|
||||
lastName?.let { enterLastName(it) }
|
||||
}
|
||||
}
|
||||
|
||||
@When("user selects gender {string}")
|
||||
fun user_selects_gender(gender: String?) {
|
||||
gender?.let { formPageFactory.selectGender(gender) }
|
||||
}
|
||||
|
||||
@When("user enters email address {string}")
|
||||
fun user_enters_email_address(email: String?) {
|
||||
email?.let { formPageFactory.enterEmailAddress(it) }
|
||||
}
|
||||
|
||||
@When("user enters mobile number {string}")
|
||||
fun user_enters_mobile_number(mobile: String?) {
|
||||
mobile?.let { formPageFactory.enterMobileNumber(it) }
|
||||
}
|
||||
|
||||
@When("user clicks submit button")
|
||||
fun user_clicks_submit_button() {
|
||||
formPageFactory.submit()
|
||||
}
|
||||
|
||||
@Then("pop up is displayed")
|
||||
fun pop_up_is_displayed() {
|
||||
if(!submittedFormFactory.checkTableIsDisplayed()){
|
||||
throw AssertionError("Popup not displayed")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
11
src/test/kotlin/stepDefinition/TestRunner.kt
Normal file
11
src/test/kotlin/stepDefinition/TestRunner.kt
Normal file
@@ -0,0 +1,11 @@
|
||||
package stepDefinition
|
||||
|
||||
import io.cucumber.junit.Cucumber
|
||||
import io.cucumber.junit.CucumberOptions
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
@RunWith(Cucumber::class)
|
||||
@CucumberOptions(features = ["src/test/resources/features"],
|
||||
glue = ["stepDefinition"],
|
||||
plugin = ["pretty", "json:target/reports/cucumber.json"])
|
||||
class TestRunner
|
||||
20
src/test/kotlin/stepDefinition/baseSteps/Driver.kt
Normal file
20
src/test/kotlin/stepDefinition/baseSteps/Driver.kt
Normal file
@@ -0,0 +1,20 @@
|
||||
package stepDefinition.baseSteps
|
||||
|
||||
import constants.Drivers
|
||||
import org.openqa.selenium.WebDriver
|
||||
import org.openqa.selenium.chrome.ChromeDriver
|
||||
import java.io.IOException
|
||||
|
||||
abstract class Driver{
|
||||
|
||||
fun createChromeDriver(driver: Drivers): WebDriver {
|
||||
val path = System.getProperty("user.dir")
|
||||
System.setProperty(driver.driverProperty, "$path\\src\\test\\resources\\drivers\\${driver.driverFileName}")
|
||||
|
||||
return when(driver){
|
||||
Drivers.Chrome -> ChromeDriver()
|
||||
else -> { throw IOException("No web driver available")}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
30
src/test/kotlin/stepDefinition/baseSteps/DriverSteps.kt
Normal file
30
src/test/kotlin/stepDefinition/baseSteps/DriverSteps.kt
Normal file
@@ -0,0 +1,30 @@
|
||||
package stepDefinition.baseSteps
|
||||
|
||||
import constants.Drivers
|
||||
import constants.TIMEOUT_DURATION
|
||||
import org.openqa.selenium.WebDriver
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
|
||||
abstract class DriverSteps : Driver(){
|
||||
|
||||
fun createWebDriver(driver: Drivers): WebDriver{
|
||||
return createChromeDriver(driver).apply {
|
||||
manage().timeouts().let { tO ->
|
||||
tO.implicitlyWait(TIMEOUT_DURATION, TimeUnit.SECONDS)
|
||||
tO.pageLoadTimeout(TIMEOUT_DURATION, TimeUnit.SECONDS)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun WebDriver.launchUrl(url: String){
|
||||
navigate().to(url)
|
||||
}
|
||||
|
||||
fun WebDriver.finish(){
|
||||
close()
|
||||
quit()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
14
src/test/kotlin/utils/ElementUtils.kt
Normal file
14
src/test/kotlin/utils/ElementUtils.kt
Normal file
@@ -0,0 +1,14 @@
|
||||
package utils
|
||||
|
||||
import org.openqa.selenium.WebDriver
|
||||
import org.openqa.selenium.WebElement
|
||||
import org.openqa.selenium.interactions.Actions
|
||||
|
||||
/*
|
||||
* Scroll down to a web element
|
||||
*/
|
||||
fun WebElement.scrollTo(driver: WebDriver){
|
||||
val actions = Actions(driver)
|
||||
actions.moveToElement(this)
|
||||
actions.perform()
|
||||
}
|
||||
BIN
src/test/resources/drivers/chromedriver.exe
Normal file
BIN
src/test/resources/drivers/chromedriver.exe
Normal file
Binary file not shown.
68
src/test/resources/features/parctice_form.feature
Normal file
68
src/test/resources/features/parctice_form.feature
Normal file
@@ -0,0 +1,68 @@
|
||||
Feature: Feature to test the practice form
|
||||
|
||||
@SmokeTest @RegressionTest
|
||||
Scenario Outline: Check user can successfully submit a form with minimum mandatory valid credentials
|
||||
|
||||
Given user is on practice form
|
||||
When user enters first name "<firstName>" and last name "<lastName>"
|
||||
And user selects gender "<gender>"
|
||||
And user enters email address "<emailAddress>"
|
||||
And user enters mobile number "<mobileNumber>"
|
||||
And user clicks submit button
|
||||
Then pop up is displayed
|
||||
|
||||
Examples:
|
||||
| firstName | lastName | gender | emailAddress | mobileNumber |
|
||||
| Harvey | Specter | Male | harvey.specter@pearson-specter.com | 2125096995 |
|
||||
| Rachel | Zane | Female | rachel.zane@pearson-specter.com | 2125096965 |
|
||||
|
||||
|
||||
@SmokeTest @RegressionTest
|
||||
Scenario Outline: Check user can successfully submit a form with all the minimum valid credentials and 1 letter names
|
||||
|
||||
Given user is on practice form
|
||||
When user enters first name "<firstName>" and last name "<lastName>"
|
||||
And user selects gender "<gender>"
|
||||
And user enters email address "<emailAddress>"
|
||||
And user enters mobile number "<mobileNumber>"
|
||||
And user clicks submit button
|
||||
Then pop up is displayed
|
||||
|
||||
Examples:
|
||||
| firstName | lastName | gender | emailAddress | mobileNumber |
|
||||
| i | j | Male | j@domain.com | 2125096995 |
|
||||
| 2 | y | Female | y@domain.com | 2125096965 |
|
||||
|
||||
|
||||
@RegressionTest
|
||||
Scenario Outline: Check user cannot submit a form with if fields are empty
|
||||
|
||||
Given user is on practice form
|
||||
When user enters first name "<firstName>" and last name "<lastName>"
|
||||
And user selects gender "<gender>"
|
||||
And user enters email address "<emailAddress>"
|
||||
And user enters mobile number "<mobileNumber>"
|
||||
And user clicks submit button
|
||||
Then no pop up is displayed
|
||||
|
||||
Examples:
|
||||
| firstName | lastName | gender | emailAddress | mobileNumber |
|
||||
| | Lastname | Male | name@domain.com | 2125096995 |
|
||||
| FirstName | | Female | name@domain.com | 2125096965 |
|
||||
| FirstName | Lastname | | name@domain.com | 2125096965 |
|
||||
| FirstName | Lastname | Other | | 2125096965 |
|
||||
| FirstName | Lastname | Other | name@domain.com | |
|
||||
|
||||
@RegressionTest
|
||||
Scenario Outline: Check email address shows error if incorrect email string
|
||||
|
||||
Given user is on practice form
|
||||
When user enters email address "<emailAddress>"
|
||||
Then email input is displaying an error
|
||||
|
||||
Examples:
|
||||
| emailAddress |
|
||||
| namedomain.com |
|
||||
| name@domain.c |
|
||||
| @domain.com |
|
||||
|
||||
Reference in New Issue
Block a user