How to use page.evaluate method in qawolf

Best JavaScript code snippet using qawolf

Terminal.api.ts

Source:Terminal.api.ts Github

copy

Full Screen

...20 after(async () => browser.close());21 beforeEach(async () => page.goto(APP));22 it('Default options', async () => {23 await openTerminal(page);24 assert.equal(await page.evaluate(`window.term.cols`), 80);25 assert.equal(await page.evaluate(`window.term.rows`), 24);26 });27 it('Proposed API check', async () => {28 await openTerminal(page, { allowProposedApi: false });29 await page.evaluate(`30 try {31 window.term.buffer;32 } catch (e) {33 window.throwMessage = e.message;34 }35 `);36 await pollFor(page, 'window.throwMessage', 'You must set the allowProposedApi option to true to use proposed API');37 });38 it('write', async () => {39 await openTerminal(page);40 await page.evaluate(`41 window.term.write('foo');42 window.term.write('bar');43 window.term.write('文');44 `);45 await pollFor(page, `window.term.buffer.active.getLine(0).translateToString(true)`, 'foobar文');46 });47 it('write with callback', async () => {48 await openTerminal(page);49 await page.evaluate(`50 window.term.write('foo', () => { window.__x = 'a'; });51 window.term.write('bar', () => { window.__x += 'b'; });52 window.term.write('文', () => { window.__x += 'c'; });53 `);54 await pollFor(page, `window.term.buffer.active.getLine(0).translateToString(true)`, 'foobar文');55 await pollFor(page, `window.__x`, 'abc');56 });57 it('write - bytes (UTF8)', async () => {58 await openTerminal(page);59 await page.evaluate(`60 window.term.write(new Uint8Array([102, 111, 111])); // foo61 window.term.write(new Uint8Array([98, 97, 114])); // bar62 window.term.write(new Uint8Array([230, 150, 135])); // 文63 `);64 await pollFor(page, `window.term.buffer.active.getLine(0).translateToString(true)`, 'foobar文');65 });66 it('write - bytes (UTF8) with callback', async () => {67 await openTerminal(page);68 await page.evaluate(`69 window.term.write(new Uint8Array([102, 111, 111]), () => { window.__x = 'A'; }); // foo70 window.term.write(new Uint8Array([98, 97, 114]), () => { window.__x += 'B'; }); // bar71 window.term.write(new Uint8Array([230, 150, 135]), () => { window.__x += 'C'; }); // 文72 `);73 await pollFor(page, `window.term.buffer.active.getLine(0).translateToString(true)`, 'foobar文');74 await pollFor(page, `window.__x`, 'ABC');75 });76 it('writeln', async () => {77 await openTerminal(page);78 await page.evaluate(`79 window.term.writeln('foo');80 window.term.writeln('bar');81 window.term.writeln('文');82 `);83 await pollFor(page, `window.term.buffer.active.getLine(0).translateToString(true)`, 'foo');84 await pollFor(page, `window.term.buffer.active.getLine(1).translateToString(true)`, 'bar');85 await pollFor(page, `window.term.buffer.active.getLine(2).translateToString(true)`, '文');86 });87 it('writeln with callback', async () => {88 await openTerminal(page);89 await page.evaluate(`90 window.term.writeln('foo', () => { window.__x = '1'; });91 window.term.writeln('bar', () => { window.__x += '2'; });92 window.term.writeln('文', () => { window.__x += '3'; });93 `);94 await pollFor(page, `window.term.buffer.active.getLine(0).translateToString(true)`, 'foo');95 await pollFor(page, `window.term.buffer.active.getLine(1).translateToString(true)`, 'bar');96 await pollFor(page, `window.term.buffer.active.getLine(2).translateToString(true)`, '文');97 await pollFor(page, `window.__x`, '123');98 });99 it('writeln - bytes (UTF8)', async () => {100 await openTerminal(page);101 await page.evaluate(`102 window.term.writeln(new Uint8Array([102, 111, 111]));103 window.term.writeln(new Uint8Array([98, 97, 114]));104 window.term.writeln(new Uint8Array([230, 150, 135]));105 `);106 await pollFor(page, `window.term.buffer.active.getLine(0).translateToString(true)`, 'foo');107 await pollFor(page, `window.term.buffer.active.getLine(1).translateToString(true)`, 'bar');108 await pollFor(page, `window.term.buffer.active.getLine(2).translateToString(true)`, '文');109 });110 it('paste', async () => {111 await openTerminal(page);112 await page.evaluate(`113 window.calls = [];114 window.term.onData(e => calls.push(e));115 window.term.paste('foo');116 window.term.paste('\\r\\nfoo\\nbar\\r');117 window.term.write('\\x1b[?2004h', () => {118 window.term.paste('foo');119 });120 `);121 await pollFor(page, `window.calls`, ['foo', '\rfoo\rbar\r', '\x1b[200~foo\x1b[201~']);122 });123 it('clear', async () => {124 await openTerminal(page, { rows: 5 });125 await page.evaluate(`126 window.term.write('test0');127 window.parsed = 0;128 for (let i = 1; i < 10; i++) {129 window.term.write('\\n\\rtest' + i, () => window.parsed++);130 }131 `);132 await pollFor(page, `window.parsed`, 9);133 await page.evaluate(`window.term.clear()`);134 await pollFor(page, `window.term.buffer.active.length`, 5);135 await pollFor(page, `window.term.buffer.active.getLine(0).translateToString(true)`, 'test9');136 for (let i = 1; i < 5; i++) {137 await pollFor(page, `window.term.buffer.active.getLine(${i}).translateToString(true)`, '');138 }139 });140 it('getOption, setOption', async () => {141 await openTerminal(page);142 assert.equal(await page.evaluate(`window.term.getOption('rendererType')`), 'canvas');143 await page.evaluate(`window.term.setOption('rendererType', 'dom')`);144 assert.equal(await page.evaluate(`window.term.getOption('rendererType')`), 'dom');145 });146 describe('options', () => {147 it('getter', async () => {148 await openTerminal(page);149 assert.equal(await page.evaluate(`window.term.options.rendererType`), 'canvas');150 assert.equal(await page.evaluate(`window.term.options.cols`), 80);151 assert.equal(await page.evaluate(`window.term.options.rows`), 24);152 });153 it('setter', async () => {154 await openTerminal(page);155 try {156 await page.evaluate('window.term.options.cols = 40');157 fail();158 } catch {}159 try {160 await page.evaluate('window.term.options.rows = 20');161 fail();162 } catch {}163 await page.evaluate('window.term.options.scrollback = 1');164 assert.equal(await page.evaluate(`window.term.options.scrollback`), 1);165 await page.evaluate(`166 window.term.options = {167 fontSize: 30,168 fontFamily: 'Arial'169 };170 `);171 assert.equal(await page.evaluate(`window.term.options.fontSize`), 30);172 assert.equal(await page.evaluate(`window.term.options.fontFamily`), 'Arial');173 });174 it('object.keys return the correct number of options', async () => {175 await openTerminal(page);176 assert.notEqual(await page.evaluate(`Object.keys(window.term.options).length`), 0);177 });178 });179 describe('renderer', () => {180 it('foreground', async () => {181 await openTerminal(page, { rendererType: 'dom' });182 await writeSync(page, '\\x1b[30m0\\x1b[31m1\\x1b[32m2\\x1b[33m3\\x1b[34m4\\x1b[35m5\\x1b[36m6\\x1b[37m7');183 await pollFor(page, `document.querySelectorAll('.xterm-rows > :nth-child(1) > *').length`, 9);184 assert.deepEqual(await page.evaluate(`185 [186 document.querySelector('.xterm-rows > :nth-child(1) > :nth-child(1)').className,187 document.querySelector('.xterm-rows > :nth-child(1) > :nth-child(2)').className,188 document.querySelector('.xterm-rows > :nth-child(1) > :nth-child(3)').className,189 document.querySelector('.xterm-rows > :nth-child(1) > :nth-child(4)').className,190 document.querySelector('.xterm-rows > :nth-child(1) > :nth-child(5)').className,191 document.querySelector('.xterm-rows > :nth-child(1) > :nth-child(6)').className,192 document.querySelector('.xterm-rows > :nth-child(1) > :nth-child(7)').className193 ]194 `), [195 'xterm-fg-0',196 'xterm-fg-1',197 'xterm-fg-2',198 'xterm-fg-3',199 'xterm-fg-4',200 'xterm-fg-5',201 'xterm-fg-6'202 ]);203 });204 it('background', async () => {205 await openTerminal(page, { rendererType: 'dom' });206 await writeSync(page, '\\x1b[40m0\\x1b[41m1\\x1b[42m2\\x1b[43m3\\x1b[44m4\\x1b[45m5\\x1b[46m6\\x1b[47m7');207 await pollFor(page, `document.querySelectorAll('.xterm-rows > :nth-child(1) > *').length`, 9);208 assert.deepEqual(await page.evaluate(`209 [210 document.querySelector('.xterm-rows > :nth-child(1) > :nth-child(1)').className,211 document.querySelector('.xterm-rows > :nth-child(1) > :nth-child(2)').className,212 document.querySelector('.xterm-rows > :nth-child(1) > :nth-child(3)').className,213 document.querySelector('.xterm-rows > :nth-child(1) > :nth-child(4)').className,214 document.querySelector('.xterm-rows > :nth-child(1) > :nth-child(5)').className,215 document.querySelector('.xterm-rows > :nth-child(1) > :nth-child(6)').className,216 document.querySelector('.xterm-rows > :nth-child(1) > :nth-child(7)').className217 ]218 `), [219 'xterm-bg-0',220 'xterm-bg-1',221 'xterm-bg-2',222 'xterm-bg-3',223 'xterm-bg-4',224 'xterm-bg-5',225 'xterm-bg-6'226 ]);227 });228 });229 it('selection', async () => {230 await openTerminal(page, { rows: 5, cols: 5 });231 await writeSync(page, `\\n\\nfoo\\n\\n\\rbar\\n\\n\\rbaz`);232 assert.equal(await page.evaluate(`window.term.hasSelection()`), false);233 assert.equal(await page.evaluate(`window.term.getSelection()`), '');234 assert.deepEqual(await page.evaluate(`window.term.getSelectionPosition()`), undefined);235 await page.evaluate(`window.term.selectAll()`);236 assert.equal(await page.evaluate(`window.term.hasSelection()`), true);237 if (process.platform === 'win32') {238 assert.equal(await page.evaluate(`window.term.getSelection()`), '\r\n\r\nfoo\r\n\r\nbar\r\n\r\nbaz');239 } else {240 assert.equal(await page.evaluate(`window.term.getSelection()`), '\n\nfoo\n\nbar\n\nbaz');241 }242 assert.deepEqual(await page.evaluate(`window.term.getSelectionPosition()`), { startColumn: 0, startRow: 0, endColumn: 5, endRow: 6 });243 await page.evaluate(`window.term.clearSelection()`);244 assert.equal(await page.evaluate(`window.term.hasSelection()`), false);245 assert.equal(await page.evaluate(`window.term.getSelection()`), '');246 assert.deepEqual(await page.evaluate(`window.term.getSelectionPosition()`), undefined);247 await page.evaluate(`window.term.select(1, 2, 2)`);248 assert.equal(await page.evaluate(`window.term.hasSelection()`), true);249 assert.equal(await page.evaluate(`window.term.getSelection()`), 'oo');250 assert.deepEqual(await page.evaluate(`window.term.getSelectionPosition()`), { startColumn: 1, startRow: 2, endColumn: 3, endRow: 2 });251 });252 it('focus, blur', async () => {253 await openTerminal(page);254 assert.equal(await page.evaluate(`document.activeElement.className`), '');255 await page.evaluate(`window.term.focus()`);256 assert.equal(await page.evaluate(`document.activeElement.className`), 'xterm-helper-textarea');257 await page.evaluate(`window.term.blur()`);258 assert.equal(await page.evaluate(`document.activeElement.className`), '');259 });260 describe('loadAddon', () => {261 it('constructor', async () => {262 await openTerminal(page, { cols: 5 });263 await page.evaluate(`264 window.cols = 0;265 window.term.loadAddon({266 activate: (t) => window.cols = t.cols,267 dispose: () => {}268 });269 `);270 assert.equal(await page.evaluate(`window.cols`), 5);271 });272 it('dispose (addon)', async () => {273 await openTerminal(page);274 await page.evaluate(`275 window.disposeCalled = false276 window.addon = {277 activate: () => {},278 dispose: () => window.disposeCalled = true279 };280 window.term.loadAddon(window.addon);281 `);282 assert.equal(await page.evaluate(`window.disposeCalled`), false);283 await page.evaluate(`window.addon.dispose()`);284 assert.equal(await page.evaluate(`window.disposeCalled`), true);285 });286 it('dispose (terminal)', async () => {287 await openTerminal(page);288 await page.evaluate(`289 window.disposeCalled = false290 window.term.loadAddon({291 activate: () => {},292 dispose: () => window.disposeCalled = true293 });294 `);295 assert.equal(await page.evaluate(`window.disposeCalled`), false);296 await page.evaluate(`window.term.dispose()`);297 assert.equal(await page.evaluate(`window.disposeCalled`), true);298 });299 });300 describe('Events', () => {301 it('onCursorMove', async () => {302 await openTerminal(page);303 await page.evaluate(`304 window.callCount = 0;305 window.term.onCursorMove(e => window.callCount++);306 window.term.write('foo');307 `);308 await pollFor(page, `window.callCount`, 1);309 await page.evaluate(`window.term.write('bar')`);310 await pollFor(page, `window.callCount`, 2);311 });312 it('onData', async () => {313 await openTerminal(page);314 await page.evaluate(`315 window.calls = [];316 window.term.onData(e => calls.push(e));317 `);318 await page.type('.xterm-helper-textarea', 'foo');319 assert.deepEqual(await page.evaluate(`window.calls`), ['f', 'o', 'o']);320 });321 it('onKey', async () => {322 await openTerminal(page);323 await page.evaluate(`324 window.calls = [];325 window.term.onKey(e => calls.push(e.key));326 `);327 await page.type('.xterm-helper-textarea', 'foo');328 assert.deepEqual(await page.evaluate(`window.calls`), ['f', 'o', 'o']);329 });330 it('onLineFeed', async () => {331 await openTerminal(page);332 await page.evaluate(`333 window.callCount = 0;334 window.term.onLineFeed(() => callCount++);335 window.term.writeln('foo');336 `);337 await pollFor(page, `window.callCount`, 1);338 await page.evaluate(`window.term.writeln('bar')`);339 await pollFor(page, `window.callCount`, 2);340 });341 it('onScroll', async () => {342 await openTerminal(page, { rows: 5 });343 await page.evaluate(`344 window.calls = [];345 window.term.onScroll(e => window.calls.push(e));346 for (let i = 0; i < 4; i++) {347 window.term.writeln('foo');348 }349 `);350 await pollFor(page, `window.calls`, []);351 await page.evaluate(`window.term.writeln('bar')`);352 await pollFor(page, `window.calls`, [1]);353 await page.evaluate(`window.term.writeln('baz')`);354 await pollFor(page, `window.calls`, [1, 2]);355 });356 it('onSelectionChange', async () => {357 await openTerminal(page);358 await page.evaluate(`359 window.callCount = 0;360 window.term.onSelectionChange(() => window.callCount++);361 `);362 await pollFor(page, `window.callCount`, 0);363 await page.evaluate(`window.term.selectAll()`);364 await pollFor(page, `window.callCount`, 1);365 await page.evaluate(`window.term.clearSelection()`);366 await pollFor(page, `window.callCount`, 2);367 });368 it('onRender', async function(): Promise<void> {369 this.retries(3);370 await openTerminal(page);371 await timeout(20); // Ensure all init events are fired372 await page.evaluate(`373 window.calls = [];374 window.term.onRender(e => window.calls.push([e.start, e.end]));375 `);376 await pollFor(page, `window.calls`, []);377 await page.evaluate(`window.term.write('foo')`);378 await pollFor(page, `window.calls`, [[0, 0]]);379 await page.evaluate(`window.term.write('bar\\n\\nbaz')`);380 await pollFor(page, `window.calls`, [[0, 0], [0, 2]]);381 });382 it('onResize', async () => {383 await openTerminal(page);384 await timeout(20); // Ensure all init events are fired385 await page.evaluate(`386 window.calls = [];387 window.term.onResize(e => window.calls.push([e.cols, e.rows]));388 `);389 await pollFor(page, `window.calls`, []);390 await page.evaluate(`window.term.resize(10, 5)`);391 await pollFor(page, `window.calls`, [[10, 5]]);392 await page.evaluate(`window.term.resize(20, 15)`);393 await pollFor(page, `window.calls`, [[10, 5], [20, 15]]);394 });395 it('onTitleChange', async () => {396 await openTerminal(page);397 await page.evaluate(`398 window.calls = [];399 window.term.onTitleChange(e => window.calls.push(e));400 `);401 await pollFor(page, `window.calls`, []);402 await page.evaluate(`window.term.write('\\x1b]2;foo\\x9c')`);403 await pollFor(page, `window.calls`, ['foo']);404 });405 it('onBell', async () => {406 await openTerminal(page);407 await page.evaluate(`408 window.calls = [];409 window.term.onBell(() => window.calls.push(true));410 `);411 await pollFor(page, `window.calls`, []);412 await page.evaluate(`window.term.write('\\x07')`);413 await pollFor(page, `window.calls`, [true]);414 });415 });416 describe('buffer', () => {417 it('cursorX, cursorY', async () => {418 await openTerminal(page, { rows: 5, cols: 5 });419 assert.equal(await page.evaluate(`window.term.buffer.active.cursorX`), 0);420 assert.equal(await page.evaluate(`window.term.buffer.active.cursorY`), 0);421 await writeSync(page, 'foo');422 assert.equal(await page.evaluate(`window.term.buffer.active.cursorX`), 3);423 assert.equal(await page.evaluate(`window.term.buffer.active.cursorY`), 0);424 await writeSync(page, '\\n');425 assert.equal(await page.evaluate(`window.term.buffer.active.cursorX`), 3);426 assert.equal(await page.evaluate(`window.term.buffer.active.cursorY`), 1);427 await writeSync(page, '\\r');428 assert.equal(await page.evaluate(`window.term.buffer.active.cursorX`), 0);429 assert.equal(await page.evaluate(`window.term.buffer.active.cursorY`), 1);430 await writeSync(page, 'abcde');431 assert.equal(await page.evaluate(`window.term.buffer.active.cursorX`), 5);432 assert.equal(await page.evaluate(`window.term.buffer.active.cursorY`), 1);433 await writeSync(page, '\\n\\r\\n\\n\\n\\n\\n');434 assert.equal(await page.evaluate(`window.term.buffer.active.cursorX`), 0);435 assert.equal(await page.evaluate(`window.term.buffer.active.cursorY`), 4);436 });437 it('viewportY', async () => {438 await openTerminal(page, { rows: 5 });439 assert.equal(await page.evaluate(`window.term.buffer.active.viewportY`), 0);440 await writeSync(page, '\\n\\n\\n\\n');441 assert.equal(await page.evaluate(`window.term.buffer.active.viewportY`), 0);442 await writeSync(page, '\\n');443 assert.equal(await page.evaluate(`window.term.buffer.active.viewportY`), 1);444 await writeSync(page, '\\n\\n\\n\\n');445 assert.equal(await page.evaluate(`window.term.buffer.active.viewportY`), 5);446 await page.evaluate(`window.term.scrollLines(-1)`);447 assert.equal(await page.evaluate(`window.term.buffer.active.viewportY`), 4);448 await page.evaluate(`window.term.scrollToTop()`);449 assert.equal(await page.evaluate(`window.term.buffer.active.viewportY`), 0);450 });451 it('baseY', async () => {452 await openTerminal(page, { rows: 5 });453 assert.equal(await page.evaluate(`window.term.buffer.active.baseY`), 0);454 await writeSync(page, '\\n\\n\\n\\n');455 assert.equal(await page.evaluate(`window.term.buffer.active.baseY`), 0);456 await writeSync(page, '\\n');457 assert.equal(await page.evaluate(`window.term.buffer.active.baseY`), 1);458 await writeSync(page, '\\n\\n\\n\\n');459 assert.equal(await page.evaluate(`window.term.buffer.active.baseY`), 5);460 await page.evaluate(`window.term.scrollLines(-1)`);461 assert.equal(await page.evaluate(`window.term.buffer.active.baseY`), 5);462 await page.evaluate(`window.term.scrollToTop()`);463 assert.equal(await page.evaluate(`window.term.buffer.active.baseY`), 5);464 });465 it('length', async () => {466 await openTerminal(page, { rows: 5 });467 assert.equal(await page.evaluate(`window.term.buffer.active.length`), 5);468 await writeSync(page, '\\n\\n\\n\\n');469 assert.equal(await page.evaluate(`window.term.buffer.active.length`), 5);470 await writeSync(page, '\\n');471 assert.equal(await page.evaluate(`window.term.buffer.active.length`), 6);472 await writeSync(page, '\\n\\n\\n\\n');473 assert.equal(await page.evaluate(`window.term.buffer.active.length`), 10);474 });475 describe('getLine', () => {476 it('invalid index', async () => {477 await openTerminal(page, { rows: 5 });478 assert.equal(await page.evaluate(`window.term.buffer.active.getLine(-1)`), undefined);479 assert.equal(await page.evaluate(`window.term.buffer.active.getLine(5)`), undefined);480 });481 it('isWrapped', async () => {482 await openTerminal(page, { cols: 5 });483 assert.equal(await page.evaluate(`window.term.buffer.active.getLine(0).isWrapped`), false);484 assert.equal(await page.evaluate(`window.term.buffer.active.getLine(1).isWrapped`), false);485 await writeSync(page, 'abcde');486 assert.equal(await page.evaluate(`window.term.buffer.active.getLine(0).isWrapped`), false);487 assert.equal(await page.evaluate(`window.term.buffer.active.getLine(1).isWrapped`), false);488 await writeSync(page, 'f');489 assert.equal(await page.evaluate(`window.term.buffer.active.getLine(0).isWrapped`), false);490 assert.equal(await page.evaluate(`window.term.buffer.active.getLine(1).isWrapped`), true);491 });492 it('translateToString', async () => {493 await openTerminal(page, { cols: 5 });494 assert.equal(await page.evaluate(`window.term.buffer.active.getLine(0).translateToString()`), ' ');495 assert.equal(await page.evaluate(`window.term.buffer.active.getLine(0).translateToString(true)`), '');496 await writeSync(page, 'foo');497 assert.equal(await page.evaluate(`window.term.buffer.active.getLine(0).translateToString()`), 'foo ');498 assert.equal(await page.evaluate(`window.term.buffer.active.getLine(0).translateToString(true)`), 'foo');499 await writeSync(page, 'bar');500 assert.equal(await page.evaluate(`window.term.buffer.active.getLine(0).translateToString()`), 'fooba');501 assert.equal(await page.evaluate(`window.term.buffer.active.getLine(0).translateToString(true)`), 'fooba');502 assert.equal(await page.evaluate(`window.term.buffer.active.getLine(1).translateToString(true)`), 'r');503 assert.equal(await page.evaluate(`window.term.buffer.active.getLine(0).translateToString(false, 1)`), 'ooba');504 assert.equal(await page.evaluate(`window.term.buffer.active.getLine(0).translateToString(false, 1, 3)`), 'oo');505 });506 it('getCell', async () => {507 await openTerminal(page, { cols: 5 });508 assert.equal(await page.evaluate(`window.term.buffer.active.getLine(0).getCell(-1)`), undefined);509 assert.equal(await page.evaluate(`window.term.buffer.active.getLine(0).getCell(5)`), undefined);510 assert.equal(await page.evaluate(`window.term.buffer.active.getLine(0).getCell(0).getChars()`), '');511 assert.equal(await page.evaluate(`window.term.buffer.active.getLine(0).getCell(0).getWidth()`), 1);512 await writeSync(page, 'a文');513 assert.equal(await page.evaluate(`window.term.buffer.active.getLine(0).getCell(0).getChars()`), 'a');514 assert.equal(await page.evaluate(`window.term.buffer.active.getLine(0).getCell(0).getWidth()`), 1);515 assert.equal(await page.evaluate(`window.term.buffer.active.getLine(0).getCell(1).getChars()`), '文');516 assert.equal(await page.evaluate(`window.term.buffer.active.getLine(0).getCell(1).getWidth()`), 2);517 assert.equal(await page.evaluate(`window.term.buffer.active.getLine(0).getCell(2).getChars()`), '');518 assert.equal(await page.evaluate(`window.term.buffer.active.getLine(0).getCell(2).getWidth()`), 0);519 });520 it('clearMarkers', async () => {521 await openTerminal(page, { cols: 5 });522 await page.evaluate(`523 window.disposeStack = [];524 `);525 await writeSync(page, '\\n\\n\\n\\n');526 await writeSync(page, '\\n\\n\\n\\n');527 await writeSync(page, '\\n\\n\\n\\n');528 await writeSync(page, '\\n\\n\\n\\n');529 await page.evaluate(`window.term.addMarker(1)`);530 await page.evaluate(`window.term.addMarker(2)`);531 await page.evaluate(`window.term.scrollLines(10)`);532 await page.evaluate(`window.term.addMarker(3)`);533 await page.evaluate(`window.term.addMarker(4)`);534 await page.evaluate(`535 for (let i = 0; i < window.term.markers.length; ++i) {536 const marker = window.term.markers[i];537 marker.onDispose(() => window.disposeStack.push(marker));538 }`);539 await page.evaluate(`window.term.clear()`);540 assert.equal(await page.evaluate(`window.disposeStack.length`), 4);541 });542 });543 it('active, normal, alternate', async () => {544 await openTerminal(page, { cols: 5 });545 assert.equal(await page.evaluate(`window.term.buffer.active.type`), 'normal');546 assert.equal(await page.evaluate(`window.term.buffer.normal.type`), 'normal');547 assert.equal(await page.evaluate(`window.term.buffer.alternate.type`), 'alternate');548 await writeSync(page, 'norm ');549 assert.equal(await page.evaluate(`window.term.buffer.active.getLine(0).translateToString()`), 'norm ');550 assert.equal(await page.evaluate(`window.term.buffer.normal.getLine(0).translateToString()`), 'norm ');551 assert.equal(await page.evaluate(`window.term.buffer.alternate.getLine(0)`), undefined);552 await writeSync(page, '\\x1b[?47h\\r'); // use alternate screen buffer553 assert.equal(await page.evaluate(`window.term.buffer.active.type`), 'alternate');554 assert.equal(await page.evaluate(`window.term.buffer.normal.type`), 'normal');555 assert.equal(await page.evaluate(`window.term.buffer.alternate.type`), 'alternate');556 assert.equal(await page.evaluate(`window.term.buffer.active.getLine(0).translateToString()`), ' ');557 await writeSync(page, 'alt ');558 assert.equal(await page.evaluate(`window.term.buffer.active.getLine(0).translateToString()`), 'alt ');559 assert.equal(await page.evaluate(`window.term.buffer.normal.getLine(0).translateToString()`), 'norm ');560 assert.equal(await page.evaluate(`window.term.buffer.alternate.getLine(0).translateToString()`), 'alt ');561 await writeSync(page, '\\x1b[?47l\\r'); // use normal screen buffer562 assert.equal(await page.evaluate(`window.term.buffer.active.type`), 'normal');563 assert.equal(await page.evaluate(`window.term.buffer.normal.type`), 'normal');564 assert.equal(await page.evaluate(`window.term.buffer.alternate.type`), 'alternate');565 assert.equal(await page.evaluate(`window.term.buffer.active.getLine(0).translateToString()`), 'norm ');566 assert.equal(await page.evaluate(`window.term.buffer.normal.getLine(0).translateToString()`), 'norm ');567 assert.equal(await page.evaluate(`window.term.buffer.alternate.getLine(0)`), undefined);568 });569 });570 describe('modes', () => {571 it('defaults', async () => {572 await openTerminal(page);573 assert.deepStrictEqual(await page.evaluate(`window.term.modes`), {574 applicationCursorKeysMode: false,575 applicationKeypadMode: false,576 bracketedPasteMode: false,577 insertMode: false,578 mouseTrackingMode: 'none',579 originMode: false,580 reverseWraparoundMode: false,581 sendFocusMode: false,582 wraparoundMode: true583 });584 });585 it('applicationCursorKeysMode', async () => {586 await openTerminal(page);587 await writeSync(page, '\\x1b[?1h');588 assert.strictEqual(await page.evaluate(`window.term.modes.applicationCursorKeysMode`), true);589 await writeSync(page, '\\x1b[?1l');590 assert.strictEqual(await page.evaluate(`window.term.modes.applicationCursorKeysMode`), false);591 });592 it('applicationKeypadMode', async () => {593 await openTerminal(page);594 await writeSync(page, '\\x1b[?66h');595 assert.strictEqual(await page.evaluate(`window.term.modes.applicationKeypadMode`), true);596 await writeSync(page, '\\x1b[?66l');597 assert.strictEqual(await page.evaluate(`window.term.modes.applicationKeypadMode`), false);598 });599 it('bracketedPasteMode', async () => {600 await openTerminal(page);601 await writeSync(page, '\\x1b[?2004h');602 assert.strictEqual(await page.evaluate(`window.term.modes.bracketedPasteMode`), true);603 await writeSync(page, '\\x1b[?2004l');604 assert.strictEqual(await page.evaluate(`window.term.modes.bracketedPasteMode`), false);605 });606 it('insertMode', async () => {607 await openTerminal(page);608 await writeSync(page, '\\x1b[4h');609 assert.strictEqual(await page.evaluate(`window.term.modes.insertMode`), true);610 await writeSync(page, '\\x1b[4l');611 assert.strictEqual(await page.evaluate(`window.term.modes.insertMode`), false);612 });613 it('mouseTrackingMode', async () => {614 await openTerminal(page);615 await writeSync(page, '\\x1b[?9h');616 assert.strictEqual(await page.evaluate(`window.term.modes.mouseTrackingMode`), 'x10');617 await writeSync(page, '\\x1b[?9l');618 assert.strictEqual(await page.evaluate(`window.term.modes.mouseTrackingMode`), 'none');619 await writeSync(page, '\\x1b[?1000h');620 assert.strictEqual(await page.evaluate(`window.term.modes.mouseTrackingMode`), 'vt200');621 await writeSync(page, '\\x1b[?1000l');622 assert.strictEqual(await page.evaluate(`window.term.modes.mouseTrackingMode`), 'none');623 await writeSync(page, '\\x1b[?1002h');624 assert.strictEqual(await page.evaluate(`window.term.modes.mouseTrackingMode`), 'drag');625 await writeSync(page, '\\x1b[?1002l');626 assert.strictEqual(await page.evaluate(`window.term.modes.mouseTrackingMode`), 'none');627 await writeSync(page, '\\x1b[?1003h');628 assert.strictEqual(await page.evaluate(`window.term.modes.mouseTrackingMode`), 'any');629 await writeSync(page, '\\x1b[?1003l');630 assert.strictEqual(await page.evaluate(`window.term.modes.mouseTrackingMode`), 'none');631 });632 it('originMode', async () => {633 await openTerminal(page);634 await writeSync(page, '\\x1b[?6h');635 assert.strictEqual(await page.evaluate(`window.term.modes.originMode`), true);636 await writeSync(page, '\\x1b[?6l');637 assert.strictEqual(await page.evaluate(`window.term.modes.originMode`), false);638 });639 it('reverseWraparoundMode', async () => {640 await openTerminal(page);641 await writeSync(page, '\\x1b[?45h');642 assert.strictEqual(await page.evaluate(`window.term.modes.reverseWraparoundMode`), true);643 await writeSync(page, '\\x1b[?45l');644 assert.strictEqual(await page.evaluate(`window.term.modes.reverseWraparoundMode`), false);645 });646 it('sendFocusMode', async () => {647 await openTerminal(page);648 await writeSync(page, '\\x1b[?1004h');649 assert.strictEqual(await page.evaluate(`window.term.modes.sendFocusMode`), true);650 await writeSync(page, '\\x1b[?1004l');651 assert.strictEqual(await page.evaluate(`window.term.modes.sendFocusMode`), false);652 });653 it('wraparoundMode', async () => {654 await openTerminal(page);655 await writeSync(page, '\\x1b[?7h');656 assert.strictEqual(await page.evaluate(`window.term.modes.wraparoundMode`), true);657 await writeSync(page, '\\x1b[?7l');658 assert.strictEqual(await page.evaluate(`window.term.modes.wraparoundMode`), false);659 });660 });661 it('dispose', async () => {662 await page.evaluate(`663 window.term = new Terminal();664 window.term.dispose();665 `);666 assert.equal(await page.evaluate(`window.term._core._isDisposed`), true);667 });668 it('dispose (opened)', async () => {669 await openTerminal(page);670 await page.evaluate(`window.term.dispose()`);671 assert.equal(await page.evaluate(`window.term._core._isDisposed`), true);672 });673 it('render when visible after hidden', async () => {674 await page.evaluate(`document.querySelector('#terminal-container').style.display='none'`);675 await page.evaluate(`window.term = new Terminal()`);676 await page.evaluate(`window.term.open(document.querySelector('#terminal-container'))`);677 await page.evaluate(`document.querySelector('#terminal-container').style.display=''`);678 await pollFor(page, `window.term._core._renderService.dimensions.actualCellWidth > 0`, true);679 });680 describe('registerDecoration', () => {681 describe('bufferDecorations', () => {682 it('should register decorations and render them when terminal open is called', async () => {683 await page.evaluate(`window.term = new Terminal({})`);684 await page.evaluate(`window.term.open(document.querySelector('#terminal-container'))`);685 await page.waitForSelector('.xterm-text-layer');686 await page.evaluate(`window.marker1 = window.term.addMarker(1)`);687 await page.evaluate(`window.marker2 = window.term.addMarker(2)`);688 await page.evaluate(`window.term.registerDecoration({ marker: window.marker1 })`);689 await page.evaluate(`window.term.registerDecoration({ marker: window.marker2 })`);690 await openTerminal(page);691 await pollFor(page, `document.querySelectorAll('.xterm-screen .xterm-decoration').length`, 2);692 });693 it('should return undefined when the marker has already been disposed of', async () => {694 await openTerminal(page);695 await page.evaluate(`window.marker = window.term.addMarker(1)`);696 await page.evaluate(`window.marker.dispose()`);697 await pollFor(page, `window.decoration = window.term.registerDecoration({ marker: window.marker });`, undefined);698 });699 it('should throw when a negative x offset is provided', async () => {700 await openTerminal(page);701 await page.evaluate(`window.marker = window.term.addMarker(1)`);702 await page.evaluate(`703 try {704 window.decoration = window.term.registerDecoration({ marker: window.marker, x: -2 });705 } catch (e) {706 window.throwMessage = e.message;707 }708 `);709 await pollFor(page, 'window.throwMessage', 'This API only accepts positive integers');710 });711 });712 describe('overviewRulerDecorations', () => {713 it('should not add an overview ruler when width is not set', async () => {714 await page.evaluate(`window.term = new Terminal({})`);715 await page.evaluate(`window.term.open(document.querySelector('#terminal-container'))`);716 await page.waitForSelector('.xterm-text-layer');717 await page.evaluate(`window.marker1 = window.term.addMarker(1)`);718 await page.evaluate(`window.marker2 = window.term.addMarker(2)`);719 await page.evaluate(`window.term.registerDecoration({ marker: window.marker1, overviewRulerOptions: { color: 'red', position: 'full' } })`);720 await page.evaluate(`window.term.registerDecoration({ marker: window.marker2, overviewRulerOptions: { color: 'blue', position: 'full' } })`);721 await openTerminal(page);722 await pollFor(page, `document.querySelectorAll('.xterm-decoration-overview-ruler').length`, 0);723 });724 it('should add an overview ruler when width is set', async () => {725 await page.evaluate(`window.term = new Terminal({ overviewRulerWidth: 15 })`);726 await page.evaluate(`window.term.open(document.querySelector('#terminal-container'))`);727 await page.waitForSelector('.xterm-text-layer');728 await page.evaluate(`window.marker1 = window.term.addMarker(1)`);729 await page.evaluate(`window.marker2 = window.term.addMarker(2)`);730 await page.evaluate(`window.term.registerDecoration({ marker: window.marker1, overviewRulerOptions: { color: 'red', position: 'full' } })`);731 await page.evaluate(`window.term.registerDecoration({ marker: window.marker2, overviewRulerOptions: { color: 'blue', position: 'full' } })`);732 await openTerminal(page);733 await pollFor(page, `document.querySelectorAll('.xterm-decoration-overview-ruler').length`, 1);734 });735 });736 });737 describe('registerLinkProvider', () => {738 it('should fire provideLinks when hovering cells', async () => {739 await openTerminal(page, { rendererType: 'dom' });740 await page.evaluate(`741 window.calls = [];742 window.disposable = window.term.registerLinkProvider({743 provideLinks: (position, cb) => {744 calls.push(position);745 cb(undefined);746 }747 });748 `);749 const dims = await getDimensions();750 await moveMouseCell(page, dims, 1, 1);751 await moveMouseCell(page, dims, 2, 2);752 await moveMouseCell(page, dims, 10, 4);753 await pollFor(page, `window.calls`, [1, 2, 4]);754 await page.evaluate(`window.disposable.dispose()`);755 });756 it('should fire hover and leave events on the link', async () => {757 await openTerminal(page, { rendererType: 'dom' });758 await writeSync(page, 'foo bar baz');759 // Wait for renderer to catch up as links are cleared on render760 await pollFor(page, `document.querySelector('.xterm-rows').textContent`, 'foo bar baz ');761 await page.evaluate(`762 window.calls = [];763 window.disposable = window.term.registerLinkProvider({764 provideLinks: (position, cb) => {765 window.calls.push('provide ' + position);766 if (position === 1) {767 window.calls.push('match');768 cb([{769 range: { start: { x: 5, y: 1 }, end: { x: 7, y: 1 } },770 text: 'bar',771 activate: () => window.calls.push('activate'),772 hover: () => window.calls.push('hover'),773 leave: () => window.calls.push('leave')774 }]);775 }776 }777 });778 `);779 const dims = await getDimensions();780 await moveMouseCell(page, dims, 5, 1);781 await timeout(100);782 await moveMouseCell(page, dims, 4, 1);783 await pollFor(page, `window.calls`, ['provide 1', 'match', 'hover', 'leave' ]);784 await moveMouseCell(page, dims, 7, 1);785 await timeout(100);786 await moveMouseCell(page, dims, 8, 1);787 await pollFor(page, `window.calls`, ['provide 1', 'match', 'hover', 'leave', 'hover', 'leave']);788 await page.evaluate(`window.disposable.dispose()`);789 });790 it('should work fine when hover and leave callbacks are not provided', async () => {791 await openTerminal(page, { rendererType: 'dom' });792 await writeSync(page, 'foo bar baz');793 // Wait for renderer to catch up as links are cleared on render794 await pollFor(page, `document.querySelector('.xterm-rows').textContent`, 'foo bar baz ');795 await page.evaluate(`796 window.calls = [];797 window.disposable = window.term.registerLinkProvider({798 provideLinks: (position, cb) => {799 window.calls.push('provide ' + position);800 if (position === 1) {801 window.calls.push('match 1');802 cb([{803 range: { start: { x: 5, y: 1 }, end: { x: 7, y: 1 } },804 text: 'bar',805 activate: () => window.calls.push('activate')806 }]);807 } else if (position === 2) {808 window.calls.push('match 2');809 cb([{810 range: { start: { x: 5, y: 2 }, end: { x: 7, y: 2 } },811 text: 'bar',812 activate: () => window.calls.push('activate')813 }]);814 }815 }816 });817 `);818 const dims = await getDimensions();819 await moveMouseCell(page, dims, 5, 1);820 await pollFor(page, `window.calls`, ['provide 1', 'match 1']);821 await moveMouseCell(page, dims, 4, 2);822 await pollFor(page, `window.calls`, ['provide 1', 'match 1', 'provide 2', 'match 2']);823 await moveMouseCell(page, dims, 7, 1);824 await pollFor(page, `window.calls`, ['provide 1', 'match 1', 'provide 2', 'match 2', 'provide 1', 'match 1']);825 await moveMouseCell(page, dims, 6, 2);826 await pollFor(page, `window.calls`, ['provide 1', 'match 1', 'provide 2', 'match 2', 'provide 1', 'match 1', 'provide 2', 'match 2']);827 await page.evaluate(`window.disposable.dispose()`);828 });829 it('should fire activate events when clicking the link', async () => {830 await openTerminal(page, { rendererType: 'dom' });831 await writeSync(page, 'a b c');832 // Wait for renderer to catch up as links are cleared on render833 await pollFor(page, `document.querySelector('.xterm-rows').textContent`, 'a b c ');834 // Focus terminal to avoid a render event clearing the active link835 const dims = await getDimensions();836 await moveMouseCell(page, dims, 5, 5);837 await page.mouse.down();838 await page.mouse.up();839 await timeout(200); // Not sure how to avoid this timeout, checking for xterm-focus doesn't help840 await page.evaluate(`841 window.calls = [];842 window.disposable = window.term.registerLinkProvider({843 provideLinks: (y, cb) => {844 window.calls.push('provide ' + y);845 cb([{846 range: { start: { x: 1, y }, end: { x: 80, y } },847 text: window.term.buffer.active.getLine(y - 1).translateToString(),848 activate: (_, text) => window.calls.push('activate ' + y),849 hover: () => window.calls.push('hover ' + y),850 leave: () => window.calls.push('leave ' + y)851 }]);852 }853 });854 `);855 await moveMouseCell(page, dims, 3, 1);856 await pollFor(page, `window.calls`, ['provide 1', 'hover 1']);857 await page.mouse.down();858 await page.mouse.up();859 await pollFor(page, `window.calls`, ['provide 1', 'hover 1', 'activate 1']);860 await moveMouseCell(page, dims, 1, 2);861 await pollFor(page, `window.calls`, ['provide 1', 'hover 1', 'activate 1', 'leave 1', 'provide 2', 'hover 2']);862 await page.mouse.down();863 await page.mouse.up();864 await pollFor(page, `window.calls`, ['provide 1', 'hover 1', 'activate 1', 'leave 1', 'provide 2', 'hover 2', 'activate 2']);865 await moveMouseCell(page, dims, 5, 1);866 await pollFor(page, `window.calls`, ['provide 1', 'hover 1', 'activate 1', 'leave 1', 'provide 2', 'hover 2', 'activate 2', 'leave 2', 'provide 1', 'hover 1']);867 await page.mouse.down();868 await page.mouse.up();869 await pollFor(page, `window.calls`, ['provide 1', 'hover 1', 'activate 1', 'leave 1', 'provide 2', 'hover 2', 'activate 2', 'leave 2', 'provide 1', 'hover 1', 'activate 1']);870 await page.evaluate(`window.disposable.dispose()`);871 });872 it('should work when multiple links are provided on the same line', async () => {873 await openTerminal(page, { rendererType: 'dom' });874 await writeSync(page, 'foo bar baz');875 // Wait for renderer to catch up as links are cleared on render876 await pollFor(page, `document.querySelector('.xterm-rows').textContent`, 'foo bar baz ');877 await page.evaluate(`878 window.calls = [];879 window.disposable = window.term.registerLinkProvider({880 provideLinks: (position, cb) => {881 window.calls.push('provide ' + position);882 if (position === 1) {883 cb([{884 range: { start: { x: 1, y: 1 }, end: { x: 3, y: 1 } },885 text: '',886 activate: () => window.calls.push('activate'),887 hover: () => window.calls.push('hover 1-3'),888 leave: () => window.calls.push('leave 1-3')889 }, {890 range: { start: { x: 5, y: 1 }, end: { x: 7, y: 1 } },891 text: '',892 activate: () => window.calls.push('activate'),893 hover: () => window.calls.push('hover 5-7'),894 leave: () => window.calls.push('leave 5-7')895 }, {896 range: { start: { x: 9, y: 1 }, end: { x: 11, y: 1 } },897 text: '',898 activate: () => window.calls.push('activate'),899 hover: () => window.calls.push('hover 9-11'),900 leave: () => window.calls.push('leave 9-11')901 }]);902 }903 }904 });905 `);906 const dims = await getDimensions();907 await moveMouseCell(page, dims, 2, 1);908 await pollFor(page, `window.calls`, ['provide 1', 'hover 1-3']);909 await moveMouseCell(page, dims, 6, 1);910 await pollFor(page, `window.calls`, ['provide 1', 'hover 1-3', 'leave 1-3', 'hover 5-7']);911 await moveMouseCell(page, dims, 6, 2);912 await pollFor(page, `window.calls`, ['provide 1', 'hover 1-3', 'leave 1-3', 'hover 5-7', 'leave 5-7', 'provide 2']);913 await moveMouseCell(page, dims, 10, 1);914 await pollFor(page, `window.calls`, ['provide 1', 'hover 1-3', 'leave 1-3', 'hover 5-7', 'leave 5-7', 'provide 2', 'provide 1', 'hover 9-11']);915 await page.evaluate(`window.disposable.dispose()`);916 });917 it('should dispose links when hovering away', async () => {918 await openTerminal(page, { rendererType: 'dom' });919 await writeSync(page, 'foo bar baz');920 // Wait for renderer to catch up as links are cleared on render921 await pollFor(page, `document.querySelector('.xterm-rows').textContent`, 'foo bar baz ');922 await page.evaluate(`923 window.calls = [];924 window.disposable = window.term.registerLinkProvider({925 provideLinks: (position, cb) => {926 window.calls.push('provide ' + position);927 if (position === 1) {928 cb([{929 range: { start: { x: 1, y: 1 }, end: { x: 3, y: 1 } },930 text: '',931 activate: () => window.calls.push('activate'),932 dispose: () => window.calls.push('dispose 1-3'),933 hover: () => window.calls.push('hover 1-3'),934 leave: () => window.calls.push('leave 1-3')935 }, {936 range: { start: { x: 5, y: 1 }, end: { x: 7, y: 1 } },937 text: '',938 activate: () => window.calls.push('activate'),939 dispose: () => window.calls.push('dispose 5-7'),940 hover: () => window.calls.push('hover 5-7'),941 leave: () => window.calls.push('leave 5-7')942 }, {943 range: { start: { x: 9, y: 1 }, end: { x: 11, y: 1 } },944 text: '',945 activate: () => window.calls.push('activate'),946 dispose: () => window.calls.push('dispose 9-11'),947 hover: () => window.calls.push('hover 9-11'),948 leave: () => window.calls.push('leave 9-11')949 }]);950 }951 }952 });953 `);954 const dims = await getDimensions();955 await moveMouseCell(page, dims, 2, 1);956 await pollFor(page, `window.calls`, ['provide 1', 'hover 1-3']);957 await moveMouseCell(page, dims, 6, 1);958 await pollFor(page, `window.calls`, ['provide 1', 'hover 1-3', 'leave 1-3', 'hover 5-7']);959 await moveMouseCell(page, dims, 6, 2);960 await pollFor(page, `window.calls`, ['provide 1', 'hover 1-3', 'leave 1-3', 'hover 5-7', 'leave 5-7', 'dispose 1-3', 'dispose 5-7', 'dispose 9-11', 'provide 2']);961 await moveMouseCell(page, dims, 10, 1);962 await pollFor(page, `window.calls`, ['provide 1', 'hover 1-3', 'leave 1-3', 'hover 5-7', 'leave 5-7', 'dispose 1-3', 'dispose 5-7', 'dispose 9-11', 'provide 2', 'provide 1', 'hover 9-11']);963 await moveMouseCell(page, dims, 10, 2);964 await pollFor(page, `window.calls`, ['provide 1', 'hover 1-3', 'leave 1-3', 'hover 5-7', 'leave 5-7', 'dispose 1-3', 'dispose 5-7', 'dispose 9-11', 'provide 2', 'provide 1', 'hover 9-11', 'leave 9-11', 'dispose 1-3', 'dispose 5-7', 'dispose 9-11', 'provide 2']);965 await page.evaluate(`window.disposable.dispose()`);966 });967 });968});969interface IDimensions {970 top: number;971 left: number;972 renderDimensions: IRenderDimensions;973}974interface IRenderDimensions {975 scaledCharWidth: number;976 scaledCharHeight: number;977 scaledCellWidth: number;978 scaledCellHeight: number;979 scaledCharLeft: number;980 scaledCharTop: number;981 scaledCanvasWidth: number;982 scaledCanvasHeight: number;983 canvasWidth: number;984 canvasHeight: number;985 actualCellWidth: number;986 actualCellHeight: number;987}988async function getDimensions(): Promise<IDimensions> {989 return await page.evaluate(`990 (function() {991 const rect = document.querySelector('.xterm-rows').getBoundingClientRect();992 return {993 top: rect.top,994 left: rect.left,995 renderDimensions: window.term._core._renderService.dimensions996 };997 })();998 `);999}1000async function getCellCoordinates(dimensions: IDimensions, col: number, row: number): Promise<{ x: number, y: number }> {1001 return {1002 x: dimensions.left + dimensions.renderDimensions.scaledCellWidth * (col - 0.5),1003 y: dimensions.top + dimensions.renderDimensions.scaledCellHeight * (row - 0.5)...

Full Screen

Full Screen

index.test.js

Source:index.test.js Github

copy

Full Screen

...8 let page = await browser.newPage();9 await page.goto(helpers.PAGE_URL_DEFAULT + `v:public.test`);10 await page.emulate(helpers.EMULATED_SCREEN);11 page = await helpers.waitForPageToLoad(page);12 await page.evaluate(`$('[href="#layer-content"]').trigger('click')`);13 await page.evaluate(`$('[href="#collapseUHVibGljIGdyb3Vw"]').trigger('click')`);14 await helpers.sleep(8000);15 expect(await page.evaluate(`$('#layers').find('.js-app-is-online-badge').hasClass('hidden');`)).to.be.false;16 expect(await page.evaluate(`$('#layers').find('.js-app-is-offline-badge').hasClass('hidden');`)).to.be.true;17 expect(await page.evaluate(`$('[data-gc2-layer-key="public.test_point_no_type.the_geom"]').find('.js-set-online').is(':visible')`)).to.be.false;18 expect(await page.evaluate(`$('[data-gc2-layer-key="public.test_point_no_type.the_geom"]').find('.js-set-offline').is(':visible')`)).to.be.false;19 expect(await page.evaluate(`$('[data-gc2-layer-key="public.test_line.the_geom"]').find('.js-set-online').prop('disabled')`)).to.be.true;20 expect(await page.evaluate(`$('[data-gc2-layer-key="public.test_line.the_geom"]').find('.js-set-offline').prop('disabled')`)).to.be.true;21 expect(await page.evaluate(`$('[data-gc2-layer-key="public.test.the_geom"]').find('.js-set-online').prop('disabled')`)).to.be.true;22 expect(await page.evaluate(`$('[data-gc2-layer-key="public.test.the_geom"]').find('.js-set-offline').prop('disabled')`)).to.be.false;23 expect(await page.evaluate(`$('[data-gc2-layer-key="public.test.the_geom"]').find('.js-refresh').prop('disabled')`)).to.be.true;24 await helpers.sleep(1000);25 await page.evaluate(`$('[data-gc2-layer-key="public.test_point_no_type.the_geom"]').find('.js-set-offline').trigger('click')`);26 await page.evaluate(`$('[data-gc2-layer-key="public.test.the_geom"]').find('.js-set-offline').trigger('click')`);27 await helpers.sleep(2000);28 await helpers.img(page);29 // Reload page30 await page.reload(helpers.PAGE_LOAD_TIMEOUT);31 page = await helpers.waitForPageToLoad(page);32 33 await page.evaluate(`$('[href="#layer-content"]').trigger('click')`);34 await page.evaluate(`$('[href="#collapseUHVibGljIGdyb3Vw"]').trigger('click')`);35 await helpers.sleep(4000);36 expect(await page.evaluate(`$('#layers').find('.js-app-is-online-badge').hasClass('hidden');`)).to.be.false;37 expect(await page.evaluate(`$('#layers').find('.js-app-is-offline-badge').hasClass('hidden');`)).to.be.true;38 expect(await page.evaluate(`$('[data-gc2-layer-key="public.test_point_no_type.the_geom"]').find('.js-set-online').is(':visible')`)).to.be.false;39 expect(await page.evaluate(`$('[data-gc2-layer-key="public.test_point_no_type.the_geom"]').find('.js-set-offline').is(':visible')`)).to.be.false;40 expect(await page.evaluate(`$('[data-gc2-layer-key="public.test_line.the_geom"]').find('.js-set-online').prop('disabled')`)).to.be.true;41 expect(await page.evaluate(`$('[data-gc2-layer-key="public.test_line.the_geom"]').find('.js-set-offline').prop('disabled')`)).to.be.true;42 expect(await page.evaluate(`$('[data-gc2-layer-key="public.test.the_geom"]').find('.js-set-online').prop('disabled')`)).to.be.false;43 expect(await page.evaluate(`$('[data-gc2-layer-key="public.test.the_geom"]').find('.js-set-offline').prop('disabled')`)).to.be.true;44 expect(await page.evaluate(`$('[data-gc2-layer-key="public.test.the_geom"]').find('.js-refresh').prop('disabled')`)).to.be.false;45 await page.close();46 });47 it(`should allow loading vector layers in both dynamic and static mode`, async () => {48 let page = await browser.newPage();49 await page.goto(helpers.PAGE_URL_DEFAULT + `v:public.test`);50 await page.emulate(helpers.EMULATED_SCREEN);51 page = await helpers.waitForPageToLoad(page);52 await page.evaluate(`$('[href="#layer-content"]').trigger('click')`);53 await page.evaluate(`$('[href="#collapseUHVibGljIGdyb3Vw"]').trigger('click')`);54 await helpers.sleep(1000);55 await page.evaluate(`$('[data-gc2-layer-key="public.test.the_geom"]').find('.js-toggle-load-strategy').trigger('click')`)56 await helpers.sleep(1000);57 let layerWasRequestedDynamically = false;58 await page.setRequestInterception(true);59 page.on('request', interceptedRequest => {60 if (interceptedRequest.url().indexOf(`api/sql/aleksandrshumilov`) !== -1) {61 if (Buffer.from(interceptedRequest._postData.split(`&`)[0].split(`=`)[1], 'base64').toString().indexOf(`ST_Transform(ST_MakeEnvelope`) !== -1) {62 layerWasRequestedDynamically = true;63 } else {64 layerWasRequestedDynamically = false;65 }66 }67 interceptedRequest.continue();68 });69 // Enable dynamic load70 await page.evaluate(`$('[data-gc2-layer-key="public.test.the_geom"]').find('.js-layer-settings-load-strategy').find('input').trigger('click')`);71 await helpers.sleep(2000);72 expect(layerWasRequestedDynamically).to.be.true;73 // Disable dynamic load74 await page.evaluate(`$('[data-gc2-layer-key="public.test.the_geom"]').find('.js-layer-settings-load-strategy').find('input').trigger('click')`);75 await helpers.sleep(2000);76 expect(layerWasRequestedDynamically).to.be.false;77 });78 it(`pulls layer data from cache if the vector is set to be offline, pulls data from server if it is not`, async () => {79 let page = await browser.newPage();80 await page.goto(helpers.PAGE_URL_DEFAULT + `v:public.test`);81 await page.emulate(helpers.EMULATED_SCREEN);82 page = await helpers.waitForPageToLoad(page);83 await page.evaluate(`$('[href="#layer-content"]').trigger('click')`);84 await page.evaluate(`$('[href="#collapseUHVibGljIGdyb3Vw"]').trigger('click')`);85 await helpers.sleep(8000);86 expect(await page.evaluate(`$('[data-gc2-layer-key="public.test.the_geom"]').find('.js-set-online').prop('disabled')`)).to.be.true;87 expect(await page.evaluate(`$('[data-gc2-layer-key="public.test.the_geom"]').find('.js-set-offline').prop('disabled')`)).to.be.false;88 await helpers.sleep(1000);89 await page.evaluate(`navigator.serviceWorker.addEventListener('message', event => {90 console.log('Service worker reports: ' + event.data.msg);91 });`);92 let requestWasServedFromSWCache = false;93 page.on('console', async (msg) => {94 if (msg.text().indexOf(`RESPONSE_CACHED_DUE_TO_OFFLINE_MODE_SETTINGS`) !== -1) {95 requestWasServedFromSWCache = true;96 }97 });98 await page.evaluate(`$('[data-gc2-layer-key="public.test.the_geom"]').find('.check').trigger('click')`);99 await helpers.sleep(1000);100 await page.evaluate(`$('[data-gc2-layer-key="public.test.the_geom"]').find('.check').trigger('click')`);101 await helpers.sleep(2000);102 expect(requestWasServedFromSWCache).to.be.false;103 requestWasServedFromSWCache = false;104 await page.evaluate(`$('[data-gc2-layer-key="public.test.the_geom"]').find('.js-set-offline').trigger('click')`);105 await helpers.sleep(3000);106 await page.evaluate(`$('[data-gc2-layer-key="public.test.the_geom"]').find('.check').trigger('click')`);107 await helpers.sleep(1000);108 await page.evaluate(`$('[data-gc2-layer-key="public.test.the_geom"]').find('.check').trigger('click')`);109 await helpers.sleep(2000);110 expect(requestWasServedFromSWCache).to.be.true;111 requestWasServedFromSWCache = false;112 await page.evaluate(`$('[data-gc2-layer-key="public.test.the_geom"]').find('.js-set-online').trigger('click')`);113 await helpers.sleep(3000);114 await page.evaluate(`$('[data-gc2-layer-key="public.test.the_geom"]').find('.check').trigger('click')`);115 await helpers.sleep(1000);116 await page.evaluate(`$('[data-gc2-layer-key="public.test.the_geom"]').find('.check').trigger('click')`);117 await helpers.sleep(2000);118 expect(requestWasServedFromSWCache).to.be.false;119 await page.close();120 });121 it(`uses Service worker API in order to control offline mode settings for layers`, async () => {122 let page = await browser.newPage();123 await page.goto(helpers.PAGE_URL_DEFAULT + `v:public.test`);124 await page.emulate(helpers.EMULATED_SCREEN);125 page = await helpers.waitForPageToLoad(page);126 await page.evaluate(`$('[href="#layer-content"]').trigger('click')`);127 await page.evaluate(`$('[href="#collapseUHVibGljIGdyb3Vw"]').trigger('click')`);128 await helpers.sleep(2000);129 const requestServiceWorkerAboutCachedLayers = () => {130 return new Promise((resolve, reject) => {131 var messageChannel = new MessageChannel();132 messageChannel.port1.onmessage = (event) => {133 resolve(JSON.stringify(event.data));134 };135 136 navigator.serviceWorker.controller.postMessage({ action: `getListOfCachedRequests` }, [messageChannel.port2]);137 });138 };139 let reply = JSON.parse(await page.evaluate(requestServiceWorkerAboutCachedLayers)).pop();140 await helpers.sleep(2000);141 expect(reply.layerKey).to.equal(`public.test`);142 expect(reply.offlineMode).to.equal(false);143 144 await page.evaluate(`$('[data-gc2-layer-key="public.test.the_geom"]').find('.js-set-offline').trigger('click')`);145 await helpers.sleep(3000);146 reply = JSON.parse(await page.evaluate(requestServiceWorkerAboutCachedLayers)).pop();147 await helpers.sleep(2000);148 expect(reply.layerKey).to.equal(`public.test`);149 expect(reply.offlineMode).to.equal(true);150 });151 it(`refreshes the vector layer in offline mode`, async () => {152 let page = await browser.newPage();153 await page.goto(helpers.PAGE_URL_DEFAULT + `v:public.test`);154 await page.emulate(helpers.EMULATED_SCREEN);155 page = await helpers.waitForPageToLoad(page);156 await page.evaluate(`$('[href="#layer-content"]').trigger('click')`);157 await page.evaluate(`$('[href="#collapseUHVibGljIGdyb3Vw"]').trigger('click')`);158 await helpers.sleep(2000);159 await page.evaluate(`$('[data-gc2-layer-key="public.test.the_geom"]').find('.js-set-offline').trigger('click')`);160 await helpers.sleep(3000);161 expect(await page.evaluate(`$('[data-gc2-layer-key="public.test.the_geom"]').find('.js-refresh').prop('disabled')`)).to.be.false;162 // Accepting dialog windows163 page.on('dialog', (dialog) => {164 dialog.accept();165 });166 let layerWasRequested = false;167 await page.setRequestInterception(true);168 page.on('request', interceptedRequest => {169 if (interceptedRequest.url().indexOf(`api/sql/aleksandrshumilov`) !== -1) {170 layerWasRequested = true;171 }172 interceptedRequest.continue();173 });174 await page.evaluate(`$('[data-gc2-layer-key="public.test.the_geom"]').find('.js-refresh').trigger('click')`);175 await helpers.sleep(3000);176 expect(layerWasRequested).to.equal(true);177 });178 it('should load layers from page URL from same schema', async () => {179 let page = await browser.newPage();180 await page.goto(`${helpers.PAGE_URL_EMBEDDED}v:public.test,public.test_poly`);181 page = await helpers.waitForPageToLoad(page);182 await page.click(`#burger-btn`);183 await helpers.sleep(1000);184 await page.evaluate(`$('[href="#collapseUHVibGljIGdyb3Vw"]').trigger('click')`);185 await helpers.sleep(1000);186 expect(await page.evaluate(`$('input[data-gc2-id="public.test"][class="js-show-layer-control"]').length`)).to.equal(1);187 expect(await page.evaluate(`$('input[data-gc2-id="public.test"][class="js-show-layer-control"]').is(':checked')`)).to.be.true;188 expect(await page.evaluate(`$('input[data-gc2-id="public.test_line"][class="js-show-layer-control"]').length`)).to.equal(1);189 expect(await page.evaluate(`$('input[data-gc2-id="public.test_line"][class="js-show-layer-control"]').is(':checked')`)).to.be.false;190 expect(await page.evaluate(`$('input[data-gc2-id="public.test_poly"][class="js-show-layer-control"]').length`)).to.equal(1);191 expect(await page.evaluate(`$('input[data-gc2-id="public.test_poly"][class="js-show-layer-control"]').is(':checked')`)).to.be.true;192 await page.close();193 });194 it('should load layers from page URL from different schemas', async () => {195 let page = await browser.newPage();196 await page.goto(`${helpers.PAGE_URL_EMBEDDED}test.polygon,public.urbanspatial_dar_es_salaam_luse_2002,public.test_poly,v:public.test,v:public.test_line`);197 page = await helpers.waitForPageToLoad(page);198 await page.click(`#burger-btn`);199 await helpers.sleep(1000);200 await page.evaluate(`$('[href="#collapseUHVibGljIGdyb3Vw"]').trigger('click')`);201 await helpers.sleep(1000);202 await page.evaluate(`$('[href="#collapseRGFyIGVzIFNhbGFhbSBMYW5kIFVzZSBhbmQgSW5mb3JtYWwgU2V0dGxlbWVudCBEYXRhIFNldA"]').trigger('click')`);203 await helpers.sleep(1000);204 await page.evaluate(`$('[data-gc2-subgroup-id="Urban spatial development 1"]').find('.js-subgroup-toggle-button').first().trigger('click')`);205 await helpers.sleep(1000);206 expect(await page.evaluate(`$('input[data-gc2-id="test.polygon"]').length`)).to.equal(1);207 expect(await page.evaluate(`$('input[data-gc2-id="test.polygon"]').is(':checked')`)).to.be.true;208 expect(await page.evaluate(`$('input[data-gc2-id="public.test"]').length`)).to.equal(1);209 expect(await page.evaluate(`$('input[data-gc2-id="public.test"]').is(':checked')`)).to.be.true;210 expect(await page.evaluate(`$('input[data-gc2-id="public.test_line"]').length`)).to.equal(1);211 expect(await page.evaluate(`$('input[data-gc2-id="public.test_line"]').is(':checked')`)).to.be.true;212 expect(await page.evaluate(`$('input[data-gc2-id="public.test_point_no_type"]').length`)).to.equal(1);213 expect(await page.evaluate(`$('input[data-gc2-id="public.test_point_no_type"]').is(':checked')`)).to.be.false;214 expect(await page.evaluate(`$('input[data-gc2-id="public.urbanspatial_dar_es_salaam_luse_2002"][class="js-show-layer-control"]').length`)).to.equal(1);215 expect(await page.evaluate(`$('input[data-gc2-id="public.urbanspatial_dar_es_salaam_luse_2002"][class="js-show-layer-control"]').is(':checked')`)).to.be.true;216 expect(await page.evaluate(`$('input[data-gc2-id="public.test_poly"][class="js-show-layer-control"]').length`)).to.equal(1);217 expect(await page.evaluate(`$('input[data-gc2-id="public.test_poly"][class="js-show-layer-control"]').is(':checked')`)).to.be.true;218 // Check if the panel for different schema was drawn as well219 expect(await page.evaluate(`$('#layers_list').find('.accordion-toggle').eq(0).text()`)).to.equal(`Test group`);220 expect(await page.evaluate(`$('#layers_list').find('.accordion-toggle').eq(1).text()`)).to.equal(`Dar es Salaam Land Use and Informal Settlement Data Set`);221 expect(await page.evaluate(`$('#layers_list').find('.accordion-toggle').eq(2).text()`)).to.equal(`Public group`);222 expect(await page.evaluate(`$('#layers_list').find('.accordion-toggle').eq(3).text()`)).to.equal(`Snapping`);223 expect(await page.evaluate(`$('#layers_list').find('.accordion-toggle').eq(4).text()`)).to.equal(`Dynamic load test`);224 await page.close();225 });226 it('should load vector and tile layers', async () => {227 let page = await browser.newPage();228 await page.goto(helpers.PAGE_URL_EMBEDDED);229 page = await helpers.waitForPageToLoad(page);230 await page.click(`#burger-btn`);231 await page.evaluate(`$('[href="#collapseUHVibGljIGdyb3Vw"]').trigger('click')`);232 await helpers.sleep(1000);233 await page._client.send('Network.enable');234 let apiWasRequested = false;235 await page._client.on('Network.requestWillBeSent', event => {236 if (event.request.url.indexOf(`/api/legend/aleksandrshumilov?l=v:public.test&db=aleksandrshumilov`) !== -1) {237 apiWasRequested = true;238 }239 });240 await page.evaluate(`$('[data-gc2-layer-key="public.test.the_geom"]').find('[type="checkbox"]').trigger('click')`);241 expect(await page.evaluate(`$('[data-gc2-layer-key="public.test.the_geom"]').find('[type="checkbox"]').prop('checked')`)).to.be.true;242 expect(apiWasRequested).to.be.true;243 await helpers.sleep(2000);244 let tilesWereRequested = false;245 await page._client.on('Network.requestWillBeSent', event => {246 if (event.request.url.indexOf(`service=WMS&request=GetMap&version=1.1.1&layers=public.test_poly`) !== -1) {247 tilesWereRequested = true;248 }249 });250 await page.evaluate(`$('[data-gc2-layer-key="public.test_poly.the_geom"]').find('[type="checkbox"]').trigger('click')`);251 await helpers.sleep(2000);252 expect(tilesWereRequested).to.be.true;253 await page.close();254 });255 it('should load vector layers', async () => {256 let page = await browser.newPage();257 await page.goto(helpers.PAGE_URL_EMBEDDED);258 page = await helpers.waitForPageToLoad(page);259 await page.click(`#burger-btn`);260 await page.evaluate(`$('[href="#collapseUHVibGljIGdyb3Vw"]').trigger('click')`);261 await helpers.sleep(1000);262 await page._client.send('Network.enable');263 let apiWasRequested = false;264 await page._client.on('Network.requestWillBeSent', event => {265 if (event.request.url.indexOf(`/api/legend/aleksandrshumilov?l=v:public.test_line&db=aleksandrshumilov`) !== -1) {266 apiWasRequested = true;267 }268 });269 await page.evaluate(`$('[data-gc2-layer-key="public.test_line.the_geom"]').find('.js-show-layer-control').trigger('click')`);270 expect(apiWasRequested).to.be.true;271 await page.close();272 });273 it('should load tile layers', async () => {274 let page = await browser.newPage();275 await page._client.send('Network.enable');276 let tilesWereRequested = false;277 await page._client.on('Network.requestWillBeSent', event => {278 if (event.request.url.indexOf(`service=WMS&request=GetMap&version=1.1.1&layers=public.test_poly`) !== -1) {279 tilesWereRequested = true;280 }281 });282 await page.goto(helpers.PAGE_URL_EMBEDDED);283 page = await helpers.waitForPageToLoad(page);284 await page.click(`#burger-btn`);285 await page.evaluate(`$('[href="#collapseUHVibGljIGdyb3Vw"]').trigger('click')`);286 await helpers.sleep(1000);287 await page.evaluate(`$('[data-gc2-layer-key="public.test_poly.the_geom"]').find('.check').trigger('click')`);288 expect(tilesWereRequested).to.be.true;289 await page.close();290 });291 it('should keep layer and layer group order', async () => {292 let page = await browser.newPage();293 await page.goto(helpers.PAGE_URL_EMBEDDED);294 await page.emulate(helpers.EMULATED_SCREEN);295 page = await helpers.waitForPageToLoad(page);296 await page.click(`#burger-btn`);297 await helpers.sleep(1000);298 expect(await page.evaluate(`$('#layer-slide').find('[data-toggle="collapse"]').eq(0).text()`)).to.equal(`Dar es Salaam Land Use and Informal Settlement Data Set`);299 expect(await page.evaluate(`$('#layer-slide').find('[data-toggle="collapse"]').eq(1).text()`)).to.equal(`Public group`);300 expect(await page.evaluate(`$('#layer-slide').find('[data-toggle="collapse"]').eq(2).text()`)).to.equal(`Snapping`);301 expect(await page.evaluate(`$('#layer-slide').find('[data-toggle="collapse"]').eq(3).text()`)).to.equal(`Dynamic load test`);302 let e = await page.$('#layer-panel-UHVibGljIGdyb3Vw .layer-move-vert');303 let box = await e.boundingBox();304 let x = box.x + box.width / 2;305 let y = box.y + box.height / 2;306 await page.mouse.move(x, y);307 await page.mouse.down();308 await page.mouse.move(x, y + 50);309 await helpers.sleep(100);310 await page.mouse.move(x, y + 55);311 await page.mouse.move(x, y + 50);312 await page.mouse.move(x, y + 55);313 await page.mouse.move(x, y + 50);314 await page.mouse.up();315 await page.mouse.click(1, 1);316 await helpers.sleep(1000);317 await page.reload();318 page = await helpers.waitForPageToLoad(page);319 await helpers.sleep(1000);320 expect(await page.evaluate(`$('#layer-slide').find('[data-toggle="collapse"]').eq(0).text()`)).to.equal(`Dar es Salaam Land Use and Informal Settlement Data Set`);321 expect(await page.evaluate(`$('#layer-slide').find('[data-toggle="collapse"]').eq(1).text()`)).to.equal(`Snapping`);322 expect(await page.evaluate(`$('#layer-slide').find('[data-toggle="collapse"]').eq(2).text()`)).to.equal(`Public group`);323 expect(await page.evaluate(`$('#layer-slide').find('[data-toggle="collapse"]').eq(3).text()`)).to.equal(`Dynamic load test`);324 await page.close();325 });...

Full Screen

Full Screen

end.test.js

Source:end.test.js Github

copy

Full Screen

...8 await test('.subscribe', async ({ plan, same }) => {9 plan(4)10 const { ripple, page } = await startup()11 ripple('foo', 'bar')12 same('bar', await page.evaluate(d => ($ = ripple.subscribe('foo'))))13 same(1, keys(ripple.server.ws.sockets[0].subscriptions).length)14 await page.evaluate(d => Promise.all($.source.emit('stop')))15 await delay(1100)16 same(0, keys(ripple.server.ws.sockets[0].subscriptions).length)17 same(str({ undefined: undefined }), await page.evaluate(d => JSON.stringify(ripple.subscriptions.foo)))18 page.close()19 })2021 // TODO: this can be re-enabled after async-await performance issue resolved in critical path22 // .load can wait till resource loaded, if not loadable23 // await test('.subscribe before resource exists', async ({ plan, same }) => {24 // plan(4)25 // const { ripple, page } = await startup()26 // await page.evaluate(d => { $ = ripple.subscribe('foo').map(d => (console.log("d", d), d)) })27 // ripple('foo', 'bar')28 // same('bar', await page.evaluate(d => $))29 // same(1, keys(ripple.server.ws.sockets[0].subscriptions).length)30 // await page.evaluate(d => Promise.all($.source.emit('stop')))31 // await delay(1100)32 // same(str({ undefined: undefined }), await page.evaluate(d => JSON.stringify(ripple.subscriptions.foo)))33 // same(0, keys(ripple.server.ws.sockets[0].subscriptions).length)34 // page.close()35 // })3637 await test('.subscribe on single key', async ({ plan, same }) => {38 plan(3)39 const { ripple, page } = await startup() 40 ripple('foo', { bar: 'boo' })41 await page.evaluate(d => { results = ripple.subscribe('foo', 'bar')42 .reduce((acc = [], d) => acc.concat(d))43 .filter(d => d.length == 2)44 })45 46 update('xxx', 'xxx')(ripple('foo'))47 update('bar', 'baz')(ripple('foo'))48 same(['boo', 'baz'], await page.evaluate(d => results))4950 await page.evaluate(d => Promise.all(results.source.emit('stop')))51 await delay(1100)5253 same(str({ bar: undefined }), await page.evaluate(d => JSON.stringify(ripple.subscriptions.foo)))54 same(0, keys(ripple.server.ws.sockets[0].subscriptions).length)5556 page.close()57 })5859 await test('.subscribe on multiple keys', async ({ plan, same }) => {60 plan(4)61 const { ripple, page } = await startup()62 63 ripple('foo', { bar: 'bar', baz: { baz: 'baz' }, bee: 'bee' })64 await page.evaluate(d => {65 clone = d => JSON.parse(JSON.stringify(d))66 $ = ripple67 .subscribe('foo', ['bar', 'baz'])68 .reduce((acc = [], d) => acc.concat(clone(d)))69 70 results = $.filter(d => d.length == 3)71 return $.filter(d => d.length == 1)72 })7374 update('xxx', 'xxx')(ripple('foo'))75 update('bar', 'boo')(ripple('foo'))76 update('baz.bil', 'bil')(ripple('foo'))7778 same([79 { bar: 'bar', baz: { baz: 'baz' }}80 , { bar: 'boo', baz: { baz: 'baz' }}81 , { bar: 'boo', baz: { baz: 'baz', bil: 'bil' }}82 ], await page.evaluate(d => results))8384 same(2, keys(ripple.server.ws.sockets[0].subscriptions).length)85 await page.evaluate(d => Promise.all(results.source.emit('stop')))86 await delay(1100)87 same(str({ bar: undefined, baz: undefined }), await page.evaluate(d => JSON.stringify(ripple.subscriptions.foo)))88 same(0, keys(ripple.server.ws.sockets[0].subscriptions).length)8990 page.close()91 })9293 await test('.get', async ({ plan, same }) => {94 plan(4)95 const { ripple, page } = await startup()96 97 ripple('foo', { bar: 'bar' })98 same('bar', await page.evaluate(d => ripple.get('foo', 'bar')), 'fetch single value')99 100 update('bar', 'boo')(ripple('foo'))101 same('boo', await page.evaluate(d => ripple.get('foo', 'bar')), 'fetch cached value')102103 await delay(1100)104 same(0, keys(ripple.server.ws.sockets[0].subscriptions).length, 'no subscriptions (server)')105 same(str({ bar: undefined }), await page.evaluate(d => JSON.stringify(ripple.subscriptions.foo)), 'no subscriptions (client)')106107 page.close()108 })109110 await test('.get on multiple keys', async ({ plan, same }) => {111 plan(3)112 const { ripple, page } = await startup()113 114 ripple('foo', { bar: 'bar', baz: 'baz', boo: 'boo' })115 same({ bar: 'bar', baz: 'baz' }, await page.evaluate(d => ripple.get('foo', ['bar', 'baz'])), 'fetch single value')116117 await delay(1100)118 same(0, keys(ripple.server.ws.sockets[0].subscriptions).length, 'no subscriptions (server)')119 same(str({ bar: undefined, baz: undefined }), await page.evaluate(d => JSON.stringify(ripple.subscriptions.foo)), 'no subscriptions (client)')120121 page.close()122 })123124 await test('.upload', async ({ plan, same, notOk }) => {125 plan(5)126 const { ripple, page } = await startup()127 , sink = () => {128 const out = { result: '' }129 out.stream = new Writable({ 130 write(data, enc, next){ 131 out.result += data132 next()133 }134 })135 return out136 }137 , pipe = input => new Promise(resolve => {138 const out = sink()139 input.pipe(out.stream.on('finish', d => resolve(out.result)))140 })141 , from = req => {142 same(req.data.value.fname, 'fname')143 return Promise.all([144 ...req.data.value.files1145 , ...req.data.value.files2146 ].map(pipe))147 .then(results => {148 same(7000, results.join('').length, 'piped results')149 return 'ack'150 })151 }152 , results = [153 { type: 'progress'154 , value: {155 total: 7000156 , received: 1000157 }158 }159 , { type: 'progress'160 , value: {161 total: 7000162 , received: 2024163 }164 }165 , { type: 'progress'166 , value: {167 total: 7000168 , received: 3000169 }170 }171 , { type: 'progress'172 , value: {173 total: 7000174 , received: 4024175 }176 }177 , { type: 'progress'178 , value: {179 total: 7000180 , received: 5048181 }182 }183 , { type: 'progress'184 , value: {185 total: 7000186 , received: 6072187 }188 }189 , { type: 'progress'190 , value: {191 total: 7000192 , received: 7000193 }194 }195 , { type: 'complete'196 , value: 'ack'197 }198 ]199200 ripple('foo', {}, { from })201 same(results, await page.evaluate(d => {202 const results = []203 , createFileList = arr => (arr.__proto__ = FileList.prototype, arr)204 , form = {205 fname: 'fname'206 , files1: createFileList([207 new File([Array(1000).fill(1).join('')], '', { name: 'file1' })208 ])209 , files2: createFileList([210 new File([Array(2000).fill(2).join('')], '', { name: 'file2' })211 , new File([Array(4000).fill(3).join('')], '', { name: 'file3' })212 ])213 }214215 return ripple216 .upload('foo', form)217 .on('progress', d => results.push({ type: 'progress', value: d }))218 .map(d => (results.push({ type: 'complete', value: d }), results))219 }), 'upload form')220221 notOk(await page.evaluate(d => ripple.subscriptions.foo), 'no subscriptions (client)')222 same(0, keys(ripple.server.ws.sockets[0].subscriptions).length, 'no subscriptions (server)')223 page.close()224 })225226 // TODO: move this to fullstack 227 // await test('.render (+ hot reload)', async ({ plan, same }) => {228 // plan(2)229 // const { ripple, page } = await startup()230 // , received = emitterify()231232 // // capture messages233 // ripple('test', {}, { from: d => received.emit('drawn', d.data) })234235 // // first version of component236 // ripple('x-foo', node => ripple.send('test', 'DRAW', node.innerHTML = 1))237238 // await page.evaluate(d => {239 // foo = document.createElement('x-foo')240 // document.body.appendChild(foo)241 // return ripple.draw(foo)242 // })243 244 // // first component rendered245 // same({ name: 'test', type: 'DRAW', value: '1' }, await received.once('drawn'), 'initial load')246247 // // register new version248 // ripple('x-foo', node => ripple.send('test', 'DRAW', node.innerHTML = 2))249250 // // second component rendereds251 // same({ name: 'test', type: 'DRAW', value: '2' }, await received.once('drawn'), 'hot reload')252253 // page.close()254 // })255256 await test('strip server headers', async ({ plan, same }) => {257 plan(4)258 const { ripple, page } = await startup()259 , received = emitterify()260261 // capture messages262 ripple({ 263 name: 'test'264 , body: {}265 , headers: { 266 from: d => false267 , transpile: 'transpile'268 , valid: d => d269 , loaded: (a, b) => { 270 same(a, ripple)271 same(b.name, 'test')272 }273 }274 })275276 const test = await page.evaluate(async d => {277 await ripple.get('test')278 return { 279 headers: Object.keys(ripple.resources.test.headers)280 , valid: typeof ripple.resources.test.headers.valid281 }282 })283 284 same(test.headers, ['valid', 'content-type'], 'headers stripped')285 same(test.valid, 'function', 'function headers valid')286287 page.close()288 })289290 await test('auto dynamically transpile functions', async ({ plan, same }) => {291 plan(7)292 const { ripple, page } = await startup()293294 ripple('arrow', d => d)295 same(keys(ripple.caches).length, 0, 'empty cache')296297 const transpiled = await page.evaluate(async d => ('' + await ripple.get('arrow')))298 same(keys(ripple.caches), ['arrow'], 'one cache')299 same(ripple.caches.arrow.size, 1, 'one transpilation')300301 await page.setUserAgent('Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36')302 await page.reload()303304 const untranspiled = await page.evaluate(async d => ('' + await ripple.get('arrow')))305 same(ripple.caches.arrow.size, 2, 'two transpilations')306 same(untranspiled, 'd => d', 'untranspiled')307 same(transpiled, 'function (d) { return d; }', 'transpiled')308 309 await page.close()310311 ripple('arrow', d => false)312 same(keys(ripple.caches).length, 0, 'clear transpilation caches on reload')313 })314315 await test('dynamically transpile objects with functions (opt in) + hot updates', async ({ plan, same }) => {316 plan(1)317 const { ripple, page } = await startup()318319 await page.setUserAgent('Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; AS; rv:11.0) like Gecko')320 await page.reload()321 ripple('arrow', { fn: d => true }, { transpile: { limit: 1 }})322 323 await page.evaluate(d => { 324 $ = ripple325 .subscribe('arrow', 'fn')326 .reduce((acc = [], d) => acc.concat('' +d))327 328 results = $.filter(d => d.length == 2)329 return $330 })331 update('fn', d => false)(ripple('arrow'))332333 same(await page.evaluate(d => results), [334 'function (d) { return true; }'335 , 'function (d) { return false; }'336 ], 'transpiled versions')337338 page.close()339 })340341 await test('allow subscribing using numbers as keys', async ({ plan, same }) => {342 plan(2)343 const { ripple, page } = await startup()344 ripple('object', { 10: 20, 30: 40 })345 same(await page.evaluate(d => ripple.get('object', 10)), 20, 'number key')346 same(await page.evaluate(d => ripple('object')), { 10: 20 }, 'number key update cache')347 page.close()348 })349350 await test('.subscribe + .get on same sub-resource', async ({ plan, same }) => {351 plan(3)352 const { ripple, page } = await startup()353 , bar = 'bar'354 , boo = 'boo'355356 ripple('foo', { bar, boo })357 same({ bar, boo }, await page.evaluate(d => ripple.subscribe('foo')), 'subscribe')358 same('bar', await page.evaluate(d => ripple.get('foo', 'bar')), 'get key')359 same({ bar, boo }, await page.evaluate(d => ripple('foo')), 'full resource still available')360361 page.close()362 })363364 await test('push dependencies', async ({ plan, same }) => {365 plan(1)366 const { ripple, page } = await startup()367 368 ripple('foo', () => ripple('boo'), { dependencies: { 'bar': 'boo' }})369 ripple('boo', 'boo')370 same(371 'boo'372 , await page.evaluate(async d => (await ripple.get('foo'))())373 , 'boo should have been preloaded with foo'374 )375376 page.close()377 })378379 process.exit(0)380381 async function startup(){382 const core = require('rijs.core')383 , data = require('rijs.data')384 , fn = require('rijs.fn')385 , ripple = require('./')(loader(fn(data(core()))), { port: 0 })386 ...

Full Screen

Full Screen

category.test.js

Source:category.test.js Github

copy

Full Screen

...46 const jsHandle = await page.evaluateHandle(() => {47 const element = document.querySelector('.category-box');48 return element.childNodes;49 });50 const ACTUAL_COUNT = await page.evaluate(e => e.length, jsHandle);51 const EXPECTED_COUNT = 3;52 expect(ACTUAL_COUNT).toBe(EXPECTED_COUNT);53 });54});55describe('Display categories', () => {56 it('test 4: Name of category correctly displayed', async () => {57 // https://stackoverflow.com/questions/48146973/puppeteer-how-to-use-page-evaluatehandle58 const jsHandle = await page.evaluateHandle(() => {59 const element = document.querySelector('.category-box');60 // select second entry61 const newCat = element.childNodes[1];62 return newCat.shadowRoot.querySelector(".title");63 });64 const ACTUAL_TITLE = await page.evaluate(e => e.innerHTML, jsHandle);65 const EXPECTED_TITLE = "";66 expect(ACTUAL_TITLE).toBe(EXPECTED_TITLE);67 });68 69 it('test 5: Category displays proper color', async () => {70 /*71 const jsHandle = await page.evaluateHandle(() => {72 const element = document.querySelector('.category-box');73 // select second entry74 const newCat = element.childNodes[1];75 return newCat.shadowRoot.querySelector("#color");76 });77 const ACTUAL_COLOR = await page.evaluate(e => e.selectedIndex, jsHandle);78 const EXPECTED_COLOR = 1;79 expect(ACTUAL_COLOR).toBe(EXPECTED_COLOR);80 */81 });82});83describe('Selecting categories', () => {84 it('test 6: Selected categories show in Focus', async () => {85 // click the box86 const checkBtn = await page.evaluateHandle(`document.querySelector("body > main > div > div.cell.cell-5 > div > div.category-box > category-entry:nth-child(2)").shadowRoot.querySelector("#category-check")`);87 await checkBtn.click();88 // check the box89 const jsHandle = await page.evaluateHandle(() => {90 const element = document.querySelector('.category-box');91 // select second entry92 const newCat = element.childNodes[1];93 return newCat.shadowRoot.querySelector(".checkbox");94 });95 /*96 // can't actually check for psuedo selectors so just pass97 const ACTUAL_COLOR = await page.evaluate(e => e.selectedIndex, jsHandle);98 const EXPECTED_COLOR = 1;99 expect(ACTUAL_COLOR).toBe(EXPECTED_COLOR);100 */101 });102 it('test 7: Select all button functions appropriately', async () => {103 const selectAllBtn = await page.evaluateHandle(`document.querySelector("#select-all")`);104 await selectAllBtn.click();105 // focuses mostly on triggering global errors from clicking, can't check functionality106 // because there's no way to check changes in .css styling in puppeteer107 });108 it('test 8: Deselect all button functions appropriately', async () => {109 const deselectAllBtn = await page.evaluateHandle(`document.querySelector("#deselect-all")`) ;110 await deselectAllBtn.click();111 // focuses mostly on triggering global errors from clicking, can't check functionality112 // because there's no way to check changes in .css styling in puppeteer113 });114});115describe('Category storage', () => {116 it('test 9: Categories persist after refresh', async () => {117 /**118 * https://stackoverflow.com/questions/55877263/puppeteer-execution-context-was-destroyed-most-likely-because-of-a-navigation119 * 120 * Can't use `page.reload() and check elements. Would destroy local variables121 * 122 * Solution: use a second page. Since it uses localStorage, this will make 123 * elements persist across multiple instances124 */125 await page.goto('https://cse110-sp21-group32.github.io/cse110-sp21-group32/');126 await page.waitForTimeout(500);127 128 const category = await page.evaluateHandle(`document.querySelector("body > main > div > div.cell.cell-5 > div > div.category-box > category-entry:nth-child(2)").shadowRoot.querySelector("#category-title")`);129 const ACTUAL_TITLE = await page.evaluate(e => e.innerHTML, category);130 const EXPECTED_TITLE = "";131 expect(ACTUAL_TITLE).toBe(EXPECTED_TITLE);132 });133});134describe('Deleting categories', () => {135 it('test 10: Deleted category disappears from right side list', async () => {136 const cateDelBtn = await page.evaluateHandle(`document.querySelector("body > main > div > div.cell.cell-5 > div > div.category-box > category-entry:nth-child(2)").shadowRoot.querySelector("#cate-delete")`);137 await cateDelBtn.click();138 /**139 * https://stackoverflow.com/questions/46042613/how-to-test-the-type-of-a-thrown-exception-in-jest#:~:text=In%20Jest%20you%20have%20to,or%20type%20of%20error%3E)%20.&text=If%20you%20need%20to%20test,anonymous%20function%20in%20expect()%20.140 * 141 * two ways to implement142 * 143 * 1. check size of childnode144 * 2. expect error when select second child145 * 146 */147 // Method 1148 const jsHandle = await page.evaluateHandle(() => {149 const element = document.querySelector('.category-box');150 // select second entry151 return element.childElementCount;152 });153 const ACTUAL_COUNT = await page.evaluate(e => e, jsHandle);154 const EXPECTED_COUNT = 2;155 expect(ACTUAL_COUNT).toBe(EXPECTED_COUNT);156 /*157 // Method 2158 const test = () => {159 await cateDelBtn.click();160 };161 expect(test).toThrow(new Error);162 163 */164 });165 /*166 // writing this test out because it should be handled in a separate file where167 // interactions between categories and bullets should happen168 it('test 11: Bullets of a deleted category revert to Default', async () => {169 170 });171 */172});173describe('Editing categories', () => {174/**175 * Editing text fields is a funky thing. We can either hard reset the value176 * or we could try emulating actual keypresses177 * 178 * https://stackoverflow.com/questions/52631057/how-to-delete-existing-text-from-input-using-puppeteer179 */180/*181 it('dummy test to set up for test 11', async () => {182 // opens add menu 183 const addCategory = await page.evaluateHandle(`document.querySelector("#add-cate-button")`);184 await addCategory.click();185 186 // data into both fields187 const nameField = await page.evaluateHandle(`document.querySelector("body > cate-editor-page").shadowRoot.querySelector("#name")`);188 await nameField.focus();189 await page.keyboard.type("cat");190 // accepts data191 const confirmBtn = await page.evaluateHandle(`document.querySelector("body > cate-editor-page").shadowRoot.querySelector("#cate-submit")`);192 await confirmBtn.click();193 194 }, 30000);195 it('test 11: Category edit button opens menu and allows editing', async() => {196 197 // selects title field and renames198 const editBtn = await page.evaluateHandle(`document.querySelector("body > main > div > div.cell.cell-5 > div > div.category-box > category-entry:nth-child(2)").shadowRoot.querySelector("#cate-edit")`);199 await editBtn.click();200 const titleField = await page.evaluateHandle(`document.querySelector("body > cate-editor-page").shadowRoot.querySelector("#name")`);201 await titleField.focus();202 await titleField.click({ clickCount: 3});203 await page.keyboard.type("new cat");204 205 const colField = await page.evaluateHandle(`document.querySelector("body > cate-editor-page").shadowRoot.querySelector("#color")`);206 await colField.focus();207 await page.keyboard.press("ArrowDown");208 await page.keyboard.press("Enter");209 // accepts changes210 const confirmBtn = await page.evaluateHandle(`document.querySelector("body > cate-editor-page").shadowRoot.querySelector("#cate-submit")`);211 await confirmBtn.click();212 // read title value213 const jsHandle = await page.evaluateHandle(() => {214 const element = document.querySelector('.category-box');215 // select second entry216 const newCat = element.childNodes[1];217 return newCat.shadowRoot.querySelector(".title");218 });219 const ACTUAL_TITLE = await page.evaluate(e => e.innerHTML, jsHandle);220 const EXPECTED_TITLE = "new cat";221 expect(ACTUAL_TITLE).toBe(EXPECTED_TITLE);222 }, 30000);223 224 it('test 12: Category with edited title changes title', async () => {225 const jsHandle = await page.evaluateHandle(() => {226 const element = document.querySelector('.category-box');227 // select second entry228 const newCat = element.childNodes[1];229 return newCat.shadowRoot.querySelector(".title");230 });231 const ACTUAL_TITLE = await page.evaluate(e => e.innerHTML, jsHandle);232 const EXPECTED_TITLE = "new cat";233 expect(ACTUAL_TITLE).toBe(EXPECTED_TITLE);234 });235 */236 237 it('test 11: Category with edited color changes color', async() => {238 // Change color239 const colorField = await page.evaluateHandle(`document.querySelector("body > main > div > div.cell.cell-5 > div > div.category-box > category-entry:nth-child(2)").shadowRoot.querySelector("#color")`);240 await colorField.focus();241 await page.keyboard.press("ArrowDown");242 // Check and return color243 const jsHandle = await page.evaluateHandle(() => {244 const element = document.querySelector('.category-box');245 // select second entry246 const newCat = element.childNodes[1];247 return newCat.shadowRoot.querySelector("#color");248 });249 const ACTUAL_COLOR = await page.evaluate(e => e.selectedIndex, jsHandle);250 const EXPECTED_COLOR = 0;251 expect(ACTUAL_COLOR).toBe(EXPECTED_COLOR);252 });...

Full Screen

Full Screen

jshandle.spec.js

Source:jshandle.spec.js Github

copy

Full Screen

...30 });31 it('should accept object handle as an argument', async () => {32 const { page } = getTestState();33 const navigatorHandle = await page.evaluateHandle(() => navigator);34 const text = await page.evaluate((e) => e.userAgent, navigatorHandle);35 expect(text).toContain('Mozilla');36 });37 it('should accept object handle to primitive types', async () => {38 const { page } = getTestState();39 const aHandle = await page.evaluateHandle(() => 5);40 const isFive = await page.evaluate((e) => Object.is(e, 5), aHandle);41 expect(isFive).toBeTruthy();42 });43 it('should warn on nested object handles', async () => {44 const { page } = getTestState();45 const aHandle = await page.evaluateHandle(() => document.body);46 let error = null;47 await page48 .evaluateHandle((opts) => opts.elem.querySelector('p'), {49 elem: aHandle,50 })51 .catch((error_) => (error = error_));52 expect(error.message).toContain('Are you passing a nested JSHandle?');53 });54 it('should accept object handle to unserializable value', async () => {55 const { page } = getTestState();56 const aHandle = await page.evaluateHandle(() => Infinity);57 expect(await page.evaluate((e) => Object.is(e, Infinity), aHandle)).toBe(58 true59 );60 });61 it('should use the same JS wrappers', async () => {62 const { page } = getTestState();63 const aHandle = await page.evaluateHandle(() => {64 window.FOO = 123;65 return window;66 });67 expect(await page.evaluate((e) => e.FOO, aHandle)).toBe(123);68 });69 it('should work with primitives', async () => {70 const { page } = getTestState();71 const aHandle = await page.evaluateHandle(() => {72 window.FOO = 123;73 return window;74 });75 expect(await page.evaluate((e) => e.FOO, aHandle)).toBe(123);76 });77 });78 describe('JSHandle.getProperty', function () {79 it('should work', async () => {80 const { page } = getTestState();81 const aHandle = await page.evaluateHandle(() => ({82 one: 1,83 two: 2,84 three: 3,85 }));86 const twoHandle = await aHandle.getProperty('two');87 expect(await twoHandle.jsonValue()).toEqual(2);88 });89 });90 describe('JSHandle.jsonValue', function () {91 it('should work', async () => {92 const { page } = getTestState();93 const aHandle = await page.evaluateHandle(() => ({ foo: 'bar' }));94 const json = await aHandle.jsonValue();95 expect(json).toEqual({ foo: 'bar' });96 });97 it('should not work with dates', async () => {98 const { page } = getTestState();99 const dateHandle = await page.evaluateHandle(100 () => new Date('2017-09-26T00:00:00.000Z')101 );102 const json = await dateHandle.jsonValue();103 expect(json).toEqual({});104 });105 it('should throw for circular objects', async () => {106 const { page, isChrome } = getTestState();107 const windowHandle = await page.evaluateHandle('window');108 let error = null;109 await windowHandle.jsonValue().catch((error_) => (error = error_));110 if (isChrome)111 expect(error.message).toContain('Object reference chain is too long');112 else expect(error.message).toContain('Object is not serializable');113 });114 });115 describe('JSHandle.getProperties', function () {116 it('should work', async () => {117 const { page } = getTestState();118 const aHandle = await page.evaluateHandle(() => ({119 foo: 'bar',120 }));121 const properties = await aHandle.getProperties();122 const foo = properties.get('foo');123 expect(foo).toBeTruthy();124 expect(await foo.jsonValue()).toBe('bar');125 });126 it('should return even non-own properties', async () => {127 const { page } = getTestState();128 const aHandle = await page.evaluateHandle(() => {129 class A {130 constructor() {131 this.a = '1';132 }133 }134 class B extends A {135 constructor() {136 super();137 this.b = '2';138 }139 }140 return new B();141 });142 const properties = await aHandle.getProperties();143 expect(await properties.get('a').jsonValue()).toBe('1');144 expect(await properties.get('b').jsonValue()).toBe('2');145 });146 });147 describe('JSHandle.asElement', function () {148 it('should work', async () => {149 const { page } = getTestState();150 const aHandle = await page.evaluateHandle(() => document.body);151 const element = aHandle.asElement();152 expect(element).toBeTruthy();153 });154 it('should return null for non-elements', async () => {155 const { page } = getTestState();156 const aHandle = await page.evaluateHandle(() => 2);157 const element = aHandle.asElement();158 expect(element).toBeFalsy();159 });160 it('should return ElementHandle for TextNodes', async () => {161 const { page } = getTestState();162 await page.setContent('<div>ee!</div>');163 const aHandle = await page.evaluateHandle(164 () => document.querySelector('div').firstChild165 );166 const element = aHandle.asElement();167 expect(element).toBeTruthy();168 expect(169 await page.evaluate(170 (e) => e.nodeType === HTMLElement.TEXT_NODE,171 element172 )173 );174 });175 it('should work with nullified Node', async () => {176 const { page } = getTestState();177 await page.setContent('<section>test</section>');178 await page.evaluate(() => delete Node);179 const handle = await page.evaluateHandle(() =>180 document.querySelector('section')181 );182 const element = handle.asElement();183 expect(element).not.toBe(null);184 });185 });186 describe('JSHandle.toString', function () {187 it('should work for primitives', async () => {188 const { page } = getTestState();189 const numberHandle = await page.evaluateHandle(() => 2);190 expect(numberHandle.toString()).toBe('JSHandle:2');191 const stringHandle = await page.evaluateHandle(() => 'a');192 expect(stringHandle.toString()).toBe('JSHandle:a');...

Full Screen

Full Screen

alfacart.com.js

Source:alfacart.com.js Github

copy

Full Screen

...24 else req.continue();25 }); */26 27 await page.goto(body[2], { waitUntil: "networkidle0", timeout: 0 });28 const page_exist = await page.evaluate(() => document.querySelector("#__layout > div > div:nth-child(2) > main > div > div:nth-child(2) > div.col-sm-9 > div > div > h3"));29 log(33, page_exist);30 if(_.isNull(page_exist)) {31 await browser.close();32 return null;33 }34 const title = await page.evaluate(() => document.querySelector("#__layout > div > div:nth-child(2) > main > div > div:nth-child(2) > div.col-sm-9 > div > div > h3").innerText);35 const alert_exist = await page.evaluate(() => document.querySelector("#__layout > div > div:nth-child(2) > main > div > div:nth-child(2) > div.col-sm-9 > div > div > div:nth-child(5) > div.col-sm-7.pl-60 > div:nth-child(1) > div > div.alert"));36 log(36, alert_exist);37 if(!_.isNil(alert_exist)) await page.evaluate(() => document.querySelector("#__layout > div > div:nth-child(2) > main > div > div:nth-child(2) > div.col-sm-9 > div > div > div:nth-child(5) > div.col-sm-7.pl-60 > div:nth-child(1)").remove());38 let short_desc = await page.evaluate(() => document.querySelector("#__layout > div > div:nth-child(2) > main > div > div:nth-child(2) > div.col-sm-9 > div > div > div:nth-child(5) > div.col-sm-7.pl-60 > div:nth-child(1) > div.col-sm-9.pl-0 > div").innerHTML);39 short_desc = _.replace(short_desc, /\n/g, '<br />');40 short_desc = _.replace(short_desc, /\r/g, '<br />');41 short_desc = _.replace(short_desc, /"/g, '\'');42 log(39, await page.evaluate(() => document.querySelector("#deskripsi")));43 let long_desc = await page.evaluate(() => document.querySelector("#deskripsi").innerText);44 long_desc = _.replace(long_desc, /\n/g, '\\n'); //\u202845 long_desc = _.replace(long_desc, /\r/g, '\\r'); //\u202946 long_desc = _.replace(long_desc, /"/g, '\'');47 log(42, await page.evaluate(() => document.querySelector("#__layout > div > div:nth-child(2) > main > div > div:nth-child(2) > div.col-sm-9 > div > div > div:nth-child(5) > div.col-sm-7.pl-60 > div:nth-child(3) > div.col-sm-9.pl-0 > p.fprice")));48 const regular_price_exist = await page.evaluate(() => document.querySelector("#__layout > div > div:nth-child(2) > main > div > div:nth-child(2) > div.col-sm-9 > div > div > div:nth-child(5) > div.col-sm-7.pl-60 > div:nth-child(3) > div.col-sm-9.pl-0 > p.fprice"));49 let regular_price;50 if(!_.isNil(regular_price_exist)) {51 log(47, await page.evaluate(() => document.querySelector("#__layout > div > div:nth-child(2) > main > div > div:nth-child(2) > div.col-sm-9 > div > div > div:nth-child(5) > div.col-sm-7.pl-60 > div:nth-child(3) > div.col-sm-9.pl-0 > p.fprice")));52 regular_price = await page.evaluate(() => document.querySelector("#__layout > div > div:nth-child(2) > main > div > div:nth-child(2) > div.col-sm-9 > div > div > div:nth-child(5) > div.col-sm-7.pl-60 > div:nth-child(3) > div.col-sm-9.pl-0 > p.fprice").innerText);53 54 if(_.isEmpty(regular_price)) regular_price = undefined;55 else {56 regular_price = _.replace(regular_price, 'Rp', '');57 regular_price = _.replace(regular_price, 'IDR', '');58 regular_price = _.replace(regular_price, /\./g, '');59 regular_price = _.replace(regular_price, /\,/g, '');60 regular_price = _.replace(regular_price, /\s/g, '');61 regular_price = _.toNumber(regular_price);62 }63 }64 log(61, await page.evaluate(() => document.querySelector("#__layout > div > div:nth-child(2) > main > div > div:nth-child(2) > div.col-sm-9 > div > div > div:nth-child(5) > div.col-sm-7.pl-60 > div:nth-child(3) > div.col-sm-9.pl-0 > p.tprice")));65 let sale_price = await page.evaluate(() => document.querySelector("#__layout > div > div:nth-child(2) > main > div > div:nth-child(2) > div.col-sm-9 > div > div > div:nth-child(5) > div.col-sm-7.pl-60 > div:nth-child(3) > div.col-sm-9.pl-0 > p.tprice").innerText);66 sale_price = _.replace(sale_price, 'Rp', '');67 sale_price = _.replace(sale_price, 'IDR', '');68 sale_price = _.replace(sale_price, /\./g, '');69 sale_price = _.replace(sale_price, /\,/g, '');70 sale_price = _.replace(sale_price, /\s/g, '');71 sale_price = _.toNumber(sale_price);72 await page.click("#slick0 > div > div > div > div > div > div > img");73 const images_exist = await page.evaluate(() => document.querySelector("#blueimp-gallery > div"));74 log(72, images_exist);75 let images;76 if(!_.isNil(images_exist)) {77 const total_images = await page.evaluate(() => document.querySelector("#blueimp-gallery > div").childElementCount);78 for (let index = 1; index <= total_images; index++) {79 const image_exist = await page.evaluate(num => document.querySelector(`#blueimp-gallery > div > div:nth-child(${num}) > img`), index);80 log(76, image_exist);81 if(_.isNil(image_exist)) continue;82 83 if(_.eq(index, 1)) images = await page.evaluate(num => document.querySelector(`#blueimp-gallery > div > div:nth-child(${num}) > img`).src, index);84 else images += ', ' + await page.evaluate(num => document.querySelector(`#blueimp-gallery > div > div:nth-child(${num}) > img`).src, index);85 }86 }87 await browser.close();88 return [89 body[0],"simple",,title,1,0,"visible",short_desc,long_desc,,,"taxable",,1,,,0,0,0,,,,1,,_.isNil(regular_price) ? undefined : sale_price,_.isNil(regular_price) ? sale_price : regular_price,body[1],,,images,,,,,,,,,090 ]91 } catch (err) {92 log(err)93 await browser.close();94 return null;95 }96 })()...

Full Screen

Full Screen

auto.js

Source:auto.js Github

copy

Full Screen

...23 page.click("#createWebAccountLinkCapva")24 ]);25 await Promise.all([26 page.waitForNavigation(),27 page.evaluate(() => {28 document.querySelector('input[id="privacyOptInAcceptanceCheckBox"]').click()29 }),30 page.evaluate(() => {31 document.querySelector("body > div:nth-child(20) > div.ui-dialog-buttonpane.ui-widget-content.ui-helper-clearfix > div > button:nth-child(1)").click()32 }),33 page.evaluate(() => {34 document.querySelector('input[id="candidateIdOptions:2"]').click()35 }),36 page.evaluate((fname) => {37 document.querySelector('input[id="fname"]').value = fname38 }, fname),39 page.evaluate((lname) => {40 document.querySelector('input[id="lname"]').value = lname;41 }, lname),42 page.evaluate((dob) => {43 document.querySelector('select[id="editPersonalInformationGridDATE_OF_BIRTH.day"]').value = dob[0];44 }, dob),45 page.evaluate((dob) => {46 document.querySelector('select[id="editPersonalInformationGridDATE_OF_BIRTH.month"]').value = dob[1];47 }, dob),48 page.evaluate((dob) => {49 document.querySelector('select[id="editPersonalInformationGridDATE_OF_BIRTH.year"]').value = dob[2];50 }, dob),51 page.evaluate((g) => {52 const evl = 'input[id="editPersonalInformationGridGENDER:' + g + '"]';53 document.querySelector(evl).click();54 }, g),55 page.evaluate((nin) => {56 document.querySelector('input[id="personalConfigNinonino1"]').value = nin[0] + nin[1];57 }, nin),58 page.evaluate((nin) => {59 document.querySelector('input[id="personalConfigNinonino2"]').value = nin[2] + nin[3];60 }, nin),61 page.evaluate((nin) => {62 document.querySelector('input[id="personalConfigNinonino3"]').value = nin[4] + nin[5];63 }, nin),64 page.evaluate((nin) => {65 document.querySelector('input[id="personalConfigNinonino4"]').value = nin[6] + nin[7];66 }, nin),67 page.evaluate((nin) => {68 document.querySelector('input[id="personalConfigNinonino5"]').value = nin[8];69 }, nin),70 page.evaluate((nin) => {71 document.querySelector('input[id="inputNinonino1"]').value = nin[0] + nin[1];72 }, nin),73 page.evaluate((nin) => {74 document.querySelector('input[id="inputNinonino2"]').value = nin[2] + nin[3];75 }, nin),76 page.evaluate((nin) => {77 document.querySelector('input[id="inputNinonino3"]').value = nin[4] + nin[5];78 }, nin),79 page.evaluate((nin) => {80 document.querySelector('input[id="inputNinonino4"]').value = nin[6] + nin[7];81 }, nin),82 page.evaluate((nin) => {83 document.querySelector('input[id="inputNinonino5"]').value = nin[8];84 }, nin),85 page.evaluate((email) => {86 document.querySelector('input[id="editEmailPanelGroupEMAIL"]').value = email;87 }, email),88 page.evaluate((email) => {89 document.querySelector('input[id="confirmEmail"]').value = email;90 }, email),91 page.evaluate(() => {92 document.querySelector('input[id="nextButton"]').click()93 }),94 ]);95 await Promise.all([96 page.waitForNavigation(),97 page.evaluate((address) => {98 document.querySelector("#editPrimary_editAddressGridADDRESS1").value = address99 }, address),100 page.evaluate((town) => {101 document.querySelector("#editPrimary_editAddressGridCITY").value = town102 }, town),103 page.evaluate((post) => {104 document.querySelector("#editPrimary_editAddressGridPOSTAL_CODE").value = post105 }, post),106 page.evaluate(() => {107 document.querySelector("#editPrimary_editAddressGridTELEPHONE").value = "8989898989"108 }),109 page.evaluate(() => {110 document.querySelector("#CORRESPONDENCE_CONFIRMATION_737\\:0").click()111 }),112 page.evaluate(() => {113 document.querySelector("#CORRESPONDENCE_REMINDER_737\\:2").click()114 }),115 page.evaluate(() => {116 document.querySelector("#nextButton").click()117 }),118 ]);119 await Promise.all([120 page.waitForNavigation(),121 page.evaluate(() => {122 document.querySelector('input[id="component1_SELECT_ONE_RADIOBUTTON_3657:1"]').click()123 }),124 page.evaluate(() => {125 document.querySelector('input[id="nextButton"]').click()126 })127 ]);128 await Promise.all([129 page.waitForNavigation(),130 page.evaluate((userID) => {131 document.querySelector('input[id="inputUsername"]').value = userID;132 }, userID),133 page.evaluate(() => {134 document.querySelector('input[id="inputPassword"]').value = "#1Acsscitb";135 }),136 page.evaluate(() => {137 document.querySelector('input[id="inputConfirmPassword"]').value = "#1Acsscitb";138 }),139 page.evaluate(() => {140 document.querySelector('select[id="inputSecurityQuestionOne"]').value = 202;141 }),142 page.evaluate(() => {143 document.querySelector('input[id="inputAnswerOne"]').value = "none";144 }),145 page.evaluate(() => {146 document.querySelector('select[id="inputSecurityQuestionTwo"]').value = 211;147 }),148 page.evaluate(() => {149 document.querySelector('input[id="inputAnswerTwo"]').value = "none";150 }),151 page.evaluate(() => {152 document.querySelector('select[id="inputSecurityQuestionThree"]').value = 219;153 }),154 page.evaluate(() => {155 document.querySelector('input[id="inputAnswerThree"]').value = "none";156 }),157 page.evaluate(() => {158 document.querySelector('input[id="nextButton"]').click();159 }),160 ]);161 res.send("Done");162 163 })();164})...

Full Screen

Full Screen

mirotakampus.com.js

Source:mirotakampus.com.js Github

copy

Full Screen

...24 else req.continue();25 }); */26 27 await page.goto(body[2], { waitUntil: "networkidle0", timeout: 0 });28 const page_exist = await page.evaluate(() => document.querySelector("#content > section > div > div > div.col-md-9.pull-right > div > div > div.product > div > div.col-md-7 > h5"));29 log(33, page_exist);30 if(_.isNull(page_exist)) {31 await browser.close();32 return null;33 }34 const title = await page.evaluate(() => document.querySelector("#content > section > div > div > div.col-md-9.pull-right > div > div > div.product > div > div.col-md-7 > h5").innerText);35 log(35, await page.evaluate(() => document.querySelector("#content > section > div > div > div.col-md-9.pull-right > div > div > div.product > div > div.col-md-7 > div.col-md-12 > div > div > div")));36 let short_desc = await page.evaluate(() => document.querySelector("#content > section > div > div > div.col-md-9.pull-right > div > div > div.product > div > div.col-md-7 > div.col-md-12 > div > div > div").innerText);37 short_desc = _.replace(short_desc, /\n/g, ' '); //\u202838 short_desc = _.replace(short_desc, /\r/g, ' '); //\u202939 short_desc = _.replace(short_desc, /"/g, '\'');40 log(39, await page.evaluate(() => document.querySelector("#pro-detil")));41 let long_desc = await page.evaluate(() => document.querySelector("#pro-detil").innerText);42 long_desc = _.replace(long_desc, /\n/g, '\\n'); //\u202843 long_desc = _.replace(long_desc, /\r/g, '\\r'); //\u202944 long_desc = _.replace(long_desc, /"/g, '\'');45 log(42, await page.evaluate(() => document.querySelector("#content > section > div > div > div.col-md-9.pull-right > div > div > div.product > div > div.col-md-7 > div.row > div:nth-child(1) > span > span")));46 const regular_price_exist = await page.evaluate(() => document.querySelector("#content > section > div > div > div.col-md-9.pull-right > div > div > div.product > div > div.col-md-7 > div.row > div:nth-child(1) > span > span"));47 let regular_price;48 if(!_.isNil(regular_price_exist)) {49 log(47, await page.evaluate(() => document.querySelector("#content > section > div > div > div.col-md-9.pull-right > div > div > div.product > div > div.col-md-7 > div.row > div:nth-child(1) > span > span")));50 regular_price = await page.evaluate(() => document.querySelector("#content > section > div > div > div.col-md-9.pull-right > div > div > div.product > div > div.col-md-7 > div.row > div:nth-child(1) > span > span").innerText);51 52 if(_.isEmpty(regular_price)) regular_price = undefined;53 else {54 regular_price = _.replace(regular_price, 'Rp', '');55 regular_price = _.replace(regular_price, 'IDR', '');56 regular_price = _.replace(regular_price, /\./g, '');57 regular_price = _.replace(regular_price, /\,/g, '');58 regular_price = _.replace(regular_price, /\s/g, '');59 regular_price = _.toNumber(regular_price);60 }61 }62 const images_exist = await page.evaluate(() => document.querySelector("#lightgallery"));63 log(72, images_exist);64 let images;65 if(!_.isNil(images_exist)) {66 const total_images = await page.evaluate(() => document.querySelector("#lightgallery").childElementCount);67 for (let index = 1; index <= total_images; index++) {68 const image_exist = await page.evaluate(num => document.querySelector(`#lightgallery > li:nth-child(${num}) > div > div > div > img`), index);69 log(76, image_exist);70 if(_.isNil(image_exist)) continue;71 72 if(_.eq(index, 1)) images = await page.evaluate(num => document.querySelector(`#lightgallery > li:nth-child(${num}) > div > div > div > img`).src, index);73 else images += ', ' + await page.evaluate(num => document.querySelector(`#lightgallery > li:nth-child(${num}) > div > div > div > img`).src, index);74 }75 }76 await browser.close();77 return [78 body[0],"simple",,title,1,0,"visible",short_desc,long_desc,,,"taxable",,1,,,0,0,0,,,,1,,undefined,regular_price,body[1],,,images,,,,,,,,,079 ]80 } catch (err) {81 log(err)82 await browser.close();83 return null;84 }85 })()...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { launch } = require('qawolf');2const selectors = require('./selectors/test.json');3describe('test', () => {4 let browser;5 let page;6 beforeAll(async () => {7 browser = await launch();8 page = await browser.newPage();9 });10 afterAll(async () => {11 await browser.close();12 });13 it('test', a

