├── .settings └── org.eclipse.jdt.core.prefs ├── Jenkinsfile ├── README.md ├── build.gradle ├── lib ├── chromedriver ├── chromedriver.exe ├── chromedriver_mac ├── geckodriver.exe └── geckodriver_mac ├── pom.xml ├── serenity.properties ├── src └── test │ ├── java │ └── com │ │ └── uiautomation │ │ ├── actions │ │ └── GoogleSearchActions.java │ │ ├── apiactions │ │ └── RegisterUserActions.java │ │ ├── apisteps │ │ └── RegisterUserSteps.java │ │ ├── pages │ │ ├── GoogleSearchPage.java │ │ ├── LoginPage.java │ │ └── SignUpPage.java │ │ ├── registeruserpojo │ │ ├── RegisterUserRequest.java │ │ └── RegisterUserResponse.java │ │ ├── runners │ │ ├── APITest.java │ │ ├── GoogleSearchTest.java │ │ ├── JoinNLBCTest.java │ │ └── LoginNLBCTest.java │ │ ├── steps │ │ ├── GoogleSearchStep.java │ │ ├── Hooks.java │ │ ├── LoginNLBCSteps.java │ │ └── SignUpNLBC.java │ │ └── utils │ │ └── Constants.java │ └── resources │ └── features │ ├── api │ └── registeruser.feature │ └── nlbc │ ├── googlesearch.feature │ ├── login.feature │ └── signUp.feature └── testdata └── registeruser.json /.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 3 | org.eclipse.jdt.core.compiler.compliance=1.8 4 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 5 | org.eclipse.jdt.core.compiler.source=1.8 6 | -------------------------------------------------------------------------------- /Jenkinsfile: -------------------------------------------------------------------------------- 1 | pipeline { 2 | agent any 3 | 4 | stages { 5 | stage ('Compile Stage') { 6 | 7 | steps { 8 | withMaven(maven : 'maven_3_5_0') { 9 | bat 'mvn clean' 10 | } 11 | } 12 | } 13 | 14 | stage ('Testing Stage:Firefox') { 15 | 16 | steps { 17 | withMaven(maven : 'maven_3_5_0') { 18 | bat 'mvn verify -Dcontext=firefox -Dwebdriver.driver=firefox' 19 | } 20 | } 21 | } 22 | 23 | stage ('Testing Stage: Chrome') { 24 | 25 | steps { 26 | withMaven(maven : 'maven_3_5_0') { 27 | bat 'mvn verify -Dcontext=chrome -Dwebdriver.driver=chrome' 28 | } 29 | } 30 | } 31 | 32 | 33 | stage ('Deployment Stage') { 34 | steps { 35 | withMaven(maven : 'maven_3_5_0') { 36 | echo 'Deployment...' 37 | } 38 | } 39 | } 40 | 41 | stage ('Publish Reports') { 42 | steps { 43 | publishHTML([allowMissing: true, alwaysLinkToLastBuild: true, keepAll: true, reportDir: '\\target\\site\\serenity', reportFiles: 'index.html', reportName: 'HTML Report', reportTitles: '']) 44 | } 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # "Selenium" BDD with "Cucumber" and "Serenity" 2 | * This project is an example of how to setup and write selenium tests using BDD approach with Serenity framework 3 | * How to create jenkins pipeline 4 | 5 | ## Project Description: 6 | * Project setup with Selenium WebDriver and windows 10 7 | * serenity.version: 1.8.3 8 | * serenity.cucumber.version: 1.6.6 9 | * Makes use of Page Objects. 10 | * Written in Java with Junit, Cucumber & Maven 11 | * Can run test scripts in parallel 12 | 13 | ## Setup: 14 | * Install [Java 8](http://www.oracle.com/technetwork/java/javase/overview/java8-2100321.html) 15 | * Install Maven [Maven](https://maven.apache.org/) 16 | * "mvn archetype:generate -Dfilter=net.serenity-bdd:serenity-cucumber-archetype" to setup project from scratch 17 | * Install "natural plugin" using eclipse marketplace 18 | 19 | ## Run tests: 20 | * `mvn clean verify` OR `mvn clean verify -Dwebdriver.driver=chrome` - Run test scripts using Chrome browser. 21 | * `mvn clean verify -Dwebdriver.driver=firefox` - Run test scripts using Firefox browser. 22 | 23 | ## View HTML Report 24 | * HTML report will be generated once execution finish -bdd-cucumber\target\site\serenity 25 | * Open Index.html in browser to see the reports 26 | 27 | ## Run tests in parallel: 28 | * TBD 29 | # Setting jenkins pipeline for Selenium(Cucumber serenity project) 30 | * This project is example how can setup jenkins pipeline for selenium project step by step 31 | ## Setup 32 | * Download latest jenkins.war [Jenkins download link](https://updates.jenkins-ci.org/download/war/) 33 | * Start jenkins.jar on default port using command 'java -jar jenkins.war' 34 | * Start jenkins.jar on specific port using command 'java -jar jenkins.war --httpPort=portnumber' 35 | * Open localhost:portnumber and login using displayed insructions on browser screens 36 | * Now install all default plugin and set user & password 37 | ## Installing required plugins 38 | * Navigate to jenkins home and click on "Manage jenkins" tab 39 | * Now click on "Manage plugins" 40 | * In "Available plugins" tab, perform serach for "Pipeline Maven Integration" and install 41 | * Follwing above steps, install "HTML Publisher" plugin 42 | ## Setting up Java-jdk and maven 43 | * Navigate to "Manage jenkins->Global Tool configuration" 44 | * Configure java-jdk & maven with java8 & maven_3_5_0 name respectivelly 45 | ## Global configuration for Github 46 | * Navigate to "Manage jenkins->Configure System" and in Github section configure github credentials 47 | ## Creating jenkins pipe line 48 | * Navigate to "https://github.com/narottamgla/selenium-bdd-cucumber/blob/master/Jenkinsfile" and have similar file in github root 49 | * Now navigate to click New Item and create pipeline type of job 50 | * Now navigate to pipeline section of job and select "Pipeline script from SCM" 51 | * Enter repositary url and select github credentials and keep other details default 52 | * Save the changes 53 | 54 | ## Running created pipeline 55 | * Click build now and execution will be started 56 | * Pipeline steps will be displayed on jenkins screen 57 | * Once execution finish, Click on "HTML Report" tab to view serenity HTML Reports 58 | 59 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | repositories { 2 | jcenter() 3 | mavenLocal() 4 | } 5 | 6 | buildscript { 7 | repositories { 8 | mavenLocal() 9 | jcenter() 10 | } 11 | dependencies { 12 | classpath("net.serenity-bdd:serenity-gradle-plugin:1.8.3") 13 | } 14 | } 15 | 16 | apply plugin: 'java' 17 | apply plugin: 'eclipse' 18 | apply plugin: 'idea' 19 | apply plugin: 'net.serenity-bdd.aggregator' 20 | 21 | sourceCompatibility = 1.8 22 | targetCompatibility = 1.8 23 | 24 | dependencies { 25 | compile 'net.serenity-bdd:serenity-core:1.8.3' 26 | compile 'net.serenity-bdd:serenity-cucumber:1.6.6' 27 | testCompile('junit:junit:4.12') 28 | compile('org.assertj:assertj-core:3.8.0') 29 | } 30 | gradle.startParameter.continueOnFailure = true 31 | -------------------------------------------------------------------------------- /lib/chromedriver: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/narottamgla/selenium-bdd-cucumber/b3fdd91e3ffc0daed2eb01474d2ce78f02e001ed/lib/chromedriver -------------------------------------------------------------------------------- /lib/chromedriver.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/narottamgla/selenium-bdd-cucumber/b3fdd91e3ffc0daed2eb01474d2ce78f02e001ed/lib/chromedriver.exe -------------------------------------------------------------------------------- /lib/chromedriver_mac: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/narottamgla/selenium-bdd-cucumber/b3fdd91e3ffc0daed2eb01474d2ce78f02e001ed/lib/chromedriver_mac -------------------------------------------------------------------------------- /lib/geckodriver.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/narottamgla/selenium-bdd-cucumber/b3fdd91e3ffc0daed2eb01474d2ce78f02e001ed/lib/geckodriver.exe -------------------------------------------------------------------------------- /lib/geckodriver_mac: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/narottamgla/selenium-bdd-cucumber/b3fdd91e3ffc0daed2eb01474d2ce78f02e001ed/lib/geckodriver_mac -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | uiautomation 7 | bdd-cucumber 8 | 1.0-SNAPSHOT 9 | jar 10 | 11 | Sample Serenity project using Cucumber and WebDriver 12 | 13 | 14 | UTF-8 15 | 1.8.3 16 | 1.6.6 17 | chrome 18 | 2.8.5 19 | 20 | 21 | 22 | 23 | 24 | false 25 | 26 | central 27 | bintray 28 | http://jcenter.bintray.com 29 | 30 | 31 | 32 | 33 | 34 | false 35 | 36 | central 37 | bintray-plugins 38 | http://jcenter.bintray.com 39 | 40 | 41 | 42 | 43 | 44 | net.serenity-bdd 45 | serenity-core 46 | ${serenity.version} 47 | test 48 | 49 | 50 | net.serenity-bdd 51 | serenity-cucumber 52 | ${serenity.cucumber.version} 53 | test 54 | 55 | 56 | org.slf4j 57 | slf4j-simple 58 | 1.7.7 59 | test 60 | 61 | 62 | junit 63 | junit 64 | 4.12 65 | test 66 | 67 | 68 | 69 | com.google.code.gson 70 | gson 71 | ${gson.version} 72 | 73 | 74 | 75 | net.serenity-bdd 76 | serenity-rest-assured 77 | ${serenity.cucumber.version} 78 | 79 | 80 | 81 | 82 | 83 | org.apache.maven.plugins 84 | maven-surefire-plugin 85 | 2.19.1 86 | 87 | true 88 | 89 | 90 | 91 | maven-failsafe-plugin 92 | 2.19.1 93 | 94 | 95 | **/*Test.java 96 | 97 | -Xmx512m 98 | 99 | ${webdriver.driver} 100 | 101 | 102 | 103 | 104 | 105 | integration-test 106 | verify 107 | 108 | 109 | 110 | 111 | 112 | org.apache.maven.plugins 113 | maven-compiler-plugin 114 | 3.2 115 | 116 | 1.8 117 | 1.8 118 | 119 | 120 | 121 | net.serenity-bdd.maven.plugins 122 | serenity-maven-plugin 123 | ${serenity.version} 124 | 125 | 126 | serenity-reports 127 | post-integration-test 128 | 129 | aggregate 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | -------------------------------------------------------------------------------- /serenity.properties: -------------------------------------------------------------------------------- 1 | # Define the default driver 2 | #webdriver.driver=phantomjs 3 | 4 | webdriver.driver=chrome 5 | 6 | #For Mac 7 | webdriver.chrome.driver=lib/chromedriver 8 | #For windows 9 | #webdriver.chrome.driver=lib/chromedriver.exe 10 | #webdriver.gecko.driver = lib/geckodriver.exe 11 | # Appears at the top of the reports 12 | serenity.project.name = Demo Project using Selenium Serenity and Cucumber 13 | 14 | # Root package for any JUnit acceptance tests 15 | #serenity.test.root=net.thucydides.showcase.junit.features 16 | 17 | # Customise your riequirements hierarchy 18 | #serenity.requirement.types=feature, story 19 | 20 | # Run the tests without calling webdriver - useful to check your Cucumber wireing 21 | #serenity.dry.run=true 22 | 23 | # Customise browser size 24 | #serenity.browser.height = 1200 25 | #serenity.browser.width = 1200 26 | 27 | 28 | -------------------------------------------------------------------------------- /src/test/java/com/uiautomation/actions/GoogleSearchActions.java: -------------------------------------------------------------------------------- 1 | package com.uiautomation.actions; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import com.uiautomation.pages.GoogleSearchPage; 7 | 8 | import junit.framework.Assert; 9 | import net.thucydides.core.annotations.Step; 10 | 11 | public class GoogleSearchActions { 12 | GoogleSearchPage searchPage; 13 | 14 | @Step 15 | public void openGoogleSearchPage() { 16 | searchPage.open(); 17 | } 18 | 19 | @Step 20 | public void searchFor(String searchRequest) { 21 | searchPage.searchFor(searchRequest); 22 | } 23 | 24 | @Step 25 | public List verifyResult(String searchResult) { 26 | List results = new ArrayList<>(); 27 | //add search result to list and return 28 | return results; 29 | } 30 | } -------------------------------------------------------------------------------- /src/test/java/com/uiautomation/apiactions/RegisterUserActions.java: -------------------------------------------------------------------------------- 1 | package com.uiautomation.apiactions; 2 | 3 | import java.io.File; 4 | import java.io.FileNotFoundException; 5 | 6 | import com.google.gson.Gson; 7 | import com.google.gson.GsonBuilder; 8 | import com.google.gson.JsonIOException; 9 | import com.google.gson.JsonSyntaxException; 10 | import com.google.gson.stream.JsonReader; 11 | import com.uiautomation.registeruserpojo.RegisterUserRequest; 12 | import com.uiautomation.utils.Constants; 13 | 14 | import io.restassured.response.Response; 15 | import net.serenitybdd.rest.SerenityRest; 16 | import net.thucydides.core.annotations.Step; 17 | 18 | public class RegisterUserActions { 19 | 20 | private String scenarioTestData = Constants.TEST_DATA_BASEPATH; 21 | private RegisterUserRequest registerUserRequest; 22 | public Response response; 23 | 24 | @Step 25 | public void getJSONRequestWithValidRegisterUserData() throws JsonIOException, JsonSyntaxException, FileNotFoundException { 26 | File registerUserJson = new File(scenarioTestData + Constants.REGISTERUSER_REQUEST_DATA); 27 | GsonBuilder builder = new GsonBuilder(); 28 | Gson gson = builder.serializeNulls().setPrettyPrinting().create(); 29 | registerUserRequest = gson.fromJson(new JsonReader(new java.io.FileReader(registerUserJson)), RegisterUserRequest.class); 30 | registerUserRequest.setEmail("useremail@test.com"); 31 | registerUserRequest.setPassword("userpassword"); 32 | } 33 | 34 | @Step 35 | public void requestQuoteAPIWithPostMethod() throws Exception { 36 | response = SerenityRest.given().contentType("application/json").body(registerUserRequest).when() 37 | .post(Constants.REGISTERUSER_ENDPOINT); 38 | } 39 | 40 | @Step 41 | public int getStatusCode() throws Exception { 42 | return response.then().extract().statusCode(); 43 | } 44 | 45 | @Step 46 | public String getContentType() throws Exception { 47 | return response.then().extract().contentType(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/test/java/com/uiautomation/apisteps/RegisterUserSteps.java: -------------------------------------------------------------------------------- 1 | package com.uiautomation.apisteps; 2 | 3 | import cucumber.api.java.en.Given; 4 | import cucumber.api.java.en.Then; 5 | import cucumber.api.java.en.When; 6 | import net.thucydides.core.annotations.Steps; 7 | 8 | import static org.hamcrest.MatcherAssert.assertThat; 9 | import static org.hamcrest.Matchers.equalTo; 10 | import static org.hamcrest.Matchers.notNullValue; 11 | import static org.hamcrest.Matchers.is; 12 | 13 | import com.google.gson.Gson; 14 | import com.google.gson.GsonBuilder; 15 | import com.uiautomation.apiactions.RegisterUserActions; 16 | import com.uiautomation.registeruserpojo.RegisterUserResponse; 17 | 18 | public class RegisterUserSteps { 19 | 20 | @Steps 21 | RegisterUserActions registerUserActions; 22 | 23 | @Given("^the user have proper register request data$") 24 | public void the_user_have_proper_register_request_data() throws Exception { 25 | registerUserActions.getJSONRequestWithValidRegisterUserData(); 26 | } 27 | 28 | @When("^the user sents a POST request to register API with valid request$") 29 | public void the_user_sents_a_POST_request_to_register_API_with_valid_request() throws Exception { 30 | registerUserActions.requestQuoteAPIWithPostMethod(); 31 | } 32 | 33 | @Then("^register API should have status code as (\\d+) and content-type as JSON$") 34 | public void register_API_should_have_status_code_as_and_content_type_as_JSON(int statusCode) throws Exception { 35 | assertThat("Verify Content Type for Order Api ", registerUserActions.getContentType(), 36 | equalTo("application/json; charset=utf-8")); 37 | assertThat("Verify Status code for Order Api ", registerUserActions.getStatusCode(), equalTo(statusCode)); 38 | } 39 | 40 | @Then("^the register API should return proper json response$") 41 | public void the_register_API_should_return_proper_json_response() throws Exception { 42 | GsonBuilder builder = new GsonBuilder(); 43 | Gson gson = builder.serializeNulls().setPrettyPrinting().create(); 44 | RegisterUserResponse registerUserResponse = gson.fromJson(registerUserActions.response.asString(), RegisterUserResponse.class); 45 | 46 | assertThat("Verify User registration Token", registerUserResponse.getToken(), 47 | is(notNullValue())); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/test/java/com/uiautomation/pages/GoogleSearchPage.java: -------------------------------------------------------------------------------- 1 | package com.uiautomation.pages; 2 | 3 | import org.openqa.selenium.WebElement; 4 | 5 | import net.serenitybdd.core.annotations.findby.FindBy; 6 | import net.serenitybdd.core.pages.PageObject; 7 | import net.thucydides.core.annotations.DefaultUrl; 8 | import net.thucydides.core.annotations.WhenPageOpens; 9 | 10 | @DefaultUrl("https://google.com") 11 | public class GoogleSearchPage extends PageObject { 12 | @FindBy(name = "q") 13 | private WebElement searchInputField; 14 | 15 | @WhenPageOpens 16 | public void waitUntilGoogleLogoAppears() { 17 | $("#hplogo").waitUntilVisible(); 18 | } 19 | 20 | public void searchFor(String searchRequest) { 21 | element(searchInputField).clear(); 22 | element(searchInputField).typeAndEnter(searchRequest); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/test/java/com/uiautomation/pages/LoginPage.java: -------------------------------------------------------------------------------- 1 | package com.uiautomation.pages; 2 | 3 | import net.thucydides.core.annotations.DefaultUrl; 4 | import net.thucydides.core.annotations.Step; 5 | import net.serenitybdd.core.annotations.findby.FindBy; 6 | import net.thucydides.core.pages.PageObject; 7 | 8 | import org.openqa.selenium.WebElement; 9 | 10 | @DefaultUrl("http://www.nlbootcamps.com/") 11 | public class LoginPage extends PageObject { 12 | 13 | @FindBy(css = ".nav-link[data-toggle='modal']") 14 | private WebElement joinLink; 15 | 16 | @FindBy(css = ".navbar a img") 17 | private WebElement homePageLogo; 18 | 19 | @FindBy(name = "username") 20 | private WebElement joinUserPageHeader; 21 | 22 | @FindBy(id = "username") 23 | private WebElement userNameTxBx; 24 | 25 | @FindBy(xpath = "(//*[@id='password'])[2]") 26 | private WebElement userPasswordTxBx; 27 | 28 | @FindBy(xpath = "(//input[@value='Login'])") 29 | private WebElement loginButton; 30 | 31 | public void navigateJoinUserPage() { 32 | //waitFor(joinLink); 33 | joinLink.click(); 34 | } 35 | 36 | public boolean isNavigateToHomePage() { 37 | waitFor(homePageLogo); 38 | return homePageLogo.isDisplayed(); 39 | } 40 | 41 | public boolean isNavigateToLoginPage() { 42 | waitFor(joinUserPageHeader); 43 | return joinUserPageHeader.isDisplayed(); 44 | } 45 | 46 | public void enterLoginCredentials(String userName, String userPassword) { 47 | userNameTxBx.clear(); 48 | userNameTxBx.sendKeys(userName); 49 | userPasswordTxBx.clear(); 50 | userPasswordTxBx.sendKeys(userPassword); 51 | } 52 | 53 | @Step 54 | public void clickLoginButton() { 55 | loginButton.click(); 56 | } 57 | } -------------------------------------------------------------------------------- /src/test/java/com/uiautomation/pages/SignUpPage.java: -------------------------------------------------------------------------------- 1 | package com.uiautomation.pages; 2 | 3 | import net.thucydides.core.annotations.DefaultUrl; 4 | import org.openqa.selenium.WebElement; 5 | import net.serenitybdd.core.annotations.findby.FindBy; 6 | 7 | import net.thucydides.core.pages.PageObject; 8 | 9 | @DefaultUrl("http://www.nlbootcamps.com/") 10 | public class SignUpPage extends PageObject { 11 | 12 | @FindBy(linkText="Sign up") 13 | private WebElement signUpLink; 14 | 15 | @FindBy(css="h5.modal-title") 16 | private WebElement signPageHeader; 17 | 18 | @FindBy(id="user_email") 19 | private WebElement userEmailTxBx; 20 | 21 | @FindBy(id="firstname") 22 | private WebElement firstNameTxBx; 23 | 24 | @FindBy(id="lastname") 25 | private WebElement lastNameTxBx; 26 | 27 | @FindBy(id="phoneNumber") 28 | private WebElement phoneNumberTxBx; 29 | 30 | @FindBy(id="user_male") 31 | private WebElement genderDropdown; 32 | 33 | @FindBy(id="password") 34 | private WebElement passwordTxBx; 35 | 36 | @FindBy(id="password2") 37 | private WebElement confirmpasswordTxBx; 38 | 39 | @FindBy(id="form-submit") 40 | private WebElement signUpButton; 41 | 42 | public void navigateToSignUpUserPage() { 43 | waitFor(signUpLink); 44 | signUpLink.click(); 45 | } 46 | 47 | public boolean isNavigateToSignUpPage() { 48 | waitFor(signPageHeader); 49 | return signPageHeader.isDisplayed(); 50 | } 51 | 52 | public void enterSignUpDetails(String userName, String firstName,String lastName, String phoneNumber,String password,String cpassword) { 53 | userEmailTxBx.clear(); 54 | userEmailTxBx.sendKeys(userName); 55 | firstNameTxBx.clear(); 56 | firstNameTxBx.sendKeys(firstName); 57 | lastNameTxBx.clear(); 58 | lastNameTxBx.sendKeys(lastName); 59 | lastNameTxBx.clear(); 60 | phoneNumberTxBx.clear(); 61 | phoneNumberTxBx.sendKeys(phoneNumber); 62 | passwordTxBx.clear(); 63 | passwordTxBx.sendKeys(password); 64 | confirmpasswordTxBx.clear(); 65 | confirmpasswordTxBx.sendKeys(cpassword); 66 | } 67 | 68 | public void clickSignUpButton() { 69 | signUpButton.click(); 70 | } 71 | } -------------------------------------------------------------------------------- /src/test/java/com/uiautomation/registeruserpojo/RegisterUserRequest.java: -------------------------------------------------------------------------------- 1 | package com.uiautomation.registeruserpojo; 2 | 3 | import com.google.gson.annotations.Expose; 4 | import com.google.gson.annotations.SerializedName; 5 | 6 | public class RegisterUserRequest { 7 | 8 | @SerializedName("email") 9 | @Expose 10 | private String email; 11 | @SerializedName("password") 12 | @Expose 13 | private String password; 14 | 15 | public String getEmail() { 16 | return email; 17 | } 18 | 19 | public void setEmail(String email) { 20 | this.email = email; 21 | } 22 | 23 | public String getPassword() { 24 | return password; 25 | } 26 | 27 | public void setPassword(String password) { 28 | this.password = password; 29 | } 30 | } -------------------------------------------------------------------------------- /src/test/java/com/uiautomation/registeruserpojo/RegisterUserResponse.java: -------------------------------------------------------------------------------- 1 | package com.uiautomation.registeruserpojo; 2 | 3 | import com.google.gson.annotations.Expose; 4 | import com.google.gson.annotations.SerializedName; 5 | 6 | public class RegisterUserResponse { 7 | 8 | @SerializedName("token") 9 | @Expose 10 | private String token; 11 | 12 | public String getToken() { 13 | return token; 14 | } 15 | 16 | public void setToken(String token) { 17 | this.token = token; 18 | } 19 | } -------------------------------------------------------------------------------- /src/test/java/com/uiautomation/runners/APITest.java: -------------------------------------------------------------------------------- 1 | package com.uiautomation.runners; 2 | 3 | import cucumber.api.CucumberOptions; 4 | import net.serenitybdd.cucumber.CucumberWithSerenity; 5 | import org.junit.runner.RunWith; 6 | 7 | @RunWith(CucumberWithSerenity.class) 8 | @CucumberOptions(features = { "src/test/resources/features/api/registeruser.feature" }, glue = { 9 | "com.uiautomation.apisteps" }) 10 | public class APITest { 11 | } 12 | -------------------------------------------------------------------------------- /src/test/java/com/uiautomation/runners/GoogleSearchTest.java: -------------------------------------------------------------------------------- 1 | package com.uiautomation.runners; 2 | 3 | import cucumber.api.CucumberOptions; 4 | import net.serenitybdd.cucumber.CucumberWithSerenity; 5 | import org.junit.runner.RunWith; 6 | 7 | @RunWith(CucumberWithSerenity.class) 8 | @CucumberOptions(features= {"src/test/resources/features/nlbc/googlesearch.feature"},glue = { 9 | "com.uiautomation.steps"}) 10 | public class GoogleSearchTest {} 11 | -------------------------------------------------------------------------------- /src/test/java/com/uiautomation/runners/JoinNLBCTest.java: -------------------------------------------------------------------------------- 1 | package com.uiautomation.runners; 2 | 3 | import cucumber.api.CucumberOptions; 4 | import net.serenitybdd.cucumber.CucumberWithSerenity; 5 | import org.junit.runner.RunWith; 6 | 7 | @RunWith(CucumberWithSerenity.class) 8 | @CucumberOptions(features = { "src/test/resources/features/nlbc/signUp.feature" }, glue = { "com.uiautomation.steps" }) 9 | public class JoinNLBCTest { 10 | } 11 | -------------------------------------------------------------------------------- /src/test/java/com/uiautomation/runners/LoginNLBCTest.java: -------------------------------------------------------------------------------- 1 | package com.uiautomation.runners; 2 | 3 | import cucumber.api.CucumberOptions; 4 | import net.serenitybdd.cucumber.CucumberWithSerenity; 5 | import org.junit.runner.RunWith; 6 | 7 | @RunWith(CucumberWithSerenity.class) 8 | @CucumberOptions(features = { "src/test/resources/features/nlbc/login.feature" }, glue = { "com.uiautomation.steps" }) 9 | public class LoginNLBCTest { 10 | } 11 | -------------------------------------------------------------------------------- /src/test/java/com/uiautomation/steps/GoogleSearchStep.java: -------------------------------------------------------------------------------- 1 | package com.uiautomation.steps; 2 | 3 | import com.uiautomation.actions.GoogleSearchActions; 4 | 5 | import cucumber.api.java.en.Given; 6 | import cucumber.api.java.en.Then; 7 | import cucumber.api.java.en.When; 8 | import net.thucydides.core.annotations.Steps; 9 | 10 | public class GoogleSearchStep { 11 | @Steps 12 | GoogleSearchActions googleSearchActions; 13 | 14 | @Given("I want to search in Google") 15 | public void iWantToSearchInGoogle() throws Throwable { 16 | googleSearchActions.openGoogleSearchPage(); 17 | } 18 | 19 | @When("I search for '(.*)'") 20 | public void iSearchFor(String searchRequest) throws Throwable { 21 | googleSearchActions.searchFor(searchRequest); 22 | } 23 | 24 | @Then("I should see link to '(.*)'") 25 | public void iShouldSeeLinkTo(String searchResult) throws Throwable { 26 | googleSearchActions.verifyResult(searchResult); 27 | } 28 | } -------------------------------------------------------------------------------- /src/test/java/com/uiautomation/steps/Hooks.java: -------------------------------------------------------------------------------- 1 | package com.uiautomation.steps; 2 | 3 | import cucumber.api.java.Before; 4 | import jline.internal.Log; 5 | import net.serenitybdd.core.Serenity; 6 | import net.thucydides.core.ThucydidesSystemProperty; 7 | import net.thucydides.core.pages.Pages; 8 | 9 | public class Hooks { 10 | 11 | //@Before 12 | public void setSessionVariables() { 13 | Serenity.setSessionVariable("Env").to("DEV"); 14 | Pages pages = new Pages(); 15 | 16 | //Read property name 17 | String url= pages.getConfiguration().getEnvironmentVariables().getProperty(ThucydidesSystemProperty.WEBDRIVER_BASE_URL.getPropertyName()); 18 | Log.info("Application URL: "+ url); 19 | 20 | //Set Property Name 21 | pages.getConfiguration().getEnvironmentVariables() 22 | .setProperty(ThucydidesSystemProperty.WEBDRIVER_BASE_URL.getPropertyName(),"http://www.nlbootcamps.com"); 23 | String url2= pages.getConfiguration().getEnvironmentVariables().getProperty(ThucydidesSystemProperty.WEBDRIVER_BASE_URL.getPropertyName()); 24 | Log.info("Application URL2: "+ url2); 25 | 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/test/java/com/uiautomation/steps/LoginNLBCSteps.java: -------------------------------------------------------------------------------- 1 | package com.uiautomation.steps; 2 | 3 | import org.junit.Assert; 4 | 5 | import com.uiautomation.pages.LoginPage; 6 | 7 | import cucumber.api.java.en.Given; 8 | import cucumber.api.java.en.Then; 9 | import cucumber.api.java.en.When; 10 | import jline.internal.Log; 11 | import net.serenitybdd.core.Serenity; 12 | 13 | public class LoginNLBCSteps { 14 | 15 | LoginPage loginPage; 16 | 17 | @Given("^the user is navigate to homepage$") 18 | public void the_user_is_navigate_to_homepage() throws Exception { 19 | Log.info("ENV: "+Serenity.sessionVariableCalled("Env")); 20 | loginPage.open(); 21 | Assert.assertTrue(loginPage.isNavigateToHomePage()); 22 | } 23 | 24 | @When("^the user click on join link$") 25 | public void the_user_click_on_join_link() throws Exception { 26 | loginPage.navigateJoinUserPage(); 27 | } 28 | 29 | @Then("^login user page should display to user$") 30 | public void register_user_page_should_display_to_user() throws Exception { 31 | Assert.assertTrue(loginPage.isNavigateToLoginPage()); 32 | } 33 | 34 | @When("^the user enters Invalid details$") 35 | public void the_user_enters_Invalid_details() throws Exception { 36 | loginPage.enterLoginCredentials("user", "password"); 37 | } 38 | 39 | @When("^clicks on login button$") 40 | public void clicks_on_login_with_email_button() throws Exception { 41 | loginPage.clickLoginButton(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/test/java/com/uiautomation/steps/SignUpNLBC.java: -------------------------------------------------------------------------------- 1 | package com.uiautomation.steps; 2 | 3 | import cucumber.api.java.en.Then; 4 | import cucumber.api.java.en.When; 5 | 6 | import org.junit.Assert; 7 | 8 | import com.uiautomation.pages.SignUpPage; 9 | 10 | public class SignUpNLBC { 11 | 12 | SignUpPage signUpPage; 13 | 14 | @Then("^User clicks on signup link on login page$") 15 | public void user_clicks_on_signup_link_on_login_page() throws Exception { 16 | signUpPage.navigateToSignUpUserPage(); 17 | } 18 | 19 | @When("^the user navigated to signup page$") 20 | public void the_user_navigated_to_signup_page() throws Exception { 21 | Assert.assertEquals(true, signUpPage.isNavigateToSignUpPage()); 22 | 23 | } 24 | 25 | @When("^User enters singup details as Email as \"([^\"]*)\" and Gender as \"([^\"]*)\"$") 26 | public void user_enters_singup_details_as_Email_as_and_Gender_as(String arg1, String arg2) throws Exception { 27 | signUpPage.enterSignUpDetails("test@test.com", "firstName", "lastName", "phoneNumber", "password", "cpassword"); 28 | signUpPage.clickSignUpButton(); 29 | } 30 | 31 | @Then("^the user should not registred successfuly with NLBC$") 32 | public void the_user_should_not_registred_successfuly_with_NLBC() throws Exception { 33 | Assert.assertEquals(true, signUpPage.isNavigateToSignUpPage()); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/com/uiautomation/utils/Constants.java: -------------------------------------------------------------------------------- 1 | package com.uiautomation.utils; 2 | 3 | public class Constants { 4 | public static final String TEST_DATA_BASEPATH = ".//testdata"; 5 | public static final String REGISTERUSER_REQUEST_DATA = "//registeruser.json"; 6 | public static final String REGISTERUSER_ENDPOINT = "https://reqres.in/api/register"; 7 | public static final String USER_ENDPOINT = "https://reqres.in/api/users"; 8 | } 9 | -------------------------------------------------------------------------------- /src/test/resources/features/api/registeruser.feature: -------------------------------------------------------------------------------- 1 | Feature: Automate Register and Login APIs for https://reqres.in/ 2 | 3 | Scenario: Register user for https://reqres.in/ using valid details 4 | Given the user have proper register request data 5 | When the user sents a POST request to register API with valid request 6 | Then register API should have status code as 201 and content-type as JSON 7 | And the register API should return proper json response -------------------------------------------------------------------------------- /src/test/resources/features/nlbc/googlesearch.feature: -------------------------------------------------------------------------------- 1 | Feature: Google search 2 | In order to find items 3 | As a generic user 4 | I want to be able to search with Google 5 | 6 | Scenario: Google search 7 | Given I want to search in Google 8 | When I search for 'Serenity BDD' 9 | Then I should see link to 'Serenity BDD - Automated Acceptance Testing with Style' 10 | 11 | Scenario Outline: Google search multiple 12 | Given I want to search in Google 13 | When I search for '' 14 | Then I should see link to '' 15 | Examples: 16 | | search_request | search_result | 17 | | Serenity BDD | Serenity BDD - Automated Acceptance Testing with Style | 18 | | Cucumber | Cucumber | 19 | -------------------------------------------------------------------------------- /src/test/resources/features/nlbc/login.feature: -------------------------------------------------------------------------------- 1 | Feature: Login to NLBC 2 | As a Student 3 | I want to Login NLBC 4 | to Learn new technologies 5 | 6 | Scenario: Login to NLBC with InValid Data 7 | Given the user is navigate to homepage 8 | When the user click on join link 9 | Then login user page should display to user 10 | When the user enters Invalid details 11 | And clicks on login button 12 | Then the user should not registred successfuly with NLBC 13 | -------------------------------------------------------------------------------- /src/test/resources/features/nlbc/signUp.feature: -------------------------------------------------------------------------------- 1 | Feature: Join NLBC 2 | As a Student 3 | I want to Join NLBC 4 | to Learn new technologies 5 | 6 | Scenario Outline: Join as Male Student with Valid Data 7 | Given the user is navigate to homepage 8 | When the user click on join link 9 | Then login user page should display to user 10 | And User clicks on signup link on login page 11 | When the user navigated to signup page 12 | And User enters singup details as Email as "" and Gender as "" 13 | Then the user should not registred successfuly with NLBC 14 | Examples: 15 | |Email|Gender|ValidationMessage| 16 | |Testuser@test.com|Male|| 17 | 18 | @Manual 19 | Scenario: Veify registred user 20 | Given Login to email service provider 21 | When click verification link in verification email 22 | -------------------------------------------------------------------------------- /testdata/registeruser.json: -------------------------------------------------------------------------------- 1 | { 2 | "email": "sydney@fife", 3 | "password": "pistol" 4 | } --------------------------------------------------------------------------------