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

Add integration tests for starting phantom and chromedriver #512

Conversation

aaronrenner
Copy link
Member

This adds integration tests for around starting wallaby and the underlying phantomjs and chromedriver processes. These tests establish a pattern of how to test a webdriver server's startup and will make it easier to work on the following issues:

I chose to test this via integration tests because I'm thinking this style of test will give us the most flexibility to address #423 while having test coverage to ensure wallaby as a whole continues to function as users expect.

@aaronrenner aaronrenner force-pushed the ar-script-driven-integration-tests branch from 4d3147a to 34038a5 Compare February 11, 2020 19:57
mhanberg
mhanberg previously approved these changes Feb 21, 2020
test/support/chrome/chrome_test_script.ex Outdated Show resolved Hide resolved
test/support/phantom/phantom_test_script.ex Outdated Show resolved Hide resolved
ensure_setting_is_reset(:wallaby, :chromedriver)
Application.put_env(:wallaby, :chromedriver, path: test_script_path)

assert :ok = Application.start(:wallaby)
Copy link
Member

Choose a reason for hiding this comment

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

Are all these lines necessary since the stop_wallaby function flunks if the application won't start?

Copy link
Member Author

Choose a reason for hiding this comment

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

The flunk in stop_wallaby is in an on_exit callback, so the flunk will occur only if it can't restart wallaby after the test is done.

Since wallaby reads its config and starts worker pools on Application startup, in order to change settings for the driver we need to:

  1. Stop wallaby
  2. Adjust the environment for the new script path/settings
  3. Start wallaby back up

In the future, I think it would be really nice to allow more overrides in Wallaby.start_session (like which driver to use, whether or not to start a chromedriver instance or use a remote instance, etc), instead of relying so heavily on the application config that we're having to start and stop the full application during tests and can only use one driver (phantom, selenium, chromedriver) at a time. That's definitely outside the scope of this PR and should be discussed more, but I figured I just should share what I've been thinking for the longer term.

Copy link
Member

Choose a reason for hiding this comment

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

Is Wallaby not already started at the beginning of the test since it's restarted in the on_exit callback? Or does calling Application.start/1 restart the application? (I was thinking it nooped if it was already started)

Copy link
Member Author

Choose a reason for hiding this comment

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

I stopped wallaby before the test is run on line 14 in the setup block:

setup [:stop_wallaby, :create_test_workspace]

I figured that way I can start the tests by configuring wallaby before I start it back up (and so I don't forget to stop it and have my config changes not matter). Now that I look at it, I do see that setup step could be easy to miss, though. Is there another way I should write this that would be more clear?

Copy link
Member

Choose a reason for hiding this comment

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

🤦‍♂

I realized that the on_exit through me off, in reality, the steps are

  1. stop wallaby
  2. reset env stuff
  3. start wallaby
  4. test
  5. stop wallaby
  6. start wallaby

I might split it up into two functions. One stops wallaby stop_wallaby and the other defines the on_exit and is named restart_on_exit! or something like that.

Copy link
Member Author

Choose a reason for hiding this comment

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

I split it into 2 functions in the setup block: stop_wallaby and restart_wallaby_on_exit!. Do you prefer Application.stop(:wallaby) as the first line in each test instead of having a function that's called during setup?

@aaronrenner aaronrenner force-pushed the ar-script-driven-integration-tests branch from 24d0098 to 648c359 Compare February 24, 2020 17:37
on_exit(fn ->
Application.delete_env(:wallaby, :chromedriver)
end)
ensure_setting_is_reset(:wallaby, :chromedriver)
Copy link
Member Author

Choose a reason for hiding this comment

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

@mhanberg This change isn't actually required for this PR (since #512 fixed the chromedriver failures we seeing), but it seems to be more correct to just reset the environment instead of completely deleting any existing settings. Do you mind if I leave this in here?

Copy link
Member

Choose a reason for hiding this comment

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

Fine by me

@aaronrenner aaronrenner requested a review from mhanberg February 26, 2020 13:17
@aaronrenner aaronrenner merged commit 5b83d52 into elixir-wallaby:master Feb 26, 2020
@aaronrenner aaronrenner deleted the ar-script-driven-integration-tests branch February 26, 2020 14:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants