Git Product home page Git Product logo

selenium4poc's Introduction

Open Source Love License Java CI with Maven CodeQL

Don't forget to give a ⭐ to make the project popular.

❓ What is this Repository about?

Talking more about the Scenarios Covered in this project:

  • I have tried to answer the below questions by providing working code example in this repo:
  1. How do I select a value from Table?
  2. How do I tick and untick checkboxes using selenium
  3. How do I right-click using selenium?
  4. How do I drag and drop using selenium?
  5. How do I write code to log in and logout using Selenium?
  6. How do I pass multiple test data value using DataProvider in tests?
  7. How do I mouse hover an element using selenium?
  8. How do I download a file using Selenium?
  9. How do I upload file using selenium?
  10. How do I press keys using selenium?
  11. How do I work with multiple Tab windows in selenium?
  12. How do I work with iFrames using Selenium?
  13. How do I double-click using Selenium WebDriver?
  14. How to check for chrome generated logs when selenium tests are run?

✍️ Blog Links

🎥 Tutorial Videos

Watch the video Watch the video Watch the video Watch the video Watch the video Watch the video Watch the video

End-to-End Tests for OWASP-Juice-Shop

  • End-to-End tests for Juice Shop Website are running on http://localhost:3000 inside the container in GitHub actions.
  • GitHub Actions is used for setting up CI/CD Pipeline

Following is the Automation Test Strategy used for writing End-to-End Tests:

  1. User will navigate to the website and close all the pop-up first.
  2. User will click on Login link and click on Not yet a customer link and register himself on the website.
  3. Once the Registration is successful, User will Log in with that username and password.
  4. After successful Login, User will Add AppleJuice and BananaJuice to the Basket.
  5. After asserting the messages for items added to basket, user will check for the count of items displayed on top of Your Basket link.
  6. User will click on Your Basket link and check the order details and click on Checkout.
  7. User will enter a new Address for Delivery and select it to process further.
  8. User will continue further to Card for Payment and select the card added to make payment.
  9. On the Order Summary page, user will verify all the details like Name, Address, Order details and total amount to be paid and place order.
  10. User will re-check the details on Order confirmation page and check for Thank You message order confirmation and delivery message.

End-to-End Tests for LambdaTest ECommerce Playground Website

Following is the automation test strategy used for writing end-to-end tests:

  1. The User will navigate to the website.
  2. From the Home Page of the screen, user will navigate to the Registration Page and register himself. Verification will be done by asserting the registration successful message.
  3. User will click on the Shop by Category option on the top left and select a category for selecting the product to purchase.
  4. From the Product Page, the user will hover on any product which he likes and select the Add to cart option. Once a product is added to cart, assertions will be performed to check the success message displayed.
  5. On the Checkout page, user will provide the billing address details and also assertion will be made for product name and its respective price.
  6. Once a product is checked out, the user lands on the Order Confirmation page, where product name, price and shipping address will be asserted and after that Order would be marked as confirmed.
  7. Finally, an Order confirmation message would be verified in the tests which marks the end of the test journey.

How to run the Tests?

Running Juice Shop Tests on your local machine:

  • Start Juice-Shop website locally, for doing this we will make use of docker-compose-v3-juiceshop.yml which is available in the root folder of this project.

  • Open terminal/command prompt and navigate to the root folder of the project and run the following command:

    docker-compose -f docker-compose-v3-juiceshop.yml up -d

  • Once the Juice-Shop website is up and running, we are good to run the end-to-end tests using the juice shop website.

  • There are 2 ways to run the tests, those are as follows:

    1. TestNG:

    • Right-Click on the test-suite\testng-juice-shop.xml and select Run ...\test-suite\testng-juice-shop.xml

    2. Maven:

    • To run the tests in headless mode update the value for headless property variable to true

      mvn clean install -Dsuite-xml=test-suite\testng-juice-shop.xml -Dheadless=true

    • To run the tests without headless mode(to see the test running in browser) update the value for headless property variable to false

      mvn clean install -Dsuite-xml=test-suite\testng-juice-shop.xml -Dheadless=false

  • Stopping the Juice Shop website running in local

    docker-compose -f docker-compose-v3-juiceshop.yml down

Running Selenium Grid on local and running tests using Selenium Grid

  • Start the Selenium Grid in local using the docker-compose-v3-seleniumgrid.yml file.

  • Run the following command: docker-compose -f docker-compose-v3-seleniumgrid.yml up -d

    This will start the selenium grid which can be access using http://localhost:4444.

    • To run the tests on Selenium Grid using TestNG:

      Right click on test-suite\testng-seleniumgrid-theinternet.xml and select Run test-suite\testng-seleniumgrid-theinternet.xml

    • To run the tests on Selenium Grid using Maven:

      mvn clean install -Dsuite-xml=test-suite\testng-seleniumgrid-theinternet.xml

  • Stopping the Selenium Grid:

    docker-compose -f docker-compose-v3-seleniumgrid.yml down

Running all the tests in one go:

  • Start the Juice -Shop website using following command:

    docker-compose -f docker-compose-v3-juiceshop.yml up -d

  • Start Selenium Grid using following command:

    docker-compose -f docker-compose-v3-seleniumgrid.yml up -d

  • Run the tests using TestNG:

    Right click on test-suite\testng.xml and select Run test-suite\testng.xml

  • Run the tests using Maven in headless mode:

    mvn clean install -Dheadless=true

  • Stopping the Juice-Shop website and Selenium Grid:

    docker-compose -f docker-compose-v3-juiceshop.yml down --remove-orphan

Running LambdaTest ECommerce Playground Tests on your local machine:

  • There are 2 ways to run the tests, those are as follows:

    1. TestNG:

    • Right-Click on the test-suite\testng-lambdatestecommerce.xml and select Run ...\test-suite\testng-lambdatestecommerce.xml

    2. Maven:

    • To run the tests in headless mode update the value for headless property variable to true

      mvn clean install -Dsuite-xml=test-suite\testng-lambdatestecommerce.xml -Dheadless=true

    • To run the tests without headless mode(to see the test running in browser) update the value for headless property variable to false

      mvn clean install -Dsuite-xml=test-suite\testng-lambdatestecommerce.xml -Dheadless=false

❓ Need Assistance?

  • Discuss your queries by writing to me @ [email protected] OR ping me on any of the social media sites using the below link:

💻 Paid Trainings

  • Contact me for Paid trainings related to Test Automation and Software Testing, mail me @ [email protected] or ping me on LinkedIn

💭 Checkout the blogs related to Testing written by me on the following links:

💻 Recommended Proxies

There are cases when proxies may be required to run the tests, this may happen when the software teams are working in isolation at different places. Residential proxies help in keeping the user’s information safe and help in hiding the real location of the user It acts as a middleman between the device and the internet and keep the users safe from being tracked.

NodeMaven provides high quality proxies with industry-first filtering, super sticky sessions and best customer support. Try out NodeMaven now(Use F86 at checkout to get extra 2GB of proxy)

💡 Cloud platform supporter

Big thanks to LambdaTest for their support to the project with their open source license:

lambdatest

selenium4poc's People

Contributors

mfaisalkhatri avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

selenium4poc's Issues

Write end to end tests for juice shop application

Write end to end tests for juice shop application.

  1. Tests would be running on localhost inside the workflow machine
    Clone the juice shop repo and run the website using node js.
  2. Run the e2e tests once the website is up and running inside the workflow machine.

PEBCAK: Ops-er needs more instructions

It seems that I, without any Dev background, need a little bit more documentation on how to actually run the tests in an unattended fashion.

Assume that I fire up the Selenium Grid (confirmed that the UI is available on :4444, with three browsers waiting for instructions). How would I then get the Grid to perform tests against either the locally running JuiceShop, or a remotely hosted on?

If I strip testng.xml down to the Selenium Grid tests, I do see jobs queued on the SGrid UI, but the browsers themselves don't appear to be getting the assignments. Instead, there's a three minute timeout, after which the queued jobs go away again.

