Skip to content

Proof-of-concept for web test automation framework starter kit using using Java, Cucumber, Selenium, and Page-Object model design pattern

License

Notifications You must be signed in to change notification settings

ERNI-Academy/poc-testing-bbd-web-test-automation

Repository files navigation

About

Proof-of-concept for web test automation framework starter kit using using Java, Cucumber, Selenium, and Page-Object model design pattern. This POC will be particularly advantageous for projects which are using the Java ecosystem.

Built With

Features

  • Browser test automation
  • Behavior-driven approach
  • Parallel test execution
  • Reports generation after test execution

Getting Started

Installation instructions by running:

  1. Clone the repository

  2. Build and install using Maven command (clean and install)

  3. Implement Page objects corresponding to the pages of the Application under Test.

    a. Create java package under src/test/java (e.g. com.erni.pageobjects.sprout)

    b. Create a Page Object java class, make sure to extend PageBase class to inherit the Core libraries instances.

    public class LoginPO extends PageBase{

    c. Add page web elements by using annotation @FindBy

    @FindBy(how = How.ID, using = "txtUsername") 
    WebElement txtUserName;
    
    @FindBy(how = How.ID, using = "txtPassword") 
    WebElement txtPassword;
    
    @FindBy(how = How.ID, using = "btnLogIn") 
    WebElement btnLogin;

    d. Call the Selenium’s PageFactory initElements to initiate the page web elements

    PageFactory.initElements(driver, this);

    e. Add the page actions as java functions. Use the built-in functions which are inherited from PageBase class.

    public LoginPO enterUsername(String userName) {
         try {
      	   input.sendKeys(txtUserName, userName);
         } catch(Exception e) {
      	   logger.error("Error occurred in enterUsername()", e);
         }
         return this;
     }
  4. Create Features which will serve as the test cases/scenarios for this test suite

    a. Create a file directory under src/test/resources. This will be the folder of all the AUT test scenarios

    b. Create a feature file. File extension should be .feature

    c. Create test scenarios. Observe the Gherkin template (Given-When-Then)

    Feature: Login verification
       Features include all the scenarios for login
    
    Scenario: Sprout login
        Given current url is "https://erni.hrhub.ph/Login.aspx"
        When user enters valid username and password
        And user clicks login button
        Then login successful
  5. Create the Feature’s step definitions

    a. Create java package under src/test/java (e.g. com.erni.stepdefinitions)

    b. Create a Step Definition java class, make sure to extend StepDefinition parent class to inherit the common functions used for step definitions.

    public class LoginDefinition extends StepDefinition{

    c. Create instance variables to declare the path for the test data

    private static final String EXCEL_FILE_PATH = "test-data/test-data-sprout.xlsx";
    private static final String EXCEL_SHEET_NAME = "Login";

    d. Create step definitions

    @Given("current url is {string}")
     public void isUrlCorrect(String url) {
      try {
          loginPO.isUrlCorrect(url);
      } catch (Exception e) {
          logger.error("Error occurred in isUrlCorrect()", e);
      }
    }
    
    @When("enter password {string}")
    public void enterPassword(String password) {
      try {
      	loginPO.enterPassword(password);
      } catch (Exception e) {
          logger.error("Error occurred in enterPassword()", e);
      }
    }
    
    @Then("login successful")
    public void isLoginSuccessful() {
      LoginPO loginPO = pageObjectFactory.createLoginPO();
      
      try {
      	loginPO.isLoginSuccessful();
      } catch (Exception e) {
          logger.error("Error occurred in clickLoginBtn()", e);
          throw e;
      }
    }
  6. Update Hooks class (Hooks.java). Implement setup and teardown. Use @Before annotation for setup and @After for teardown. Note that the method marked with @Before annotation will be invoked before executing the test scenario/feature, whereas the one annotated with @After will be invoked immediately after the execution of the test scenario/feature.

  7. Define the test configuration by updating the src/test/resources/config.properties. Feel free to add specific configurations in that file.

    browser=googlechrome
    hubAddress=http://localhost:4444/wd/hub
    baseUrl=https://example.com/
  8. Create a Cucumber test runner and add it in TestNG.xml which resides /test-suite folder. TestNG.xml is test configuration of TestNG engine.

  9. Selenium Grid’s Hub and Node which are included in the cloned code base have default configuration to run in the localhost. Feel free to setup the Hub and Nodes configuration to run in your desired environment.

Contributing

Please see our Contribution Guide to learn how to contribute.

License

MIT

Copyright © 2023 ERNI - Swiss Software Engineering

Code of conduct

Please see our Code of Conduct

Stats

Check https://repobeats.axiom.co/ for the right URL

Follow us

Twitter Follow Twitch Status YouTube Channel Views Linkedin

Contact

📧 [email protected]

Contributors ✨

Thanks goes to these wonderful people (emoji key):

This project follows the all-contributors specification. Contributions of any kind welcome!

About

Proof-of-concept for web test automation framework starter kit using using Java, Cucumber, Selenium, and Page-Object model design pattern

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published