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

feat: Passing --browser flag alone will launch after test selection #28538

Open
wants to merge 62 commits into
base: develop
Choose a base branch
from

Conversation

raygdev
Copy link

@raygdev raygdev commented Dec 16, 2023

Additional details

  • This was a feature request made in the issue listed above
  • When the --browser flag is passed alone, after selecting the testing type, the selected browser will automatically launch.
  • I used the localSettings field in the OpenBrowser query to check if the browser was set in the cli. That query was passed as a prop to OpenBrowserList and used on mount and emits the already defined launch function if the browser was set.

Steps to test

In development yarn cypress:open --browser <browser-name-or-path>. Select your testing type in the GUI. After testing type selection, the browser specified will automatically launch. Clicking switch testing type will navigate back to select another testing type. When a new type is selected the user will have to select the browser from the UI. If an invalid browser name or path is passed, the cached browser will not launch and the error will show as intended. The user will either have to select from the list of available browsers or relaunch from the cli.

How has the user experience changed?

Previously, when a user only passed the --browser flag, they would still be prompted to select the browser and click the Start testing in <browser-name> button to open the browser. The only other option was to pass a testing type flag and browser flag together to automatically launch.

PR Tasks

@CLAassistant
Copy link

CLAassistant commented Dec 16, 2023

CLA assistant check
All committers have signed the CLA.

@cypress-app-bot
Copy link
Collaborator

@raygdev raygdev changed the title feat: passing --browser flag alone will launch after test selection feat: Passing --browser flag alone will launch after test selection in the GUI, the browser will automatically launch. Dec 16, 2023
@raygdev raygdev changed the title feat: Passing --browser flag alone will launch after test selection in the GUI, the browser will automatically launch. Passing --browser flag alone will launch after test selection in the GUI, the browser will automatically launch. Dec 16, 2023
@raygdev raygdev changed the title Passing --browser flag alone will launch after test selection in the GUI, the browser will automatically launch. feat: Passing --browser flag alone will launch after test selection in the GUI, the browser will automatically launch. Addresses [#22003](https://github.com/cypress-io/cypress/issues/22003). Dec 16, 2023
@raygdev raygdev changed the title feat: Passing --browser flag alone will launch after test selection in the GUI, the browser will automatically launch. Addresses [#22003](https://github.com/cypress-io/cypress/issues/22003). feat: Passing --browser flag alone will launch after test selection Dec 16, 2023
cli/CHANGELOG.md Outdated Show resolved Hide resolved
@raygdev
Copy link
Author

raygdev commented Dec 18, 2023

Currently the way the code is, when running the command yarn cypress:open --browser chrome it launches as intended. Let's say we provide a browser that isn't on the list like yarn cypress:open --browser something. The warning shows as intended, however... the last cached browser still launches even though a warning, about the browser passed not being found, is displayed. I'm wondering what the outcome should be for this. Should we still allow launch of the cached browser for convenience, and let the user dismiss the warning? Or do we want to negate launching altogether if an incorrect or unsupported browser is passed?

@marktnoonan
Copy link
Contributor

Currently the way the code is, when running the command yarn cypress:open --browser chrome it launches as intended. Let's say we provide a browser that isn't on the list like yarn cypress:open --browser something. The warning shows as intended, however... the last cached browser still launches even though a warning, about the browser passed not being found, is displayed. I'm wondering what the outcome should be for this. Should we still allow launch of the cached browser for convenience, and let the user dismiss the warning? Or do we want to negate launching altogether if an incorrect or unsupported browser is passed?

My suggestion is that if we couldn't find the browser that was passed, we should not open any browser and let you see the warning, then you'd have to either relaunch passing in a different browser name, or pick the browser you want from the list.

@raygdev
Copy link
Author

raygdev commented Apr 8, 2024

I'm going to open this PR as ready for review so that I can get some feedback on the current code I have.

  • I set up a global launch count in ProjectActions to keep track of launchProject calls.
  • I exposed the launchCount with a setter to help with testing.
  • I used gql-LocalSettings to add a globalLaunchCount field and isValidBrowser field
  • isValidBrowser uses what I believe to be a utility function to find a valid browser by name or path and throws otherwise
  • I created a new query in OpenBrowser.vue that makes a network request (the values were cached which made globalLaunchCount always evaluate to 0 even though it was updating on the server) so that the launch function wouldn't be called again when navigating back and selecting a new testing type.
  • I used the OpenBrowser_LocalSettingsDocument generated from the additional query to keep the request size as small as possible while leaving the other values cached.
  • Created a launchIfBrowserSetInCli function that uses the three fields needed and uses the already defined launch function if the conditions are met and is called on mount of the OpenBrowser component.

Since there is already a function that launches with the same values (testingType, wasBrowserSetInCli) I had to create a launch count to keep track of the calls to ensure that both functions wouldn't be called since they rely on the same values. I honestly feel like this is a bit hacky, so I will happily take some advice if changes need to be made. This is my first contribution to a large codebase, so I want to be sure that this is going in the right direction before I code myself into a corner. I will put this back in draft (if need be) after any feedback provided.

@raygdev raygdev marked this pull request as ready for review April 8, 2024 01:22
@cacieprins cacieprins added the stage: needs review The PR code is done & tested, needs review label Apr 8, 2024
@jennifer-shehane
Copy link
Member

@raygdev I'll see if the team has some time to review this next iteration.

@raygdev
Copy link
Author

raygdev commented Apr 17, 2024

@jennifer-shehane sounds good! Thank you!

@jennifer-shehane jennifer-shehane requested review from ryanthemanuel and mschile and removed request for jennifer-shehane April 19, 2024 15:27
@marktnoonan
Copy link
Contributor

@raygdev I hit that "update branch" button for you, it seems like there's now a little bit of cleanup needed in the changelog just FYI

@raygdev
Copy link
Author

raygdev commented May 4, 2024

@marktnoonan Done! Thanks Mark!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stage: needs review The PR code is done & tested, needs review
Projects
None yet
9 participants