WasiqB / coteafs-selenium

:computer: Selenium WebDriver wrapper framework in Java for clean and maintainable tests.
https://wasiqb.github.io/projects/selenium/
Apache License 2.0
77 stars 35 forks source link
automation-framework automation-test cross-browser hacktoberfest java selenium selenium-webdriver software-testing test-automation testing-tools

🚨🚨 This project is no longer maintained!

📢 I have created new project Boyka-Framework which has all the functionality this project provides and many more features.

PLEASE START USING BOYKA-FRAMEWORK INSTEAD!!!

Selenium WebDriver wrapper Framework in Java, which supports Automation of most of the web browsers.

[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/WasiqB/coteafs-selenium) [![Open Source Love](https://badges.frapsoft.com/os/v1/open-source.svg?v=103)][home] [![Discord](https://img.shields.io/discord/874329599285268561?label=Discord&logo=Discord&style=for-the-badge)](https://discord.gg/DWVM398zsC) [![GitHub Actions workflow](https://github.com/WasiqB/coteafs-selenium/actions/workflows/test.yml/badge.svg)](https://github.com/WasiqB/coteafs-selenium/actions/workflows/test.yml) ![CodeQL](https://github.com/WasiqB/coteafs-selenium/workflows/CodeQL/badge.svg) [![Test Coverage](https://sonarcloud.io/api/project_badges/measure?project=com.github.wasiqb.coteafs%3Aselenium&metric=coverage)][coverage] [![Quality Gate](https://sonarcloud.io/api/project_badges/measure?project=com.github.wasiqb.coteafs%3Aselenium&metric=alert_status)](https://sonarcloud.io/dashboard?id=com.github.wasiqb.coteafs%3Aselenium) [![Maintainability](https://sonarcloud.io/api/project_badges/measure?project=com.github.wasiqb.coteafs%3Aselenium&metric=sqale_rating)](https://sonarcloud.io/component_measures?id=com.github.wasiqb.coteafs%3Aselenium&metric=Maintainability) [![Reliability](https://sonarcloud.io/api/project_badges/measure?project=com.github.wasiqb.coteafs%3Aselenium&metric=reliability_rating)](https://sonarcloud.io/component_measures?id=com.github.wasiqb.coteafs%3Aselenium&metric=Reliability) [![Security](https://sonarcloud.io/api/project_badges/measure?project=com.github.wasiqb.coteafs%3Aselenium&metric=security_rating)](https://sonarcloud.io/component_measures?id=com.github.wasiqb.coteafs%3Aselenium&metric=Security) [![Vulnerability](https://sonarcloud.io/api/project_badges/measure?project=com.github.wasiqb.coteafs%3Aselenium&metric=vulnerabilities)](https://sonarcloud.io/component_measures?id=com.github.wasiqb.coteafs%3Aselenium&metric=new_vulnerabilities) [![Duplicate Code](https://sonarcloud.io/api/project_badges/measure?project=com.github.wasiqb.coteafs%3Aselenium&metric=duplicated_lines_density)](https://sonarcloud.io/component_measures?id=com.github.wasiqb.coteafs%3Aselenium&metric=Duplications) [![Maven Central](https://img.shields.io/maven-central/v/com.github.wasiqb.coteafs/selenium.svg)][maven] [![Github Releases](https://img.shields.io/github/downloads/WasiqB/coteafs-selenium/total.svg)](https://github.com/WasiqB/coteafs-selenium/releases) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)

Detailed documentation on main project site is under development.

:question: What is this Framework about?

This is a Selenium WebDriver wrapper Framework which enables robust, maintainable and easy to write test scripts. It supports the latest stable Selenium WebDriver 4.1.1.

:bulb: What features do this framework offer?

Some key features which this framework offers are as follows:

:point_right: Latest stable Selenium WebDriver 4.1.1

:point_right: Minimal learning curve.

:point_right: Supports Chrome, Safari, Firefox, IE and Edge

:point_right: Supports execution on BrowserStack, SauceLabs and Selenium Grid.

:point_right: On-demand highlighting of Elements.

:point_right: On-demand video recording and screenshots.

:point_right: On-demand delay of test execution by allowing predefined delays.

:point_right: On-demand headless mode execution for Chrome and Firefox.

:point_right: Inline verification of elements.

:point_right: Supports logging of events to Log file.

:point_right: Supports all major test frameworks like TestNG, JUnit, Cucumber, etc.

:point_right: Parallel execution of tests on different browsers.

:pushpin: Usage?

You can use the following dependency into your pom.xml to use this library.


<dependency>
    <groupId>com.github.wasiqb.coteafs</groupId>
    <artifactId>selenium</artifactId>
    <version>4.2.0</version>
</dependency>

Or you can add the following into your build.gradle file.

 compile "com.github.wasiqb.coteafs:selenium:4.2.0"

:smile: How it is easy to write Tests with this Framework?

Getting hands-on with this framework requires minimal time. You can start writing tests in following 4 simple steps.

1. :wrench: Create Config file
Config file is by default searched in `src/test/resources` folder. The name of the config file is by default considered as `selenium-config.yaml`. ### Sample Config file `src/test/resources/selenium-config.yaml` ```yaml browsers: local_browser: browser: CHROME # CHROME, SAFARI, EDGE, FIREFOX, IE. url: http://demo.guru99.com/V4/ # Application URL. headless_mode: false # true, for headless, else false. driver: # Driver manager specific settings. force_cache: true # true, false (default). Forces to use cached driver. force_download: true # true, false (default). Forces to download driver each time. path: /drivers/ # Local path where drivers will searched for. version: 2.14 # Version of driver. exe_url: https://driver/download/url # Driver download URL. remote: # Remote settings block (required when Browser is Remote). user_id: ${CLOUD_USER} # Cloud User. Not required for Grid. password: ${CLOUD_KEY} # Cloud Key. Not required for Grid. protocol: HTTPS # HTTP, HTTPS. Default HTTP. url: hub-cloud.browserstack.com # Remote hub URL source: BROWSERSTACK # BROWSERSTACK, GRID, SAUCELABS capabilities: # Remote capabilities. browser: Chrome browser_version: 75.0 os: Windows os_version: 10 resolution: 1024x768 name: Any Test name cloud_capabilities: # Cloud specific capabilities. seleniumVersion: 3.141.59 name: Sauce-[Java] Sample Test params: # test specific map. user: password: playback: # Playback settings. screen_state: NORMAL # FULL_SCREEN, MAXIMIZED, NORMAL highlight: true # true, to highlight elements, else false. screen_resolution: # Screen resolution settings. width: 1280 # Screen width. height: 768 # Screen height. recording: enable: true # true, to enable recording, else false. path: ./video # Video recording path. prefix: VID # Video file prefix. delays: # On demand delay settings. implicit: 60 # Implicit waits in seconds. explicit: 60 # Explicit waits in seconds. after_frame_switch: 500 # Delay after iFrame switch in milliseconds. after_window_switch: 500 # Delay after Window switch in milliseconds. before_key_press: 0 # delay before key press in milliseconds. after_key_press: 0 # delay after key press in milliseconds. before_mouse_move: 0 # delay before mouse move in milliseconds. after_mouse_move: 0 # delay after mouse move in milliseconds. before_click: 0 # delay before mouse click in milliseconds. after_click: 0 # delay after mouse click in milliseconds. page_load: 60 # page load timeout in seconds. script_load: 60 # script load timeout in seconds. highlight: 500 # highlight delay in milliseconds. screenshot: # Screenshot settings. path: ~/screenshots # default screenshot path. prefix: SCR # screenshot file prefix. extension: jpeg # screenshot file extension. capture_on_error: false # screenshot on error. capture_all: true # always capture screenshot on each event, when true. ``` > **Note:** If you find any config not working, feel free to raise [an issue][].
2. :page_facing_up: Create Page object class
Checkout the following examples which will guide you in writing tests. Let's have a look at the Login page of Guru99 demo site. > Remember, `BrowserPage` class needs to be extended for every page and also a flavour of inheritance can be added as per requirement. ### Sample Page object ```java package com.github.wasiqb.coteafs.selenium.pages; import com.github.wasiqb.coteafs.selenium.core.element.ITextBoxActions; import org.openqa.selenium.By; import com.github.wasiqb.coteafs.selenium.core.BrowserPage; import com.github.wasiqb.coteafs.selenium.core.element.IMouseActions; public class LoginPage extends BrowserPage { public ITextBoxActions password () { return form ().find (By.name ("password"), "Password"); } public IMouseActions signIn () { return form ().find (By.name ("btnLogin"), "Login"); } public ITextBoxActions userId () { return form ().find (By.name ("uid"), "User ID"); } private IMouseActions form () { return onClickable (By.name ("frmLogin"), "Form"); } } ```
3. :runner: Create Page Action class
This is a new concept, here you can define actions specific to each page. This approach abstracts out the page action flows and helps in modularising the classes. So whenever the flow of the page changes, you need to change only at single place. > For every page action you need to extend `AbstractPageAction`. Since it is a generic class, you need to pass the action class name as it's generic type. > Also, `perform` method needs to be implemented for every action class. ### Sample page action ```java package com.github.wasiqb.coteafs.selenium.pages.action; import static java.text.MessageFormat.format; import com.github.wasiqb.coteafs.selenium.core.page.AbstractPageAction; import com.github.wasiqb.coteafs.selenium.pages.LoginPage; import com.github.wasiqb.coteafs.selenium.pages.MainPage; public class LoginPageAction extends AbstractPageAction { public static final String PASS = "password"; public static final String USER_ID = "userId"; @Override public void perform () { final LoginPage login = new LoginPage (); login.userId () .enterText (value (USER_ID)); login.password () .enterText (value (PASS)); login.signIn () .click (); login.nextPage (MainPage.class) .managerIdBanner () .verifyText () .endsWith (format ("Manger Id : {0}", value (USER_ID).toString ())); } } ```
4. :white_check_mark: Write Test class
Test which are written using this framework are slightly different than usual. In the tests, Page actions is used instead of page objects. This can be demonstrated as shown below: ### Sample Test > Every test class extends `BrowserTest` class. ```java package com.github.wasiqb.coteafs.selenium; import static com.github.wasiqb.coteafs.selenium.config.ConfigUtil.appSetting; import static com.github.wasiqb.coteafs.selenium.pages.action.LoginPageAction.PASS; import static com.github.wasiqb.coteafs.selenium.pages.action.LoginPageAction.USER_ID; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import com.github.wasiqb.coteafs.selenium.core.BrowserTest; import com.github.wasiqb.coteafs.selenium.pages.MainPage; import com.github.wasiqb.coteafs.selenium.pages.action.LoginPageAction; public class SeleniumTest extends BrowserTest { @BeforeClass public void setupMethod () { final MainPage main = new MainPage (); main.onDriver () .navigateTo (appSetting ().getUrl ()); } @Test public void testSignIn () { final LoginPageAction login = new LoginPageAction (); login.addInputValue (USER_ID, appSetting ().getParams () .get ("user")) .addInputValue (PASS, appSetting ().getParams () .get ("password")) .perform (); } } ```
5. :microscope: Create TestNG XML file
### Basic synchronous run Following is a simple `testng.yaml` file for running the tests on Chrome browser **locally, on grid and on BrowserStack** in sync. ```yaml name: Local Suite tests: - name: Test Local preserveOrder: true parameters: { test.browser: local } classes: - name: com.github.wasiqb.coteafs.selenium.SeleniumTest includedMethods: - testLogin - testCheckboxes - testDropDownBox - name: Test Grid parameters: { test.browser: grid } classes: - name: com.github.wasiqb.coteafs.selenium.SeleniumTest includedMethods: - testLogin - name: Test BrowserStack Chrome preserveOrder: true parameters: { test.browser: bs_chrome } classes: - name: com.github.wasiqb.coteafs.selenium.SeleniumTest includedMethods: - testLogin - testCheckboxes - testDropDownBox ``` - `test.browser`: Here, the browser config key is used to tell the framework which browser config needs to be executed.
6. :cyclone: Running TestNG XML file
### Running on local browsers or on Selenium Grid Run the tests using following command, ```bash $ mvn clean install -Dsuite-xml=testng.yaml ``` ### Running on BrowserStack or any other cloud solution Run the tests using following command, ```bash $ mvn clean install -Dsuite-xml=testng.yaml -DCLOUD_USER= -DCLOUD_KEY= ```

:question: Need Assistance?

:star2: What you do if you like the project?

:gift_heart: Thanks for the support.

For allowing us to run our unit tests on different cloud platforms.

:white_check_mark: Contributors

:ticket: Versioning ideology

:copyright: Wasiq Bhamla