Full Screen

Using AI Code Generation

copy

Full Screen

1const { launch } = require("qawolf");2const selectors = require("../selectors/test.json");3describe("test", () => {4 let browser;5 let page;6 beforeAll(async () => {7 browser = await launch();8 page = await browser.newPage();9 });10 afterAll(async () => {11 await browser.close();12 });13 it("test", async () => {

Full Screen

Using AI Code Generation

copy

Full Screen

1const { launch, devices } = require('qawolf');2const iPhone = devices['iPhone 11 Pro'];3(async () => {4 const page = await browser.newPage();5 await page.type('[name="q"]', 'hello world');6 await page.click('[name="btnK"]');7 await page.waitForSelector('h3');8 await browser.close();9})();

Full Screen

Using AI Code Generation

copy

Full Screen

1await page.evaluate(() => {2 const [button] = qawolf.selectors.find('button');3 button.click();4});5await page.evaluate(() => {6 const [button] = qawolf.selectors.find('button');7 button.click();8});9await page.evaluate(() => {10 const [button] = qawolf.selectors.find('button');11 button.click();12});13await page.evaluate(() => {14 const [button] = qawolf.selectors.find('button');15 button.click();16});17await page.evaluate(() => {18 const [button] = qawolf.selectors.find('button');19 button.click();20});21await page.evaluate(() => {22 const [button] = qawolf.selectors.find('button');23 button.click();24});25await page.evaluate(() => {26 const [button] = qawolf.selectors.find('button');27 button.click();28});29await page.evaluate(() => {30 const [button] = qawolf.selectors.find('button');31 button.click();32});33await page.evaluate(() => {34 const [button] = qawolf.selectors.find('button');35 button.click();36});37await page.evaluate(() => {

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run qawolf automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful