Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CARDS-59: Add support for running frontend tests using Selenium #1569

Open
wants to merge 8 commits into
base: dev
Choose a base branch
from

Conversation

acrowthe
Copy link
Contributor

@acrowthe acrowthe commented Jul 20, 2023

Add selenium test module. This module can be run using mvn clean install -Pdocker -Dselenium. It runs tests using Docker to launch CARDS and Google Chrome to run the tests. To support this, -Dselenium will add docker to the build in addition to cleaning out any running or old CARDS docker builds.

To run these tests, make sure that you have Google Chrome installed in the default install location for your operating system. The expected location can be found here:
https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver/01fde32d0ed245141e24151f83b7c2db31d596a4#requirements

If you are using WSL, make sure that Google Chrome is installed through WSL, not just through Windows:
https://scottspence.com/posts/use-chrome-in-ubuntu-wsl

The current test is to login and verify that the user's avatar on the top right of the dashboard is correct. To ensure that this test ran, you can check /selenium/target/failsafe-reports. There should be 1 run test and no failures.

If you want to check behaviour if there is a failed test, modify LoginSelenium.java and change assertEquals("A" to some other string.

Framework has been added for supporting other browsers though there are issues with browsers other than chrome:

  • Firefox does is not waiting for user login to complete before checking if the user has logged in
  • Edge is launching Chrome and then complaining that Chrome is not Edge
  • Safari framework is in place but untested

When no browser is provided, testing will default to Chrome

To launch with other browsers, make sure they are installed in the default install location for your operating system then run
mvn clean install -Pdocker -Dselenium -DseleniumDriver=<browser>
where <browser> is one of edge, chrome, firefox or safari

pom.xml Outdated Show resolved Hide resolved
selenium/launch_cards.sh Outdated Show resolved Hide resolved
selenium/launch_cards.sh Outdated Show resolved Hide resolved
selenium/launch_cards.sh Outdated Show resolved Hide resolved
selenium/launch_cards.sh Outdated Show resolved Hide resolved
selenium/pom.xml Outdated Show resolved Hide resolved
selenium/pom.xml Show resolved Hide resolved
public static WebDriver getDriver()
{
WebDriver driver = null;
WebDriverManager.chromedriver().setup();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it would be better to use the Browsers in Docker support available in the io.github.bonigarcia.wdm.WebDriverManager module - https://github.com/bonigarcia/webdrivermanager#browsers-in-docker. Ideally, you would want the Browser In Docker container to be part of the compose-cluster environment and it would access the running CARDS instance at http://cardsinitial:8080 instead of http://localhost:8080. It's just a thought for now, maybe something to do for future work.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like that we hardcode the browser here. I would like to be able to run the tests on any browser, to catch inconsistencies.

selenium/pom.xml Outdated Show resolved Hide resolved
selenium/pom.xml Outdated Show resolved Hide resolved
acrowthe and others added 3 commits July 27, 2023 06:51
Add selenium test module. This module can be run using `mvn clean
install -Dselenium`. It runs tests using Docker to launch CARDS and
Google Chrome to run the tests. To support this, `-Dselenium` will
add docker to the build in addition to cleaning out any running or
old CARDS docker builds.

To run these tests, make sure that you have Google Chrome installed
in the default install location for your operating system. The
expected location can be found here:
https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver/01fde32d0ed245141e24151f83b7c2db31d596a4#requirements

If you are using WSL, make sure that Google Chrome is installed
through WSL, not just through Windows:
https://scottspence.com/posts/use-chrome-in-ubuntu-wsl

The current test is to login and verify that the user's avatar on
the top right of the dashboard is correct. To ensure that this test
ran, you can check `/selenium/target/failsafe-reports`. There should
be 1 run test and no failures.

If you want to check behaviour if there is a failed test, modify
`LoginSelenium.java` and change `assertEquals("A"` to some other
string.
Address review comments
- Improve compatibility across different build environments
- Improve maven configuration
@acrowthe
Copy link
Contributor Author

Fixes look good: Thanks @sdumitriu

Add framework for testing in other browsers
@acrowthe
Copy link
Contributor Author

acrowthe commented Aug 9, 2023

Added framework for testing in other browsers with known issues that will be addressed in separate PRs

Jira task created

Copy link
Member

@IntegralProgrammer IntegralProgrammer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks pretty good although I have a few small suggestions/ideas that I have discussed in this review.

@sashaandjic sashaandjic added the testing... Testing in progress label Aug 11, 2023
@sashaandjic
Copy link
Contributor

image

image

@sashaandjic
Copy link
Contributor

sashaandjic commented Aug 15, 2023

On a second attempt it worked
image

- Move login to custom TestRule for easy re-use in different tests
- Rename SeleniumUtils to improve naming scheme for future project specific selenium
  util files
@sashaandjic
Copy link
Contributor

ready for re-test?

@acrowthe
Copy link
Contributor Author

Yes, it's ready for retest

@marta- marta- added the on hold To be reviewed at a later time, awaiting other fixes, decisions, etc. label Sep 26, 2023
@sashaandjic sashaandjic removed the testing... Testing in progress label Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
low risk on hold To be reviewed at a later time, awaiting other fixes, decisions, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants