Giter Site home page Giter Site logo

umutayb / pickleib Goto Github PK

View Code? Open in Web Editor NEW
10.0 5.0 8.0 855 KB

Quickstart library for test automation projects capable of webUI, mobileUI, API, database, data layer & email tests.

License: MIT License

Java 100.00%
selenium selenium-webdriver java maven api-testing-framework appium database-testing test test-automation

pickleib's Introduction

Pickleib

Maven Central

Description

Pickleib is a utility library for software automation projects. It helps you design and run tests with Selenium WebDriver in a simple and efficient way. It provides a set of utilities and ready to go driver setup that provide great convenience for designing test automations.

Some features and benefits of using Pickleib are:

  • Easy configuration: You can set up your test environment with minimal code! Pickleib supports different browsers, drivers, timeouts, etc.
  • Utilities: Pickleib has various utilities that can help you interact with WebElements in a consistent/non-flaky way. Check basic interaction methods such as click, fill, scroll, or more advanced utilities like element state, element attribute verifications. Find these at WebUtilities.java
  • Page Object Model: Pickleib can be use the Page Object Model pattern to organize your web elements and actions in separate classes. Pickleib provides classes and methods to simplify this process.
  • API support: Pickleib has built in api capabilities that enable defining calls to endpoints, model request & response bodies as well as verifying response details, testing frontend interactions against backends
  • Emails: It has email capabilities that enable sending or receiving emails directly in the framework. This feature is further supported by utilities that acquire email HTML and test email design, content and structure using the web driver.
  • Database: Pickleib provides database connection capabilities with JDBC. Database utilities can be used to establish an SQL connection, pass queries and map the results.
  • Data Layer: Built in data layer desting capabilities allow verifying specific events or data stored in the data layer.

Installation

To use Pickleib in your Maven project, add the following dependency to your pom.xml file:

<dependency>
    <groupId>io.github.umutayb</groupId>
    <artifactId>Pickleib</artifactId>
    <version>1.x.x</version>
</dependency>

After updating your project, the quickstart library is ready to use.


Usage

The quickstart library consists of many utility methods and a ready to use web driver, database connection & api handling. It is compatible with page object model design. The infrastructure allows easy initialization of elements by initializing them within a constructor inside the WebUtilities class. In order to initialize elements inside a page class, all it takes is to extend the WebUtilities class. This also extends the Driver class, allowing usage of driver inside page classes.

Step 1: Create a pages package

Implement page objects, add elements (use @FindBy annotation) & page methods. Remember extending WebUtilities class, initializing all elements within the page class.

import utils.WebUtilities;

public class HomePage extends WebUtilities {...}

Step 2: Create a steps package

Create page step classes, instantiate page classes, create step definitions & access page methods within these step definitions as:

public class HomePageSteps {
   
   HomePage homePage = new HomePage();

   @Given("Click category card named {}")
   public void clickCategoryCard(String cardName) {
       homePage.clickCategoryCardNamed(cardName);
   }
}

Alternatively, use the reflection steps found in PickleibSteps class.

Create an ObjectRepository class, instantiate all page objects in it;

public class ObjectRepository {

   HomePage homePage = new HomePage();

}

Then input a new instance of ObjectRepository object to PickleibSteps methods;

import steps.PickleibSteps;
import utils.driver.Driver;

public class CommonSteps extends PickleibSteps {
   @Given("If present, click the {} on the {}")
   public void clickIfPresent(String buttonName, String pageName){
       log.new Info("Clicking " +
               highlighted(BLUE, buttonName) +
               highlighted(GRAY," on the ") +
               highlighted(BLUE, pageName) +
               highlighted(GRAY, ", if present...")
       );
       pageName = strUtils.firstLetterDeCapped(pageName);
       try {
           WebElement element = getElementFromPage(buttonName, pageName, new ObjectRepository());
           if (elementIs(element, ElementState.DISPLAYED)) clickElement(element, true);
       }
       catch (WebDriverException ignored){log.new Warning("The " + buttonName + " was not present");}
   }
}    

If using cucumber, set @Before & @After steps as:

import utils.driver.Driver;

public class CommonSteps {
   @Before
   public void start() {
       Driver.initialize();
   }

   @After
   public void kill(Scenario scenario) {
       Driver.terminate();
   }
}    

Use your reflection step to interact with the element;

@TestEnv @Web-UI @SCN-Click-If-Present
Scenario: Test cookie accept button 
  * Navigate to the test page
  * If present, click the cookieAcceptButton on the HomePage

Set up your test runner

@RunWith(Cucumber.class)
@CucumberOptions(
        features = {"src/test/java/features"},
        plugin = {"json:target/reports/Cucumber.json"},
        glue = {"steps"},
        publish = true
)
public class TestRunner {

    @BeforeClass
    public static void initialSequence(){...}

    @AfterClass
    public static void finalSequence(){...}
}

This will initialize the driver before each run, and kill it after each scenario is done.

Execution

In order to execute a specific feature file on a given browser, use:

mvn clean test -q -Dcucumber.filter.tags="@TestEnv and @SCN-Click-If-Present" -Dbrowser=chrome
It is recommended to use Pickleib as designed in Web-Automation-Smaple-Cucumber project

To create a cucumber project from scratch instead, run the following command in your command line:

mvn archetype:generate                      \
"-DarchetypeGroupId=io.cucumber"            \
"-DarchetypeArtifactId=cucumber-archetype"  \
"-DarchetypeVersion=6.10.4"                 \
"-DgroupId=hellocucumber"                   \
"-DartifactId=hellocucumber"                \
"-Dpackage=hellocucumber"                   \
"-Dversion=1.0.0-SNAPSHOT"                  \
"-DinteractiveMode=false"
Local tests:
docker run -p 8080:8080 umutayb/vue-test-website

pickleib's People

Contributors

beyazgulsamil avatar egecansen avatar innadrapii avatar roydekleijn avatar scshaimaaelbazedy avatar thenutester avatar tugrulhandogan avatar umutayb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.