Best JavaScript code snippet using chromeless
job_spec.js
Source:job_spec.js
...9 const JOB_URL = `${gl.TEST_HOST}/frontend-fixtures/builds-project/-/jobs/1`;10 let mock;11 let response;12 let job;13 function waitForPromise() {14 return new Promise(resolve => requestAnimationFrame(resolve));15 }16 preloadFixtures('builds/build-with-artifacts.html.raw');17 beforeEach(() => {18 loadFixtures('builds/build-with-artifacts.html.raw');19 spyOnDependency(Job, 'visitUrl');20 response = {};21 mock = new MockAdapter(axios);22 mock.onGet(new RegExp(`${JOB_URL}/trace.json?(.*)`)).reply(() => [200, response]);23 });24 afterEach(() => {25 mock.restore();26 clearTimeout(job.timeout);27 });28 describe('class constructor', () => {29 beforeEach(() => {30 jasmine.clock().install();31 });32 afterEach(() => {33 jasmine.clock().uninstall();34 });35 describe('setup', () => {36 beforeEach(function (done) {37 job = new Job();38 waitForPromise()39 .then(done)40 .catch(done.fail);41 });42 it('copies build options', function () {43 expect(job.pagePath).toBe(JOB_URL);44 expect(job.buildStatus).toBe('success');45 expect(job.buildStage).toBe('test');46 expect(job.state).toBe('');47 });48 it('only shows the jobs matching the current stage', () => {49 expect($('.build-job[data-stage="build"]').is(':visible')).toBe(false);50 expect($('.build-job[data-stage="test"]').is(':visible')).toBe(true);51 expect($('.build-job[data-stage="deploy"]').is(':visible')).toBe(false);52 });53 it('selects the current stage in the build dropdown menu', () => {54 expect($('.stage-selection').text()).toBe('test');55 });56 it('updates the jobs when the build dropdown changes', () => {57 $('.stage-item:contains("build")').click();58 expect($('.stage-selection').text()).toBe('build');59 expect($('.build-job[data-stage="build"]').is(':visible')).toBe(true);60 expect($('.build-job[data-stage="test"]').is(':visible')).toBe(false);61 expect($('.build-job[data-stage="deploy"]').is(':visible')).toBe(false);62 });63 });64 describe('running build', () => {65 it('updates the build trace on an interval', function (done) {66 response = {67 html: '<span>Update<span>',68 status: 'running',69 state: 'newstate',70 append: true,71 complete: false,72 };73 job = new Job();74 waitForPromise()75 .then(() => {76 expect($('#build-trace .js-build-output').text()).toMatch(/Update/);77 expect(job.state).toBe('newstate');78 response = {79 html: '<span>More</span>',80 status: 'running',81 state: 'finalstate',82 append: true,83 complete: true,84 };85 })86 .then(() => jasmine.clock().tick(4001))87 .then(waitForPromise)88 .then(() => {89 expect($('#build-trace .js-build-output').text()).toMatch(/UpdateMore/);90 expect(job.state).toBe('finalstate');91 })92 .then(done)93 .catch(done.fail);94 });95 it('replaces the entire build trace', (done) => {96 response = {97 html: '<span>Update<span>',98 status: 'running',99 append: false,100 complete: false,101 };102 job = new Job();103 waitForPromise()104 .then(() => {105 expect($('#build-trace .js-build-output').text()).toMatch(/Update/);106 response = {107 html: '<span>Different</span>',108 status: 'running',109 append: false,110 };111 })112 .then(() => jasmine.clock().tick(4001))113 .then(waitForPromise)114 .then(() => {115 expect($('#build-trace .js-build-output').text()).not.toMatch(/Update/);116 expect($('#build-trace .js-build-output').text()).toMatch(/Different/);117 })118 .then(done)119 .catch(done.fail);120 });121 });122 describe('truncated information', () => {123 describe('when size is less than total', () => {124 it('shows information about truncated log', (done) => {125 response = {126 html: '<span>Update</span>',127 status: 'success',128 append: false,129 size: 50,130 total: 100,131 };132 job = new Job();133 waitForPromise()134 .then(() => {135 expect(document.querySelector('.js-truncated-info').classList).not.toContain('hidden');136 })137 .then(done)138 .catch(done.fail);139 });140 it('shows the size in KiB', (done) => {141 const size = 50;142 response = {143 html: '<span>Update</span>',144 status: 'success',145 append: false,146 size,147 total: 100,148 };149 job = new Job();150 waitForPromise()151 .then(() => {152 expect(153 document.querySelector('.js-truncated-info-size').textContent.trim(),154 ).toEqual(`${numberToHumanSize(size)}`);155 })156 .then(done)157 .catch(done.fail);158 });159 it('shows incremented size', (done) => {160 response = {161 html: '<span>Update</span>',162 status: 'success',163 append: false,164 size: 50,165 total: 100,166 complete: false,167 };168 job = new Job();169 waitForPromise()170 .then(() => {171 expect(172 document.querySelector('.js-truncated-info-size').textContent.trim(),173 ).toEqual(`${numberToHumanSize(50)}`);174 response = {175 html: '<span>Update</span>',176 status: 'success',177 append: true,178 size: 10,179 total: 100,180 complete: true,181 };182 })183 .then(() => jasmine.clock().tick(4001))184 .then(waitForPromise)185 .then(() => {186 expect(187 document.querySelector('.js-truncated-info-size').textContent.trim(),188 ).toEqual(`${numberToHumanSize(60)}`);189 })190 .then(done)191 .catch(done.fail);192 });193 it('renders the raw link', () => {194 response = {195 html: '<span>Update</span>',196 status: 'success',197 append: false,198 size: 50,199 total: 100,200 };201 job = new Job();202 expect(203 document.querySelector('.js-raw-link').textContent.trim(),204 ).toContain('Complete Raw');205 });206 });207 describe('when size is equal than total', () => {208 it('does not show the trunctated information', (done) => {209 response = {210 html: '<span>Update</span>',211 status: 'success',212 append: false,213 size: 100,214 total: 100,215 };216 job = new Job();217 waitForPromise()218 .then(() => {219 expect(document.querySelector('.js-truncated-info').classList).toContain('hidden');220 })221 .then(done)222 .catch(done.fail);223 });224 });225 });226 describe('output trace', () => {227 beforeEach((done) => {228 response = {229 html: '<span>Update</span>',230 status: 'success',231 append: false,232 size: 50,233 total: 100,234 };235 job = new Job();236 waitForPromise()237 .then(done)238 .catch(done.fail);239 });240 it('should render trace controls', () => {241 const controllers = document.querySelector('.controllers');242 expect(controllers.querySelector('.js-raw-link-controller')).not.toBeNull();243 expect(controllers.querySelector('.js-scroll-up')).not.toBeNull();244 expect(controllers.querySelector('.js-scroll-down')).not.toBeNull();245 });246 it('should render received output', () => {247 expect(248 document.querySelector('.js-build-output').innerHTML,249 ).toEqual('<span>Update</span>');250 });...
test_async_in_batchmode.js
Source:test_async_in_batchmode.js
...4// As seen in bug 1197856 and bug 1190131.5Cu.import("resource://gre/modules/PlacesUtils.jsm");6// This function "waits" for a promise to resolve by spinning a nested event7// loop.8function waitForPromise(promise) {9 let thread = Cc["@mozilla.org/thread-manager;1"].getService().currentThread;10 let finalResult, finalException;11 promise.then(result => {12 finalResult = result;13 }, err => {14 finalException = err;15 });16 // Keep waiting until our callback is triggered (unless the app is quitting).17 while (!finalResult && !finalException) {18 thread.processNextEvent(true);19 }20 if (finalException) {21 throw finalException;22 }23 return finalResult;24}25add_test(function() {26 let testCompleted = false;27 PlacesUtils.bookmarks.runInBatchMode({28 runBatched() {29 // create a bookmark.30 let info = { parentGuid: PlacesUtils.bookmarks.unfiledGuid,31 type: PlacesUtils.bookmarks.TYPE_BOOKMARK,32 url: "http://example.com/" };33 let insertPromise = PlacesUtils.bookmarks.insert(info);34 let bookmark = waitForPromise(insertPromise);35 // Check we got a bookmark (bookmark creation failed completely in36 // bug 1190131)37 equal(bookmark.url, info.url);38 // Check the promiseItemGuid and promiseItemId helpers - failure in these39 // was the underlying reason for the failure.40 let id = waitForPromise(PlacesUtils.promiseItemId(bookmark.guid));41 let guid = waitForPromise(PlacesUtils.promiseItemGuid(id));42 equal(guid, bookmark.guid, "id and guid round-tripped correctly");43 testCompleted = true;44 }45 }, null);46 // make sure we tested what we think we tested.47 ok(testCompleted);48 run_next_test();...
Using AI Code Generation
1const Chromeless = require('chromeless').Chromeless2async function run() {3 const chromeless = new Chromeless()4 .type('chromeless', 'input[name="q"]')5 .press(13)6 .wait('#resultStats')7 .screenshot()8 await chromeless.end()9}10run().catch(console.error.bind(console))11const Chromeless = require('chromeless').Chromeless12async function run() {13 const chromeless = new Chromeless()14 .type('chromeless', 'input[name="q"]')15 .press(13)16 .wait('#resultStats')17 .screenshot()18 await chromeless.end()19}20run().catch(console.error.bind(console))
Using AI Code Generation
1const { Chromeless } = require('chromeless')2async function run() {3 const chromeless = new Chromeless()4 .type('chromeless', 'input[name="q"]')5 .click('input[value="Google Search"]')6 .wait('#resultStats')7 .screenshot()8 await chromeless.end()9}10run().catch(console.error.bind(console))11const { Chromeless } = require('chromeless')12async function run() {13 const chromeless = new Chromeless()14 .type('chromeless', 'input[name="q"]')15 .click('input[value="Google Search"]')16 .waitForPromise(() => {17 return new Promise((resolve, reject) => {18 setTimeout(() => {19 resolve(true)20 }, 1000)21 })22 })23 .screenshot()24 await chromeless.end()25}26run().catch(console.error.bind(console))27const { Chromeless } = require('chromeless')28async function run() {29 const chromeless = new Chromeless()30 .type('chromeless', 'input[name="q"]')31 .click('input[value="Google Search"]')32 .waitForPromise(() => {33 return new Promise((resolve, reject) => {34 setTimeout(() => {35 resolve(false)36 }, 1000)37 })38 })39 .screenshot()40 await chromeless.end()41}42run().catch(console.error.bind(console))43const { Chromeless } = require('chromeless')44async function run() {45 const chromeless = new Chromeless()46 .type('chromeless', 'input[name="
Using AI Code Generation
1const chromeless = new Chromeless()2 .type('chromeless', 'input[name="q"]')3 .press(13)4 .wait('#resultStats')5 .screenshot()6await chromeless.end()7const chromeless = new Chromeless()8 .type('chromeless', 'input[name="q"]')9 .press(13)10 .wait('#resultStats')11 .screenshot()12await chromeless.end()13const chromeless = new Chromeless()14 .type('chromeless', 'input[name="q"]')15 .press(13)16 .wait('#resultStats')17 .screenshot()18await chromeless.end()19const chromeless = new Chromeless()20 .type('chromeless', 'input[name="q"]')21 .press(13)22 .wait('#resultStats')23 .screenshot()24await chromeless.end()25const chromeless = new Chromeless()26 .type('chromeless', 'input[name="q"]')27 .press(13)28 .wait('#resultStats')29 .screenshot()30await chromeless.end()31const chromeless = new Chromeless()
Using AI Code Generation
1const chromeless = new Chromeless()2 .type('chromeless', 'input[name="q"]')3 .press(13)4 .wait('#resultStats')5 .evaluate(() => {6 })7 .end()
Using AI Code Generation
1const Chromeless = require('chromeless').Chromeless2const chromeless = new Chromeless()3 .goto(url)4 .type('chromeless', 'input[name="q"]')5 .press(13)6 .wait('#resultStats')7 .evaluate(() => {8 })9 .then(title => {10 console.log('Title is:', title)11 })12 .catch(e => {13 console.log('error:', e)14 })15 .then(() => chromeless.end())16const Chromeless = require('chromeless').Chromeless17const chromeless = new Chromeless()18 .goto(url)19 .type('chromeless', 'input[name="q"]')20 .press(13)21 .wait('#resultStats')22 .evaluate(() => {23 })24 .then(title => {25 console.log('Title is:', title)26 })27 .catch(e => {28 console.log('error:', e)29 })30 .then(() => chromeless.end())31const Chromeless = require('chromeless').Chromeless32const chromeless = new Chromeless()33 .goto(url)34 .type('chromeless', 'input[name="q"]')35 .press(13)36 .wait('#resultStats')37 .evaluate(() => {38 })39 .then(title => {40 console.log('Title is:', title)41 })42 .catch(e => {43 console.log('error:', e)44 })45 .then(() => chromeless.end())46const Chromeless = require('chromeless').Chromeless47const chromeless = new Chromeless()48 .goto(url)49 .type('chromeless', 'input[name="q"]')50 .press(13)51 .wait('#resultStats')52 .evaluate(() => {53 })54 .then(title => {
Using AI Code Generation
1const Chromeless = require('chromeless').Chromeless2const fs = require('fs')3const chromeless = new Chromeless({4 viewport: { width: 1920, height: 1080, scale: 1 },5})6async function run() {7 .type('chromeless', 'input[name="q"]')8 .click('input[name="btnK"]')9 .wait('#resultStats')10 .screenshot()11 await chromeless.end()12}13run().catch(console.error.bind(console))14const Chromeless = require('chromeless').Chromeless15const fs = require('fs')16const chromeless = new Chromeless({17 viewport: { width: 1920, height: 1080, scale: 1 },18})19async function run() {20 .type('chromeless', 'input[name="q"]')21 .click('input[name="btnK"]')22 .waitFor(() => {23 const resultStats = document.querySelector('#resultStats')24 })25 .screenshot()26 await chromeless.end()27}28run().catch(console.error.bind(console))
Using AI Code Generation
1const Chromeless = require('chromeless').Chromeless2const chromeless = new Chromeless()3const waitForPromise = require('chromeless/dist/waitForPromise')4const run = async () => {5 .type('chromeless', 'input[name="q"]')6 .click('input[name="btnK"]')7 .wait('div.g')8 .evaluate(() => document.title)9 .then(title => waitForPromise(Promise.resolve(title)))10 .catch(err => waitForPromise(Promise.reject(err)))11 .screenshot()12 await chromeless.end()13}14run().catch(console.error.bind(console))15const Chromeless = require('chromeless').Chromeless16const chromeless = new Chromeless()17const waitForPromise = require('chromeless/dist/waitForPromise')18const run = async () => {19 .type('chromeless', 'input[name="q"]')20 .click('input[name="btnK"]')21 .wait('div.g')22 .evaluate(() => document.title)23 .then(title => waitForPromise(Promise.resolve(title)))24 .catch(err => waitForPromise(Promise.reject(err)))25 .screenshot()26 await chromeless.end()27}28run().catch(console.error.bind(console))29const Chromeless = require('chromeless').Chromeless30const chromeless = new Chromeless()31const waitForPromise = require('chromeless/dist/waitForPromise')32const run = async () => {33 .type('chromeless', 'input[name="q"]')34 .click('input[name="btnK"]')35 .wait('div.g')36 .evaluate(() => document.title)37 .then(title => waitForPromise(Promise.resolve(title)))38 .catch(err => waitForPromise(Promise.reject(err)))39 .screenshot()40 await chromeless.end()41}42run().catch(console.error.bind(console))
Using AI Code Generation
1const Chromeless = require('chromeless').Chromeless2async function run() {3 const chromeless = new Chromeless()4 .type('chromeless', 'input[name="q"]')5 .press(13)6 .waitForPromise(() => {7 return new Promise((resolve, reject) => {8 setTimeout(() => {9 resolve('promise resolved after 2 seconds')10 }, 2000)11 })12 })13 .screenshot()14 await chromeless.end()15}16run().catch(console.error.bind(console))17const Chromeless = require('chromeless').Chromeless18async function run() {19 const chromeless = new Chromeless()20 .type('chromeless', 'input[name="q"]')21 .press(13)22 .waitForPromise(() => {23 return new Promise((resolve, reject) => {24 setTimeout(() => {25 reject('promise rejected after 2 seconds')26 }, 2000)27 })28 })29 .screenshot()30 await chromeless.end()31}32run().catch(console.error.bind(console))33const Chromeless = require('chromeless').Chromeless34async function run() {35 const chromeless = new Chromeless()36 .type('chromeless', 'input[name="q"]')37 .press(13)38 .waitForPromise(() => {39 return new Promise((resolve, reject) => {40 setTimeout(() => {41 resolve('promise resolved after 2 seconds')42 }, 2000)43 })44 })45 .screenshot()
Using AI Code Generation
1const chromeless = new Chromeless({ launchChrome: false });2const text = "Hello World!";3const selector = '#hplogo';4 .goto(url)5 .type(text, 'input[name="q"]')6 .press(13)7 .wait(selector)8 .screenshot();9await chromeless.end();10const chromeless = new Chromeless({ launchChrome: false });11const text = "Hello World!";12const selector = '#hplogo';13 .goto(url)14 .type(text, 'input[name="q"]')15 .press(13)16 .waitForPromise(() => {17 return new Promise(resolve => {18 setTimeout(() => {19 resolve(true);20 }, 1000);21 });22 })23 .screenshot();24await chromeless.end();25const chromeless = new Chromeless({ launchChrome: false });26const text = "Hello World!";27const selector = '#hplogo';28 .goto(url)29 .type(text, 'input[name="q"]')30 .press(13)31 .waitForPromise(() => {32 return new Promise(resolve => {33 setTimeout(() => {34 resolve(true);35 }, 1000);36 });37 })38 .screenshot();39await chromeless.end();40const chromeless = new Chromeless({ launchChrome: false });41const text = "Hello World!";42const selector = '#hplogo';43 .goto(url)44 .type(text, 'input[name="q"]')45 .press(13)46 .waitForPromise(() => {47 return new Promise(resolve => {48 setTimeout(() => {49 resolve(true);50 }, 1000);51 });52 })
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!