-
Notifications
You must be signed in to change notification settings - Fork 32
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
Updated with the Android config #3
Merged
Merged
Changes from 3 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
81eb1bb
Updated with the Android config
somebodysmokein c4e9fba
Updated with BStack url
somebodysmokein 956de18
Updated with right android version
somebodysmokein 4b41d8e
Changes required for running on mobile devices
somebodysmokein 4b185e8
update gitignore
somebodysmokein c80cd75
Merge pull request #1 from somebodysmokein/fixture-consolidation
somebodysmokein 859738e
local log file ignore
somebodysmokein 408b8cc
Removed additional config file
somebodysmokein 6e68c6f
Updated with the latest playwright version
somebodysmokein 3c60496
updated Webkit on Ventura
somebodysmokein 11e9dc6
fixed the REST api response issue
somebodysmokein ff458f0
updated with the new mobile pattern
somebodysmokein e3bfb3f
Merge branch 'main' into develop
somebodysmokein File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,113 @@ | ||||||
const base = require("@playwright/test"); | ||||||
const cp = require("child_process"); | ||||||
const { _android } = require("playwright"); | ||||||
const clientPlaywrightVersion = cp | ||||||
.execSync("npx playwright --version") | ||||||
.toString() | ||||||
.trim() | ||||||
.split(" ")[1]; | ||||||
const BrowserStackLocal = require("browserstack-local"); | ||||||
const util = require("util"); | ||||||
const { test } = require("./browserstack.config"); | ||||||
|
||||||
// BrowserStack Specific Capabilities. | ||||||
// Set 'browserstack.local:true For Local testing | ||||||
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.
Suggested change
Review this with product |
||||||
const caps = { | ||||||
osVersion: "13.0", | ||||||
deviceName: "Samsung Galaxy S23", // "Samsung Galaxy S22 Ultra", "Google Pixel 7 Pro", "OnePlus 9", etc. | ||||||
browserName: "chrome", | ||||||
realMobile: "true", | ||||||
name: "My android playwright test", | ||||||
build: "playwright-build-1", | ||||||
"browserstack.username": process.env.BROWSERSTACK_USERNAME || "<USERNAME>", | ||||||
"browserstack.accessKey": | ||||||
process.env.BROWSERSTACK_ACCESS_KEY || "<ACCESS_KEY>", | ||||||
}; | ||||||
|
||||||
exports.bsLocal = new BrowserStackLocal.Local(); | ||||||
|
||||||
// replace YOUR_ACCESS_KEY with your key. You can also set an environment variable - "BROWSERSTACK_ACCESS_KEY". | ||||||
exports.BS_LOCAL_ARGS = { | ||||||
key: process.env.BROWSERSTACK_ACCESS_KEY || "ACCESSKEY", | ||||||
}; | ||||||
|
||||||
// Patching the capabilities dynamically according to the project name. | ||||||
const patchMobileCaps = (name, title) => { | ||||||
let combination = name.split(/@browserstack/)[0]; | ||||||
let [browerCaps, osCaps] = combination.split(/:/); | ||||||
let [browser, deviceName] = browerCaps.split(/@/); | ||||||
let osCapsSplit = osCaps.split(/ /); | ||||||
let os = osCapsSplit.shift(); | ||||||
let osVersion = osCapsSplit.join(" "); | ||||||
caps.browser = browser ? browser : "chrome"; | ||||||
caps.deviceName = deviceName ? deviceName : "Samsung Galaxy S22 Ultra"; | ||||||
caps.osVersion = osVersion ? osVersion : "12.0"; | ||||||
caps.name = title; | ||||||
caps.realMobile = "true"; | ||||||
}; | ||||||
|
||||||
exports.test = base.test.extend({ | ||||||
page: async ({ baseURL }, use, testInfo) => { | ||||||
if (testInfo.project.name.match(/browserstack/)) { | ||||||
patchMobileCaps( | ||||||
testInfo.project.name, | ||||||
`${testInfo.file} - ${testInfo.title}` | ||||||
); | ||||||
const device = await base._android.connect( | ||||||
`wss://cdp.browserstack.com/playwright?caps=${encodeURIComponent( | ||||||
JSON.stringify(caps) | ||||||
)}` | ||||||
); | ||||||
await device.shell("am force-stop com.android.chrome"); | ||||||
const context = await device.launchBrowser({ | ||||||
baseURL: baseURL, | ||||||
}); | ||||||
const page = await context.newPage(); | ||||||
await use(page); | ||||||
|
||||||
await context.close(); | ||||||
await device.close(); | ||||||
} | ||||||
}, | ||||||
|
||||||
beforeEach: [ | ||||||
async ({ page }, use) => { | ||||||
await page | ||||||
.context() | ||||||
.tracing.start({ screenshots: true, snapshots: true, sources: true }); | ||||||
await use(); | ||||||
}, | ||||||
{ auto: true }, | ||||||
], | ||||||
|
||||||
afterEach: [ | ||||||
async ({ page }, use, testInfo) => { | ||||||
await use(); | ||||||
if (testInfo.status == "failed") { | ||||||
await page | ||||||
.context() | ||||||
.tracing.stop({ path: `${testInfo.outputDir}/trace.zip` }); | ||||||
await page.screenshot({ path: `${testInfo.outputDir}/screenshot.png` }); | ||||||
await testInfo.attach("screenshot", { | ||||||
path: `${testInfo.outputDir}/screenshot.png`, | ||||||
contentType: "image/png", | ||||||
}); | ||||||
await testInfo.attach("trace", { | ||||||
path: `${testInfo.outputDir}/trace.zip`, | ||||||
contentType: "application/zip", | ||||||
}); | ||||||
} | ||||||
}, | ||||||
{ auto: true }, | ||||||
], | ||||||
}); | ||||||
|
||||||
exports.getMobileEndpoint = (name, title) => { | ||||||
patchMobileCaps(name, title); | ||||||
delete caps.os_version; | ||||||
delete caps.os; | ||||||
const cdpUrl = `wss://cdp.browserstack.com/playwright?caps=${encodeURIComponent( | ||||||
JSON.stringify(caps) | ||||||
)}`; | ||||||
return cdpUrl; | ||||||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can remove this
console.log