|
| 1 | + |
| 2 | +const { test, url } = require('../fixture.js'); |
| 3 | +const { expect } = require('@playwright/test'); |
| 4 | +const { FileActions } = require('./fileactions.js'); |
| 5 | +const fs = require('fs'); |
| 6 | +require('dotenv').config(); |
| 7 | +const os = require('os'); |
| 8 | +const mammoth = require('mammoth'); |
| 9 | +// const PDFParse = require('pdf-parse'); |
| 10 | +const PDFParser = require('pdf2json'); |
| 11 | +// import PDFParser from "pdf2json"; |
| 12 | + |
| 13 | +// const local = !!process.env.PW_URL.includes('localhost'); |
| 14 | + |
| 15 | +let mobile; |
| 16 | +let browserName; |
| 17 | +let browserstackMobile; |
| 18 | +let fileActions; |
| 19 | +let fileActions1 |
| 20 | + |
| 21 | +test.beforeEach(async ({ page }, testInfo) => { |
| 22 | + test.setTimeout(90000); |
| 23 | + |
| 24 | + mobile = testInfo.project.use.mobile; |
| 25 | + browserName = testInfo.project.name.split(/@/)[0]; |
| 26 | + browserstackMobile = testInfo.project.name.match(/browserstack-mobile/); |
| 27 | + fileActions = new FileActions(page); |
| 28 | + await fileActions.loadFileType("doc") |
| 29 | +}); |
| 30 | + |
| 31 | +test('anon - doc - input text', async ({ page, context }) => { |
| 32 | + try { |
| 33 | + |
| 34 | + await fileActions.docEditor.click({force: true}); |
| 35 | + await fileActions.docEditor.dispatchEvent('focus'); |
| 36 | + await fileActions.docEditor.dispatchEvent('select'); |
| 37 | + |
| 38 | + await fileActions.typeTestTextCode(mobile, 'test text'); |
| 39 | + await page.keyboard.press('Control+A'); |
| 40 | + await page.keyboard.press('Control+C'); |
| 41 | + |
| 42 | + const clipboardText = await page.evaluate(() => navigator.clipboard.readText()); |
| 43 | + expect(clipboardText.trim()).toContain('test text'); |
| 44 | + await fileActions.toSuccess( 'Can input text into Document'); |
| 45 | + } catch (e) { |
| 46 | + await fileActions.toFailure(e,'Can\'t input text into Document'); |
| 47 | + } |
| 48 | +}); |
| 49 | + |
| 50 | +test('anon - doc - make a copy', async ({ page, context }) => { |
| 51 | + try { |
| 52 | + |
| 53 | + await fileActions.docEditor.click({force: true}); |
| 54 | + await fileActions.docEditor.dispatchEvent('focus'); |
| 55 | + await fileActions.docEditor.dispatchEvent('select'); |
| 56 | + |
| 57 | + await fileActions.typeTestTextCode(mobile, 'test text'); |
| 58 | + await page.keyboard.press('Control+A'); |
| 59 | + await page.keyboard.press('Control+C'); |
| 60 | + |
| 61 | + const clipboardText = await page.evaluate(() => navigator.clipboard.readText()); |
| 62 | + expect(clipboardText.trim()).toContain('test text'); |
| 63 | + |
| 64 | + await fileActions.filemenuClick(mobile); |
| 65 | + const [page1] = await Promise.all([ |
| 66 | + page.waitForEvent('popup'), |
| 67 | + await fileActions.filecopy.click() |
| 68 | + ]); |
| 69 | + |
| 70 | + await expect(page1).toHaveURL(new RegExp(`^${url}/doc`), { timeout: 100000 }); |
| 71 | + fileActions1 = new FileActions(page1); |
| 72 | + |
| 73 | + await fileActions1.fileSaved.waitFor() |
| 74 | + await fileActions1.docEditor.click({force: true}); |
| 75 | + |
| 76 | + await page1.keyboard.press('Control+A'); |
| 77 | + await page1.keyboard.press('Control+C'); |
| 78 | + |
| 79 | + const clipboardText2 = await page.evaluate(() => navigator.clipboard.readText()); |
| 80 | + expect(clipboardText2.trim()).toContain('test text'); |
| 81 | + |
| 82 | + await fileActions.toSuccess( 'Can make a copy of Document'); |
| 83 | + } catch (e) { |
| 84 | + await fileActions.toFailure(e,'Can\'t make a copy of Document'); |
| 85 | + } |
| 86 | +}); |
| 87 | + |
| 88 | + |
| 89 | +test('anon - doc - insert image', async ({ page, context }) => { |
| 90 | + try { |
| 91 | + |
| 92 | + await fileActions.docEditor.click({force: true}); |
| 93 | + |
| 94 | + |
| 95 | + await fileActions.insertTab.click({force: true}); |
| 96 | + await fileActions.insertImg.click(); |
| 97 | + await fileActions.imgFromFile.click(); |
| 98 | + |
| 99 | + |
| 100 | + |
| 101 | + |
| 102 | + await fileActions.toSuccess( 'Can input text into Document'); |
| 103 | + } catch (e) { |
| 104 | + await fileActions.toFailure(e,'Can\'t input text into Document'); |
| 105 | + } |
| 106 | +}); |
| 107 | + |
| 108 | +test('anon - doc - history (previous version)', async ({ page, context }) => { |
| 109 | + try { |
| 110 | + |
| 111 | + await fileActions.docEditor.click({force: true}); |
| 112 | + await fileActions.docEditor.dispatchEvent('focus'); |
| 113 | + await fileActions.docEditor.dispatchEvent('select'); |
| 114 | + |
| 115 | + await fileActions.typeTestTextCode(mobile, 'test text'); |
| 116 | + |
| 117 | + await fileActions.history(mobile); |
| 118 | + await fileActions.historyFastPrev.click() |
| 119 | + await fileActions.fileSaved.waitFor() |
| 120 | + await page.locator('#sbox-iframe').contentFrame().getByRole('paragraph').filter({ hasText: 'syncing changes, please wait' }).waitFor({state: 'hidden'}) |
| 121 | + |
| 122 | + |
| 123 | + await fileActions.docEditor.click({force: true}); |
| 124 | + |
| 125 | + await page.keyboard.press('Control+A'); |
| 126 | + await page.keyboard.press('Control+C'); |
| 127 | + |
| 128 | + const clipboardText = await page.evaluate(() => navigator.clipboard.readText()); |
| 129 | + |
| 130 | + expect(clipboardText.trim()).toEqual(''); |
| 131 | + |
| 132 | + await fileActions.toSuccess( 'Can input text into Document'); |
| 133 | + |
| 134 | + } catch (e) { |
| 135 | + await fileActions.toFailure(e,'Can\'t input text into Document'); |
| 136 | + } |
| 137 | +}); |
| 138 | + |
| 139 | +test('anon - doc - export (doc)', async ({ page, context }) => { |
| 140 | + try { |
| 141 | + |
| 142 | + await fileActions.docEditor.click({force: true}); |
| 143 | + await fileActions.docEditor.dispatchEvent('focus'); |
| 144 | + await fileActions.docEditor.dispatchEvent('select'); |
| 145 | + |
| 146 | + await fileActions.typeTestTextCode(mobile, 'test text'); |
| 147 | + |
| 148 | + await fileActions.export(mobile); |
| 149 | + await fileActions.textbox.fill('test doc'); |
| 150 | + |
| 151 | + const [download] = await Promise.all([ |
| 152 | + page.waitForEvent('download'), |
| 153 | + await fileActions.okButton.click() |
| 154 | + ]); |
| 155 | + |
| 156 | + await download.saveAs('/tmp/test doc'); |
| 157 | + |
| 158 | + mammoth.extractRawText({path: "/tmp/test doc"}) |
| 159 | + .then(result => { |
| 160 | + expect(result.value.trim()).toEqual('test text'); |
| 161 | + }) |
| 162 | + await fileActions.toSuccess( 'Can export Document as .doc'); |
| 163 | + |
| 164 | + } catch (e) { |
| 165 | + await fileActions.toFailure(e,'Can\'t input text into Document'); |
| 166 | + } |
| 167 | +}); |
| 168 | + |
| 169 | +test('anon - doc - export (pdf)', async ({ page, context }) => { |
| 170 | + try { |
| 171 | + |
| 172 | + |
| 173 | + await fileActions.docEditor.click({force: true}); |
| 174 | + await fileActions.docEditor.dispatchEvent('focus'); |
| 175 | + await fileActions.docEditor.dispatchEvent('select'); |
| 176 | + |
| 177 | + await fileActions.typeTestTextCode(mobile, 'test text'); |
| 178 | + |
| 179 | + await fileActions.export(mobile); |
| 180 | + await fileActions.textbox.fill('test doc'); |
| 181 | + await page.locator('#sbox-iframe').contentFrame().getByRole('button', { name: '.docx' }).click(); |
| 182 | + await page.locator('#sbox-iframe').contentFrame().getByText('.pdf').click(); |
| 183 | + |
| 184 | + const [download] = await Promise.all([ |
| 185 | + page.waitForEvent('download'), |
| 186 | + await fileActions.okButton.click() |
| 187 | + ]); |
| 188 | + |
| 189 | + await download.saveAs('/tmp/test doc'); |
| 190 | + const { PDFParse } = require('pdf-parse'); |
| 191 | + |
| 192 | + const buffer = fs.readFileSync('/tmp/test doc'); |
| 193 | + const parser = new PDFParse({ data: buffer }); |
| 194 | + |
| 195 | + const result = await parser.getText(); |
| 196 | + await parser.destroy(); |
| 197 | + expect(result.text).toEqual('test text\n\n-- 1 of 1 --\n\n') |
| 198 | + await fileActions.toSuccess( 'Can export Document as .pdf'); |
| 199 | + |
| 200 | + } catch (e) { |
| 201 | + await fileActions.toFailure(e,'Can\'t export Document as .pdf'); |
| 202 | + } |
| 203 | +}); |
| 204 | + |
| 205 | +test('anon - doc - history (previous version 1)', async ({ page, context }) => { |
| 206 | + try { |
| 207 | + |
| 208 | + await fileActions.docEditor.click({force: true}); |
| 209 | + await fileActions.docEditor.dispatchEvent('focus'); |
| 210 | + await fileActions.docEditor.dispatchEvent('select'); |
| 211 | + |
| 212 | + await fileActions.typeTestTextCode(mobile, 'test \n text'); |
| 213 | + |
| 214 | + await fileActions.history(mobile); |
| 215 | + await fileActions.historyFastPrev.click() |
| 216 | + await fileActions.fileSaved.waitFor() |
| 217 | + await page.locator('#sbox-iframe').contentFrame().getByRole('paragraph').filter({ hasText: 'syncing changes, please wait' }).waitFor({state: 'hidden'}) |
| 218 | + |
| 219 | + await fileActions.docEditor.click({force: true}); |
| 220 | + |
| 221 | + await page.keyboard.press('Control+A'); |
| 222 | + await page.keyboard.press('Control+C'); |
| 223 | + |
| 224 | + const clipboardText = await page.evaluate(() => navigator.clipboard.readText()); |
| 225 | + |
| 226 | + expect(clipboardText.trim()).toEqual(''); |
| 227 | + |
| 228 | + } catch (e) { |
| 229 | + await fileActions.toFailure(e,'Can\'t input text into Document'); |
| 230 | + } |
| 231 | +}); |
| 232 | + |
0 commit comments