-
Notifications
You must be signed in to change notification settings - Fork 59
feat(webdriver-utils): env-var overrides for staging/percy-dev testing #2274
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,7 +27,8 @@ export default class PlaywrightDriver { | |
| command.script = `/* percy_automate_script */ \n ${command.script}`; | ||
| } | ||
| const options = this.requestPostOptions(command); | ||
| const baseUrl = `https://cdp.browserstack.com/wd/hub/session/${this.sessionId}/execute`; | ||
| const cdpDomain = process.env.PERCY_CDP_DOMAIN || 'cdp.browserstack.com'; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Low] Domain env vars are interpolated without validation
Suggestion: Optional — validate against a hostname pattern if these ever become user-facing. Reviewer: stack:code-reviewer |
||
| const baseUrl = `https://${cdpDomain}/wd/hub/session/${this.sessionId}/execute`; | ||
| const response = JSON.parse((await request(baseUrl, options)).body); | ||
| return response; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -106,9 +106,10 @@ export default class AutomateProvider extends GenericProvider { | |
|
|
||
| async setDebugUrl() { | ||
| if (!this.driver) throw new Error('Driver is null, please initialize driver with createDriver().'); | ||
| const automateDomain = process.env.PERCY_AUTOMATE_DOMAIN || 'automate.browserstack.com'; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Medium] Cache key omits the domain — stale debug URL on repeated
Suggestion: Drop the Reviewer: stack:code-reviewer |
||
| this.debugUrl = await Cache.withCache(Cache.bstackSessionDetails, this.driver.sessionId, | ||
| async () => { | ||
| return `https://automate.browserstack.com/builds/${this.automateResults.buildHash}/sessions/${this.automateResults.sessionHash}`; | ||
| return `https://${automateDomain}/builds/${this.automateResults.buildHash}/sessions/${this.automateResults.sessionHash}`; | ||
| }); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -96,6 +96,9 @@ export default class GenericProvider { | |
|
|
||
| async browserstackExecutor(action, args) { | ||
| if (!this.driver) throw new Error('Driver is null, please initialize driver with createDriver().'); | ||
| if (action === 'percyScreenshot' && process.env.PERCY_ENABLE_DEV === 'true') { | ||
| args = { ...args, projectId: 'percy-dev' }; | ||
|
bhokaremoin marked this conversation as resolved.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Low] Spread on possibly-absent If Suggestion: Reviewer: stack:code-reviewer |
||
| } | ||
| let options = args ? { action, arguments: args } : { action }; | ||
| let res = await this.driver.executeScript({ script: `browserstack_executor: ${JSON.stringify(options)}`, args: [] }); | ||
| return res; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,6 +50,19 @@ describe('AutomateProvider', () => { | |
| expect(automateProvider.debugUrl).toEqual('https://automate.browserstack.com/builds/12e3/sessions/abc1d'); | ||
| }); | ||
|
|
||
| it('uses PERCY_AUTOMATE_DOMAIN when set', async () => { | ||
| Cache.reset(); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Low] Unexplained This reset is required because the preceding Suggestion: Add a one-line comment explaining why the reset is needed. Reviewer: stack:code-reviewer |
||
| process.env.PERCY_AUTOMATE_DOMAIN = 'automate-k8s-mobile.bsstag.com'; | ||
| try { | ||
| let automateProvider = new AutomateProvider(args); | ||
| await automateProvider.createDriver(); | ||
| await automateProvider.screenshot('abc', { }); | ||
| expect(automateProvider.debugUrl).toEqual('https://automate-k8s-mobile.bsstag.com/builds/12e3/sessions/abc1d'); | ||
| } finally { | ||
| delete process.env.PERCY_AUTOMATE_DOMAIN; | ||
| } | ||
| }); | ||
|
|
||
| it('throws error if driver is not initialized', async () => { | ||
| let automateProvider = new AutomateProvider(args); | ||
| await expectAsync(automateProvider.setDebugUrl()) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.