diff --git a/packages/e2e-tests/src/selectors.ts b/packages/e2e-tests/src/selectors.ts index 620da3e22..94c80a55a 100644 --- a/packages/e2e-tests/src/selectors.ts +++ b/packages/e2e-tests/src/selectors.ts @@ -403,11 +403,15 @@ export class Channel { baseElement: WebElement ): Promise { try { - const filenameComponentElement = await baseElement.findElement(By.xpath(`//*[@class='FileComponentfilename']`)) + const filenameComponentElement = await await this.driver.wait( + baseElement.findElement(By.xpath(`//*[@class='FileComponentfilename']`)), + 45_000 + ) const parsedPath = path.parse(filename) // this is split because we print the message as multiple lines and contains doesn't return true when searching the full filename - const filenameElement = await filenameComponentElement.findElement( - By.xpath(`//h5[contains(text(), "${parsedPath.name}")]`) + const filenameElement = await this.driver.wait( + filenameComponentElement.findElement(By.xpath(`//h5[contains(text(), "${parsedPath.name}")]`)), + 45_000 ) if ((await filenameElement.getText()) === filename) { return filenameElement @@ -426,7 +430,10 @@ export class Channel { baseElement: WebElement ): Promise { try { - const filenameElement = await baseElement.findElement(By.xpath(`//p[text()='${filename}']`)) + const filenameElement = await this.driver.wait( + baseElement.findElement(By.xpath(`//p[text()='${filename}']`)), + 45_000 + ) return filenameElement } catch (e) { if (!e.message.includes('no such element')) { @@ -450,7 +457,7 @@ export class Channel { } get uploadFileInput() { - return this.driver.wait(until.elementLocated(By.xpath('//*[@data-testid="uploadFileInput"]'))) + return this.driver.wait(this.driver.findElement(By.xpath('//*[@data-testid="uploadFileInput"]'))) } async sendMessage(message: string, username: string): Promise { @@ -471,10 +478,27 @@ export class Channel { await uploadFileInput.sendKeys(filePath) const sendMessageInput = await this.messageInput await sendMessageInput.sendKeys(Key.ENTER) - await sleep(10_000) + await sleep(5_000) return this.getMessageIdsByFile(filename, fileType, username) } + async cancelFileDownload(messageIds: MessageIds): Promise { + try { + const messageElement = await this.waitForMessageContentById(messageIds.messageId) + const downloadingElement = await this.driver.wait( + messageElement.findElement(By.xpath(`//p[text()='Downloading...']`)), + 45_000 + ) + await downloadingElement.click() + await sleep(10_000) + await this.driver.wait(messageElement.findElement(By.xpath(`//p[text()='Download file']`)), 45_000) + return true + } catch (e) { + logger.error(`Error occurred while canceling download`, e) + return false + } + } + async getMessageIdsByText(message: string, username: string): Promise { const messageElement = await this.waitForUserMessageByText(username, message) if (!messageElement) { diff --git a/packages/e2e-tests/src/tests/multipleClients.test.ts b/packages/e2e-tests/src/tests/multipleClients.test.ts index 1f4807f53..addbfeb7b 100644 --- a/packages/e2e-tests/src/tests/multipleClients.test.ts +++ b/packages/e2e-tests/src/tests/multipleClients.test.ts @@ -11,8 +11,10 @@ import { Sidebar, } from '../selectors' import { promiseWithRetries, sleep } from '../utils' -import { UserTestData } from '../types' +import { MessageIds, UserTestData } from '../types' import { createLogger } from '../logger' +import * as path from 'path' +import { UploadedFileType } from '../enums' const logger = createLogger('multipleClients') @@ -467,6 +469,53 @@ describe('Multiple Clients', () => { }) }) + describe('Uploading and downloading files', () => { + let largeFileMessageIds: MessageIds | undefined = undefined + + it('Owner uploads an image', async () => { + const filename = 'testImage.gif' + const uploadFilePath = path.resolve('./src/tests/resources/', filename) + await generalChannelOwner.uploadFile(filename, uploadFilePath, UploadedFileType.IMAGE, users.owner.username) + }) + + it('Guest sees uploaded image', async () => { + await sleep(10_000) + const filename = 'testImage.gif' + await generalChannelUser1.getMessageIdsByFile(filename, UploadedFileType.IMAGE, users.owner.username) + }) + + it('Owner uploads a file', async () => { + const filename = 'testFile.pdf' + const uploadFilePath = path.resolve('./src/tests/resources/', filename) + await generalChannelOwner.uploadFile(filename, uploadFilePath, UploadedFileType.FILE, users.owner.username) + }) + + it('Guest sees uploaded file and it downloads', async () => { + const filename = 'testFile.pdf' + await generalChannelUser1.getMessageIdsByFile(filename, UploadedFileType.FILE, users.owner.username) + }) + + it('Owner uploads a large file', async () => { + const filename = 'largeTestFile.bin' + const uploadFilePath = path.resolve('./src/tests/resources/', filename) + await generalChannelOwner.uploadFile(filename, uploadFilePath, UploadedFileType.FILE, users.owner.username) + }) + + it(`Guest sees uploaded large file`, async () => { + const filename = 'largeTestFile.bin' + largeFileMessageIds = await generalChannelUser1.getMessageIdsByFile( + filename, + UploadedFileType.FILE, + users.owner.username + ) + }) + + it(`Guest cancels download of large file`, async () => { + expect(largeFileMessageIds).toBeDefined() + expect(await generalChannelUser1.cancelFileDownload(largeFileMessageIds!)).toBeTruthy() + }) + }) + describe('Guest Closes App', () => { it('Owner closes app', async () => { await users.owner.app.close({ forceSaveState: true }) diff --git a/packages/e2e-tests/src/tests/oneClient.test.ts b/packages/e2e-tests/src/tests/oneClient.test.ts index cc3ff0494..b71a314b1 100644 --- a/packages/e2e-tests/src/tests/oneClient.test.ts +++ b/packages/e2e-tests/src/tests/oneClient.test.ts @@ -210,14 +210,12 @@ describe('One Client', () => { it('Owner uploads an image', async () => { const filename = 'testImage.gif' const uploadFilePath = path.resolve('./src/tests/resources/', filename) - logger.info(`Upload image path`, uploadFilePath) await generalChannel.uploadFile(filename, uploadFilePath, UploadedFileType.IMAGE, ownerUserName) }) it('Owner uploads a non-image file', async () => { const filename = 'testFile.pdf' const uploadFilePath = path.resolve('./src/tests/resources/', filename) - logger.info(`Upload file path`, uploadFilePath) await generalChannel.uploadFile(filename, uploadFilePath, UploadedFileType.FILE, ownerUserName) }) }) diff --git a/packages/e2e-tests/src/tests/resources/largeTestFile.bin b/packages/e2e-tests/src/tests/resources/largeTestFile.bin new file mode 100644 index 000000000..45aecedf2 Binary files /dev/null and b/packages/e2e-tests/src/tests/resources/largeTestFile.bin differ