Logs from mvn test

[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running TestSuite
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Aug 01, 2022 5:52:46 AM org.openqa.selenium.remote.tracing.opentelemetry.OpenTelemetryTracer createTracer
INFO: Using OpenTelemetry for tracing


[ERROR] Tests run: 19, Failures: 3, Errors: 0, Skipped: 16, Time elapsed: 184.097 s <<< FAILURE! - in TestSuite
[ERROR] io.github.mfaisalkhatri.tests.theinternet.FormAuthenticationTests.setupTest[remote-chrome](0)  Time elapsed: 183.981 s  <<< FAILURE!
org.openqa.selenium.SessionNotCreatedException: 
Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: '4.3.0', revision: 'a4995e2c09*'
System info: host: 'devsecops', ip: '127.0.2.1', os.name: 'Linux', os.arch: 'amd64', os.version: '5.4.0-110-generic', java.version: '17.0.3'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Command: [null, newSession {capabilities=[Capabilities {browserName: chrome, browserVersion: 101}], desiredCapabilities=Capabilities {browserName: chrome, browserVersion: 101}}]
Capabilities {}
	at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:587)
	at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:264)
	at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:179)
	at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:161)
	at io.github.mfaisalkhatri.drivers.DriverManager.createDriver(DriverManager.java:75)
	at io.github.mfaisalkhatri.tests.base.BaseSuiteSetup.setupTest(BaseSuiteSetup.java:18)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at org.testng.internal.invokers.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:139)
	at org.testng.internal.invokers.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:69)
	at org.testng.internal.invokers.ConfigInvoker.invokeConfigurationMethod(ConfigInvoker.java:361)
	at org.testng.internal.invokers.ConfigInvoker.invokeConfigurations(ConfigInvoker.java:296)
	at org.testng.internal.invokers.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:180)
	at org.testng.internal.invokers.TestMethodWorker.run(TestMethodWorker.java:122)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at org.testng.TestRunner.privateRun(TestRunner.java:806)
	at org.testng.TestRunner.run(TestRunner.java:601)
	at org.testng.SuiteRunner.runTest(SuiteRunner.java:433)
	at org.testng.SuiteRunner$SuiteWorker.run(SuiteRunner.java:471)
	at org.testng.internal.thread.ThreadUtil.lambda$execute$0(ThreadUtil.java:58)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.RuntimeException: NettyHttpHandler request execution error
	at org.openqa.selenium.remote.http.netty.NettyHttpHandler.makeCall(NettyHttpHandler.java:76)
	at org.openqa.selenium.remote.http.AddSeleniumUserAgent.lambda$apply$0(AddSeleniumUserAgent.java:42)
	at org.openqa.selenium.remote.http.Filter.lambda$andFinally$1(Filter.java:56)
	at org.openqa.selenium.remote.http.netty.NettyHttpHandler.execute(NettyHttpHandler.java:49)
	at org.openqa.selenium.remote.http.AddSeleniumUserAgent.lambda$apply$0(AddSeleniumUserAgent.java:42)
	at org.openqa.selenium.remote.http.Filter.lambda$andFinally$1(Filter.java:56)
	at org.openqa.selenium.remote.http.netty.NettyClient.execute(NettyClient.java:98)
	at org.openqa.selenium.remote.tracing.TracedHttpClient.execute(TracedHttpClient.java:55)
	at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:120)
	at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:102)
	at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:67)
	at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:156)
	at org.openqa.selenium.remote.TracedCommandExecutor.execute(TracedCommandExecutor.java:51)
	at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:569)
	... 25 more
Caused by: java.util.concurrent.ExecutionException: java.util.concurrent.TimeoutException: Request timeout to selenium-hub/127.0.0.1:4444 after 180000 ms
	at java.base/java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:396)
	at java.base/java.util.concurrent.CompletableFuture.get(CompletableFuture.java:2096)
	at org.asynchttpclient.netty.NettyResponseFuture.get(NettyResponseFuture.java:206)
	at org.openqa.selenium.remote.http.netty.NettyHttpHandler.makeCall(NettyHttpHandler.java:59)
	... 38 more
