|
1 | | -# coteafs-selenium |
| 1 | +<p align="center"> |
| 2 | + <a href=""> |
| 3 | + <img src="assets/coteafs-selenium-logo.png" width=300 padding=10 /> |
| 4 | + </a> |
| 5 | +</p> |
| 6 | + |
| 7 | +<h1 align="center">Selenium WebDriver wrapper Framework which supports Automation of most of the web browsers.</h1> |
| 8 | + |
| 9 | +[][home] |
| 10 | +[][circleci] |
| 11 | +[][coverage] |
| 12 | +[](https://sonarcloud.io/dashboard?id=com.github.wasiqb.coteafs%3Aselenium) |
| 13 | +[](https://sonarcloud.io/component_measures?id=com.github.wasiqb.coteafs%3Aselenium&metric=Maintainability) |
| 14 | +[](https://sonarcloud.io/component_measures?id=com.github.wasiqb.coteafs%3Aselenium&metric=Reliability) |
| 15 | +[](https://sonarcloud.io/component_measures?id=com.github.wasiqb.coteafs%3Aselenium&metric=Security) |
| 16 | +[](https://sonarcloud.io/component_measures?id=com.github.wasiqb.coteafs%3Aselenium&metric=new_vulnerabilities) |
| 17 | +[](https://sonarcloud.io/component_measures?id=com.github.wasiqb.coteafs%3Aselenium&metric=Duplications) |
| 18 | +[][maven] |
| 19 | +[](https://github.com/WasiqB/coteafs-selenium/releases) |
| 20 | +[](https://opensource.org/licenses/Apache-2.0) |
| 21 | + |
| 22 | +> **Detailed documentation on main project site is under development.** |
| 23 | +
|
| 24 | +## :question: What is this Framework about? |
| 25 | + |
| 26 | +This is a Selenium WebDriver wrapper Framework which enables robust, maintainable and easy to write test scripting. _**It supports latest Selenium WebDriver 4.0 (Alpha)**_ and is ready for main Selenium upgrade. |
| 27 | + |
| 28 | +## :bulb: What features does this framework offer? |
| 29 | + |
| 30 | +Nobody uses anything without knowing what it offers. Some of the key features which this framework offers are as follows: |
| 31 | + |
| 32 | +- Latest Selenium WebDriver 4.0 (Alpha 2) |
| 33 | +- On-demand highlighting of Elements |
| 34 | +- On-demand delay of test execution by allowing predefined delays |
| 35 | +- On-demand headless mode |
| 36 | +- Parallel execution of tests on different browsers |
| 37 | +- Support Chrome, Firefox, IE and Edge |
| 38 | +- CI / CD ready |
| 39 | + |
| 40 | +## :smile: How it is easy to write Tests with this Framework? |
| 41 | + |
| 42 | +Writing tests involves the following steps: |
| 43 | + |
| 44 | +1. :wrench: Config file |
| 45 | +1. :page_facing_up: Page object |
| 46 | +1. :runner: Page Action |
| 47 | +1. :ballot_box_with_check: Tests |
| 48 | + |
| 49 | +### :wrench: Config file. |
| 50 | + |
| 51 | +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`. But the same can be overridden by using System property `coteafs.selenium.config` where you can specify the new config file for the test. |
| 52 | + |
| 53 | +#### Sample Config file |
| 54 | + |
| 55 | +`src/test/resources/selenium-config.yaml` |
| 56 | + |
| 57 | +```yaml |
| 58 | +browser: CHROME # CHROME, EDGE, FIREFOX, IE. |
| 59 | +url: http://demo.guru99.com/V4/ # Application URL. |
| 60 | +headless_mode: false # true, for headless, else false. |
| 61 | +params: # test specific map. |
| 62 | + user: <test-specific-user> |
| 63 | + password: <test-specific-password> |
| 64 | +playback: # Playback settings. |
| 65 | + screen_state: NORMAL # FULL_SCREEN, MAXIMIZED, NORMAL |
| 66 | + highlight: true # true, to highlight elements, else false. |
| 67 | + screen_resolution: # Screen resolution settings. |
| 68 | + width: 1280 # Screen width. |
| 69 | + height: 768 # Screen height. |
| 70 | + delays: # On demand delay settings. |
| 71 | + implicit: 60 # Implicit waits in seconds. |
| 72 | + explicit: 60 # Explicit waits in seconds. |
| 73 | + before_key_press: 0 # delay before key press in milliseconds. |
| 74 | + after_key_press: 0 # delay after key press in milliseconds. |
| 75 | + before_mouse_move: 0 # delay before mouse move in milliseconds. |
| 76 | + after_mouse_move: 0 # delay after mouse move in milliseconds. |
| 77 | + before_click: 0 # delay before mouse click in milliseconds. |
| 78 | + after_click: 0 # delay after mouse click in milliseconds. |
| 79 | + page_load: 60 # page load timeout in seconds. |
| 80 | + script_load: 60 # script load timeout in seconds. |
| 81 | + highlight: 500 # highlight delay in milliseconds. |
| 82 | + screenshot: # Screenshot settings. |
| 83 | + path: ~/screenshots # default screenshot path. |
| 84 | + prefix: SCR # screenshot file prefix. |
| 85 | + extension: jpeg # screenshot file extension. |
| 86 | + capture_on_error: false # screenshot on error. |
| 87 | +``` |
| 88 | +
|
| 89 | +> **Note:** If you find any config not working, feel free to raise an [issue][]. |
| 90 | +
|
| 91 | +### :page_facing_up: Page objects |
| 92 | +
|
| 93 | +To know how to write tests, it's best to see the example as it is self explanatory. Lets have a look at the Login page of Guru99 demo site. |
| 94 | +
|
| 95 | +> Remember, `BrowserPage` class needs to be extended for every page and also a flavour of inheritance can be added as per requirement. |
| 96 | + |
| 97 | +#### Sample Page object |
| 98 | + |
| 99 | +```java |
| 100 | +package com.github.wasiqb.coteafs.selenium.pages; |
| 101 | +
|
| 102 | +import org.openqa.selenium.By; |
| 103 | +
|
| 104 | +import com.github.wasiqb.coteafs.selenium.core.BrowserPage; |
| 105 | +import com.github.wasiqb.coteafs.selenium.core.element.IElementActions; |
| 106 | +import com.github.wasiqb.coteafs.selenium.core.element.IMouseActions; |
| 107 | +import com.github.wasiqb.coteafs.selenium.core.element.ITextboxActions; |
| 108 | +
|
| 109 | +public class LoginPage extends BrowserPage { |
| 110 | + public ITextboxActions password () { |
| 111 | + return form ().find (By.name ("password")); |
| 112 | + } |
| 113 | +
|
| 114 | + public IMouseActions signIn () { |
| 115 | + return form ().find (By.name ("btnLogin")); |
| 116 | + } |
| 117 | +
|
| 118 | + public ITextboxActions userId () { |
| 119 | + return form ().find (By.name ("uid")); |
| 120 | + } |
| 121 | +
|
| 122 | + private IElementActions form () { |
| 123 | + return onElement (By.name ("frmLogin")); |
| 124 | + } |
| 125 | +} |
| 126 | +``` |
| 127 | + |
| 128 | +### :runner: Page Action |
| 129 | + |
| 130 | +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. |
| 131 | + |
| 132 | +> 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. |
| 133 | +> Also, `perform` method needs to be implemented for every action class. |
| 134 | + |
| 135 | +#### Sample page action |
| 136 | + |
| 137 | +```java |
| 138 | +package com.github.wasiqb.coteafs.selenium.pages.action; |
| 139 | +
|
| 140 | +import com.github.wasiqb.coteafs.selenium.core.page.AbstractPageAction; |
| 141 | +import com.github.wasiqb.coteafs.selenium.pages.LoginPage; |
| 142 | +import com.github.wasiqb.coteafs.selenium.pages.MainPage; |
| 143 | +
|
| 144 | +public class LoginPageAction extends AbstractPageAction <LoginPageAction> { |
| 145 | + @Override |
| 146 | + public void perform () { |
| 147 | + final LoginPage login = new LoginPage (); |
| 148 | + login.userId () |
| 149 | + .enterText (value ("UserId")); |
| 150 | + login.password () |
| 151 | + .enterText (value ("Password")); |
| 152 | + login.signIn () |
| 153 | + .click (); |
| 154 | +
|
| 155 | + final MainPage main = new MainPage (); |
| 156 | + main.managerIdBanner () |
| 157 | + .verifyText () |
| 158 | + .endsWith ("Manger Id : " + value ("UserId")); |
| 159 | + } |
| 160 | +} |
| 161 | +``` |
| 162 | + |
| 163 | +### :white_check_mark: Tests |
| 164 | + |
| 165 | +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: |
| 166 | + |
| 167 | +#### Sample Test |
| 168 | + |
| 169 | +> Every test class extends `BrowserTest` class. |
| 170 | + |
| 171 | +```java |
| 172 | +package com.github.wasiqb.coteafs.selenium; |
| 173 | +
|
| 174 | +import static com.github.wasiqb.coteafs.selenium.config.ConfigUtil.appSetting; |
| 175 | +
|
| 176 | +import org.testng.annotations.BeforeClass; |
| 177 | +import org.testng.annotations.Test; |
| 178 | +
|
| 179 | +import com.github.wasiqb.coteafs.selenium.core.BrowserTest; |
| 180 | +import com.github.wasiqb.coteafs.selenium.pages.MainPage; |
| 181 | +import com.github.wasiqb.coteafs.selenium.pages.action.LoginPageAction; |
| 182 | +
|
| 183 | +public class SeleniumTest extends BrowserTest { |
| 184 | + private MainPage main; |
| 185 | +
|
| 186 | + @BeforeClass |
| 187 | + public void setupMethod () { |
| 188 | + this.main = new MainPage (); |
| 189 | + this.main.onDriver () |
| 190 | + .navigateTo (appSetting ().getUrl ()); |
| 191 | + } |
| 192 | +
|
| 193 | + @Test |
| 194 | + public void testSignIn () { |
| 195 | + final LoginPageAction login = new LoginPageAction (); |
| 196 | + login.addInputValue ("UserId", appSetting ().getParams () |
| 197 | + .get ("user")) |
| 198 | + .addInputValue ("Password", appSetting ().getParams () |
| 199 | + .get ("password")) |
| 200 | + .perform (); |
| 201 | + } |
| 202 | +} |
| 203 | +``` |
| 204 | + |
| 205 | +## :pushpin: Usage? |
| 206 | + |
| 207 | +You can use the following dependency into your `pom.xml` to use this library. |
| 208 | + |
| 209 | +```xml |
| 210 | +<dependency> |
| 211 | + <groupId>com.github.wasiqb.coteafs</groupId> |
| 212 | + <artifactId>selenium</artifactId> |
| 213 | + <version>2.0.0</version> |
| 214 | +</dependency> |
| 215 | +``` |
| 216 | + |
| 217 | +## :question: Need Assistance? |
| 218 | + |
| 219 | +- Directly chat with me on my [site][] and I'll revert to you as soon as possible. |
| 220 | +- Discuss your queries by writing to me @ [wasbhamla2005@gmail.com][mail] |
| 221 | +- If you find any issue which is bottleneck for you, [search the issue tracker][tracker] to see if it is already raised. |
| 222 | +- If not raised, then you can create a [new issue][issue] with required details as mentioned in the issue template. |
| 223 | + |
| 224 | +## :star2: What you do if you like the project? |
| 225 | + |
| 226 | +- Spread the word with your network. |
| 227 | +- **Star** the project to make the project popular. |
| 228 | +- Stay updated with the project progress by **Watching** it. |
| 229 | +- **Contribute** to fix open issues, documentations or add new features. To know more, see our [contributing][] page. |
| 230 | +- I would be delighted if you can **Sponsor** this project and provide your support to open source development by clicking on the Sponsor button on the top of this repository. |
| 231 | + |
| 232 | +## :white_check_mark: Contributors |
| 233 | + |
| 234 | +<div> |
| 235 | + <ul> |
| 236 | + <li> |
| 237 | + <a href="https://github.com/WasiqB"> |
| 238 | + <img alt="Wasiq Bhamla: Framework developer and maintainer." src="https://github.com/WasiqB.png" width=100 height=100 /> |
| 239 | + </a> |
| 240 | + </li> |
| 241 | + <li> |
| 242 | + <a href="https://github.com/mfaisalkhatri"> |
| 243 | + <img alt="Mohammad Faisal Khatri: Framework Tester." src="https://github.com/mfaisalkhatri.png" width=100 height=100 /> |
| 244 | + </a> |
| 245 | + </li> |
| 246 | + </ul> |
| 247 | +</div> |
| 248 | + |
| 249 | +## :ticket: Versioning ideology |
| 250 | + |
| 251 | +<p align="left"> |
| 252 | + <a href="http://semver.org/"> |
| 253 | + <img src="assets/semver.png" width=300 /> |
| 254 | + </a> |
| 255 | +</p> |
| 256 | + |
| 257 | +## :copyright: Wasiq Bhamla |
| 258 | + |
| 259 | +<p align="left"> |
| 260 | + <a href="http://www.apache.org/licenses/LICENSE-2.0"> |
| 261 | + <img src="http://www.apache.org/img/asf_logo.png" width=300 /> |
| 262 | + </a> |
| 263 | +</p> |
| 264 | + |
| 265 | +[home]: https://github.com/wasiqb/coteafs-selenium |
| 266 | +[circleci]: https://circleci.com/gh/WasiqB/coteafs-selenium |
| 267 | +[coverage]: https://sonarcloud.io/component_measures?id=com.github.wasiqb.coteafs%3Aselenium&metric=Coverage |
| 268 | +[maven]: https://maven-badges.herokuapp.com/maven-central/com.github.wasiqb.coteafs/selenium |
| 269 | +[site]: https://wasiqb.github.io |
| 270 | +[tracker]: https://github.com/WasiqB/coteafs-selenium/issues?q=something |
| 271 | +[issue]: https://github.com/WasiqB/coteafs-selenium/issues/new |
| 272 | +[contributing]: .github/CONTRIBUTING.md |
| 273 | +[mail]: mailto:wasbhamla2005@gmail.com |
0 commit comments