Skip to content

Commit

Permalink
AB#866 Fix attachment download test when running on BrowserStack
Browse files Browse the repository at this point in the history
  • Loading branch information
gjvoosten committed Feb 21, 2024
1 parent 6c5a3ab commit f219a33
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions client/tests/webdriver/baseSpecs/showAttachment.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,35 @@ const ATTACHMENT_MIMETYPE = "image/png"
const ATTACHMENT_USED_IN = "A test report from Arthur"
const ATTACHMENT_SIZE = 12316

async function checkDownloadedFile(attachmentName, attachmentSize) {
const testEnv =
(process.env.GIT_TAG_NAME && "remote") || process.env.TEST_ENV || "local"
if (testEnv === "local") {
// Local
const stats = fs.statSync(attachmentName)
// eslint-disable-next-line no-unused-expressions
expect(stats.isFile()).to.be.true
expect(stats.size).to.equal(attachmentSize)
// clean up
fs.rmSync(attachmentName)
} else {
// On BrowserStack
// Don't specify the name, just assume it was the last downloaded file (actual filename may be different!)
const fileExists = await browser.executeScript(
'browserstack_executor: {"action": "fileExists"}',
[]
)
// eslint-disable-next-line no-unused-expressions
expect(fileExists).to.be.true
const fileProperties = await browser.executeScript(
'browserstack_executor: {"action": "getFileProperties"}',
[]
)
expect(fileProperties.size).to.equal(attachmentSize)
// Can't delete the file here
}
}

describe("Show attachment page", () => {
beforeEach("Open the show attachment page", async() => {
await ShowAttachment.open(ATTACHMENT_UUID)
Expand All @@ -28,12 +57,7 @@ describe("Show attachment page", () => {
await downloadButton.click()
await browser.pause(1000)
// file should be downloaded by now
const stats = fs.statSync(ATTACHMENT_NAME)
// eslint-disable-next-line no-unused-expressions
expect(stats.isFile()).to.be.true
expect(stats.size).to.equal(ATTACHMENT_SIZE)
// clean up
fs.rmSync(ATTACHMENT_NAME)
await checkDownloadedFile(ATTACHMENT_NAME, ATTACHMENT_SIZE)
})
it("We should see image of attachment", async() => {
await (await ShowAttachment.getImage()).waitForExist()
Expand Down

0 comments on commit f219a33

Please sign in to comment.