Caused by: java.util.concurrent.TimeoutException: Request timeout to selenium-hub/127.0.0.1:4444 after 180000 ms
	at org.asynchttpclient.netty.timeout.TimeoutTimerTask.expire(TimeoutTimerTask.java:43)
	at org.asynchttpclient.netty.timeout.RequestTimeoutTimerTask.run(RequestTimeoutTimerTask.java:50)
	at io.netty.util.HashedWheelTimer$HashedWheelTimeout.run(HashedWheelTimer.java:715)
	at io.netty.util.concurrent.ImmediateExecutor.execute(ImmediateExecutor.java:34)
	at io.netty.util.HashedWheelTimer$HashedWheelTimeout.expire(HashedWheelTimer.java:703)
	at io.netty.util.HashedWheelTimer$HashedWheelBucket.expireTimeouts(HashedWheelTimer.java:790)
	at io.netty.util.HashedWheelTimer$Worker.run(HashedWheelTimer.java:503)
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
	... 1 more

Logs from selenium-hub, after three minutes

selenium-hub    | 05:57:48.503 WARN [SeleniumSpanExporter$1.lambda$export$0] - {"traceId": "2d117effc641c9831e481049220d5e01","eventTime": 1659333468502501009,"eventName": "HTTP request execution complete","attributes": {"http.flavor": 1,"http.handler_class": "org.openqa.selenium.grid.sessionqueue.local.LocalNewSessionQueue","http.host": "selenium-hub:4444","http.method": "POST","http.request_content_length": "223","http.scheme": "HTTP","http.status_code": 500,"http.target": "\u002fsession","http.user_agent": "selenium\u002f4.3.0 (java unix)"}}
selenium-hub    | 
selenium-hub    | 05:57:48.511 WARN [SeleniumSpanExporter$1.lambda$export$0] - {"traceId": "611ee885f3e4c4e5d737154faf598a1b","eventTime": 1659333468509915752,"eventName": "HTTP request execution complete","attributes": {"http.flavor": 1,"http.handler_class": "org.openqa.selenium.grid.sessionqueue.local.LocalNewSessionQueue","http.host": "selenium-hub:4444","http.method": "POST","http.request_content_length": "223","http.scheme": "HTTP","http.status_code": 500,"http.target": "\u002fsession","http.user_agent": "selenium\u002f4.3.0 (java unix)"}}
selenium-hub    | 
selenium-hub    | 05:57:48.497 WARN [SeleniumSpanExporter$1.lambda$export$0] - {"traceId": "62ac86eb1e36b5b3f68cd7458f94281a","eventTime": 1659333468496574636,"eventName": "HTTP request execution complete","attributes": {"http.flavor": 1,"http.handler_class": "org.openqa.selenium.grid.sessionqueue.local.LocalNewSessionQueue","http.host": "selenium-hub:4444","http.method": "POST","http.request_content_length": "223","http.scheme": "HTTP","http.status_code": 500,"http.target": "\u002fsession","http.user_agent": "selenium\u002f4.3.0 (java unix)"}}

Setup:

  • Vagrant box, for Ubuntu 20.04
  • Docker and Docker-compose, also via Ubuntu repo
  • OpenJDK 17, via Ubuntu repo
  • Maven 3.8.6, via Apache.org

Original message: Removed. I was severely misunderstanding things.

Refactor Tests

Refactor the tests and remove duplicate lines of code.

Update Readme

Add Github Workflow Badge, Open source badge, codeql badge, update readme to include example code.

Add Test Retry using TestnNG

Since some of the tests are failing due to inconsistency and jobs needs to be triggered manually to rerun, it is good to have the retry mechanisms to retry tests for 3 times before marking them as failed.

Refactor DriverManager and Website Pages class

  • Move the DriverSetup Class to src\main and refactor it as DriverManager
  • Move all the page object classes to new page package in src\tests
  • Add BaseTest class and use it in all tests.

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.