Best JavaScript code snippet using wpt
user-details.test.js
Source:user-details.test.js
...47 await Page.revokeAuthentication();48 });49 beforeEach(async () => {50 await UserDetailsPage.load(tempUsers[0].email);51 await UserDetailsPage.waitForLoad();52 });53 it("can view others users' details", async () => {54 await UserDetailsPage.load(tempUsers[0].email);55 await UserDetailsPage.waitForLoad();56 57 await UserDetailsPage.load(tempUsers[1].email);58 await UserDetailsPage.waitForLoad();59 60 await UserDetailsPage.load(tempUsers[2].email);61 await UserDetailsPage.waitForLoad();62 });63 64 it("can view others users' details by selecting them from the list of users", async () => {65 await UserDetailsPage.load(Zebedee.getTempAdminUserEmail());66 await UserDetailsPage.waitForLoad();67 const waitForNavigation = page.waitForNavigation();68 await UsersPage.selectUser(tempUsers[1].email);69 await waitForNavigation;70 expect(await UserDetailsPage.currentPath()).toBe(`/florence/users/${tempUsers[1].email}`);71 await expectPuppeteer(page).toMatchElement(userDetailsSelectors.userName, {text: tempUsers[1].name});72 await expectPuppeteer(page).toMatchElement(userDetailsSelectors.userEmail, {text: tempUsers[1].email});73 });74 it("can view whether a user has a temporary password", async () => {75 await UserDetailsPage.load(tempUsers[3].email);76 await UserDetailsPage.waitForLoad();77 expect(await UserDetailsPage.tempPasswordTextIsVisible()).toBe(true);78 });79 80 it("isn't shown a message when a user doesn't have a temporary password", async () => {81 await UserDetailsPage.load(tempUsers[2].email);82 await UserDetailsPage.waitForLoad();83 expect(await UserDetailsPage.tempPasswordTextIsVisible()).toBe(false);84 });85 it("'change password' action shows for user's own details", async () => {86 await UserDetailsPage.load(Zebedee.getTempAdminUserEmail());87 await UserDetailsPage.waitForLoad();88 expect(await UserDetailsPage.userActionsBarIsVisible()).toBe(true);89 expect(await UserDetailsPage.changePasswordButtonIsVisible()).toBe(true);90 });91 it("'change password' action shows other user's details", async () => {92 expect(await UserDetailsPage.userActionsBarIsVisible()).toBe(true);93 expect(await UserDetailsPage.changePasswordButtonIsVisible()).toBe(true);94 });95 it("'change password' action takes users to the change password screen", async () => {96 await expectPuppeteer(page).toClick(userDetailsSelectors.changePasswordButton);97 await ChangeUsersPasswordPage.waitForLoad();98 expect(await UserDetailsPage.currentPath()).toBe(`/florence/users/${tempUsers[0].email}/change-password`);99 });100 it("'delete' action shows for all user's details", async () => {101 expect(await UserDetailsPage.userActionsBarIsVisible()).toBe(true);102 expect(await UserDetailsPage.deleteUserButtonIsVisible()).toBe(true);103 });104 it("'delete' action takes user to delete confirmation screen", async () => {105 await expectPuppeteer(page).toClick(userDetailsSelectors.deleteUserButton);106 await ConfirmDeleteUserPage.waitForLoad();107 expect(await UserDetailsPage.currentPath()).toBe(`/florence/users/${tempUsers[0].email}/confirm-delete`);108 });109 it("'close' action shows for all user's details", async () => {110 expect(await UserDetailsPage.closeUserButtonIsVisible()).toBe(true);111 });112 it("'close' action takes user to users screen", async () => {113 const waitForNavigation = page.waitForNavigation();114 await expectPuppeteer(page).toClick('.drawer__footer button', {text: "Close"});115 await waitForNavigation;116 expect(await UserDetailsPage.currentPath()).toBe(`/florence/users`);117 expect(await UserDetailsPage.isVisible()).toBe(false);118 });119});120describe("Non-admin users", () => {121 beforeAll(async () => {122 await Page.revokeAuthentication();123 await Page.loginAsPublisher();124 });125 it("can view others users' details from a direct route", async () => {126 await UserDetailsPage.load(tempUsers[0].email);127 await UserDetailsPage.waitForLoad();128 expect(await UserDetailsPage.userActionsBarIsVisible()).toBe(false);129 expect(await UserDetailsPage.currentPath()).toBe(`/florence/users/${tempUsers[0].email}`);130 });131 132 it("can view another users' details by selecting them from the list of users", async () => {133 await UserDetailsPage.load(Zebedee.getTempPublisherUserEmail());134 await UserDetailsPage.waitForLoad();135 await expectPuppeteer(page).toMatchElement(userDetailsSelectors.userName, {text: Zebedee.getTempPublisherUserEmail()});136 await expectPuppeteer(page).toMatchElement(userDetailsSelectors.userEmail, {text: Zebedee.getTempPublisherUserEmail()});137 const waitForNavigation = page.waitForNavigation();138 await UsersPage.selectUser(tempUsers[1].email);139 await waitForNavigation;140 expect(await UserDetailsPage.currentPath()).toBe(`/florence/users/${tempUsers[1].email}`);141 await expectPuppeteer(page).toMatchElement(userDetailsSelectors.userName, {text: tempUsers[1].name});142 await expectPuppeteer(page).toMatchElement(userDetailsSelectors.userEmail, {text: tempUsers[1].email});143 });144 it("can view user's name", async () => {145 await UserDetailsPage.load(tempUsers[0].email);146 await UserDetailsPage.waitForLoad();147 expect(await UserDetailsPage.getUsersName()).toBe(tempUsers[0].name);148 });149 it("can view user's email address", async () => {150 await UserDetailsPage.load(tempUsers[0].email);151 await UserDetailsPage.waitForLoad();152 expect(await UserDetailsPage.getUsersEmail()).toBe(tempUsers[0].email);153 });154 it("can view a user's role", async () => {155 await UserDetailsPage.load(tempUsers[0].email);156 await UserDetailsPage.waitForLoad();157 expect(await UserDetailsPage.getUsersRole()).toBe(`${tempUsers[0].name} is an admin`);158 159 await UserDetailsPage.load(tempUsers[1].email);160 await UserDetailsPage.waitForLoad();161 expect(await UserDetailsPage.getUsersRole()).toBe(`${tempUsers[1].name} is a publisher`);162 163 await UserDetailsPage.load(tempUsers[2].email);164 await UserDetailsPage.waitForLoad();165 expect(await UserDetailsPage.getUsersRole()).toBe(`${tempUsers[2].name} is a viewer`);166 });167 168 it("can view whether a user has a temporary password", async () => {169 await UserDetailsPage.load(tempUsers[3].email);170 await UserDetailsPage.waitForLoad();171 expect(await UserDetailsPage.tempPasswordTextIsVisible()).toBe(true);172 });173 174 it("isn't shown a message when a user doesn't have a temporary password", async () => {175 await UserDetailsPage.load(tempUsers[2].email);176 await UserDetailsPage.waitForLoad();177 expect(await UserDetailsPage.tempPasswordTextIsVisible()).toBe(false);178 });179 it("'change password' action shows on user's own details", async () => {180 await UserDetailsPage.load(Zebedee.getTempPublisherUserEmail());181 await UserDetailsPage.waitForLoad();182 expect(await UserDetailsPage.changePasswordButtonIsVisible()).toBe(true);183 });184 it("'change password' action isn't available on other user's details", async () => {185 await UserDetailsPage.load(tempUsers[2].email);186 await UserDetailsPage.waitForLoad();187 expect(await UserDetailsPage.changePasswordButtonIsVisible()).toBe(false);188 });189 it("banner containing actions doesn't show on other user's details", async () => {190 await UserDetailsPage.load(tempUsers[2].email);191 await UserDetailsPage.waitForLoad();192 expect(await UserDetailsPage.userActionsBarIsVisible()).toBe(false);193 });194 it("'delete' action doesn't show on any user's details", async () => {195 await UserDetailsPage.load(tempUsers[1].email);196 await UserDetailsPage.waitForLoad();197 expect(await UserDetailsPage.deleteUserButtonIsVisible()).toBe(false);198 });199 it("'close' action doesn't show on any user's details", async () => {200 await UserDetailsPage.load(tempUsers[0].email);201 await UserDetailsPage.waitForLoad();202 expect(await UserDetailsPage.closeUserButtonIsVisible()).toBe(false);203 });204 it("footer showing actions doesn't show on any users' details", async () => {205 await UserDetailsPage.load(Zebedee.getTempPublisherUserEmail());206 await UserDetailsPage.waitForLoad();207 expect(await UserDetailsPage.userActionsFooterIsVisible()).toBe(false);208 await UserDetailsPage.load(tempUsers[2].email);209 await UserDetailsPage.waitForLoad();210 expect(await UserDetailsPage.userActionsFooterIsVisible()).toBe(false);211 const waitForNavigation = page.waitForNavigation();212 await UsersPage.selectUser(tempUsers[1].email);213 await waitForNavigation;214 expect(await UserDetailsPage.userActionsFooterIsVisible()).toBe(false);215 });216});217describe("Admin users selecting a user", () => {218 beforeAll(async () => {219 await Page.revokeAuthentication();220 await Page.loginAsAdmin();221 });222 beforeEach(async () => {223 await UsersPage.load();224 await UsersPage.waitForLoad();225 });226 it("displays the user's name", async () => {227 await UsersPage.selectUser(tempUsers[1].email);228 await UserDetailsPage.waitForLoad();229 expect(await UserDetailsPage.getUsersName()).toBe(tempUsers[1].name);230 });231 it("displays the user's email", async () => {232 await UsersPage.selectUser(tempUsers[1].email);233 await UserDetailsPage.waitForLoad();234 expect(await UserDetailsPage.getUsersEmail()).toBe(tempUsers[1].email);235 });236 it("displays the user's role", async () => {237 await UsersPage.selectUser(tempUsers[1].email);238 await UserDetailsPage.waitForLoad();239 expect(await UserDetailsPage.getUsersRole()).toBe(`${tempUsers[1].name} is a publisher`);240 });241 it("displays when a user has a temporary password", async () => {242 await UsersPage.selectUser(tempUsers[3].email);243 await UserDetailsPage.waitForLoad();244 expect(await UserDetailsPage.tempPasswordTextIsVisible()).toBe(true);245 });246 247 it("doesn't display a message when a user doesn't have a temporary password", async () => {248 await UsersPage.selectUser(tempUsers[2].email);249 await UserDetailsPage.waitForLoad();250 expect(await UserDetailsPage.tempPasswordTextIsVisible()).toBe(false);251 });252 253 it("displays the 'change password' action", async () => {254 await UsersPage.selectUser(tempUsers[1].email);255 await UserDetailsPage.waitForLoad();256 expect(await UserDetailsPage.changePasswordButtonIsVisible()).toBe(true);257 });258 259 it("displays the 'delete' action", async () => {260 await UsersPage.selectUser(tempUsers[1].email);261 await UserDetailsPage.waitForLoad();262 expect(await UserDetailsPage.deleteUserButtonIsVisible()).toBe(true);263 });264 265 it("displays the 'close' action", async () => {266 await UsersPage.selectUser(tempUsers[1].email);267 await UserDetailsPage.waitForLoad();268 expect(await UserDetailsPage.closeUserButtonIsVisible()).toBe(true);269 });270});271describe("Non-admins users selecting a user", () => {272 beforeAll(async () => {273 await Page.revokeAuthentication();274 await Page.loginAsPublisher();275 });276 beforeEach(async () => {277 await UsersPage.load();278 await UsersPage.waitForLoad();279 });280 it("displays the user's name", async () => {281 await UsersPage.selectUser(tempUsers[1].email);282 await UserDetailsPage.waitForLoad();283 expect(await UserDetailsPage.getUsersName()).toBe(tempUsers[1].name);284 });285 it("displays the user's email", async () => {286 await UsersPage.selectUser(tempUsers[1].email);287 await UserDetailsPage.waitForLoad();288 expect(await UserDetailsPage.getUsersEmail()).toBe(tempUsers[1].email);289 });290 it("displays the user's role", async () => {291 await UsersPage.selectUser(tempUsers[1].email);292 await UserDetailsPage.waitForLoad();293 expect(await UserDetailsPage.getUsersRole()).toBe(`${tempUsers[1].name} is a publisher`);294 });295 it("displays when a user has a temporary password", async () => {296 await UsersPage.selectUser(tempUsers[3].email);297 await UserDetailsPage.waitForLoad();298 expect(await UserDetailsPage.tempPasswordTextIsVisible()).toBe(true);299 });300 301 it("doesn't display a message when a user doesn't have a temporary password", async () => {302 await UsersPage.selectUser(tempUsers[2].email);303 await UserDetailsPage.waitForLoad();304 expect(await UserDetailsPage.tempPasswordTextIsVisible()).toBe(false);305 });306 it("displays the 'change password' button if it's their own account", async () => {307 await UsersPage.selectUser(Zebedee.getTempPublisherUserEmail());308 await UserDetailsPage.waitForLoad();309 expect(await UserDetailsPage.changePasswordButtonIsVisible()).toBe(true);310 });311 it("doesn't display the 'change password' button if it's another user's account", async () => {312 await UsersPage.selectUser(tempUsers[2].email);313 await UserDetailsPage.waitForLoad();314 expect(await UserDetailsPage.changePasswordButtonIsVisible()).toBe(false);315 });316 it("doesn't display the 'close' action", async () => {317 await UsersPage.selectUser(tempUsers[2].email);318 await UserDetailsPage.waitForLoad();319 expect(await UserDetailsPage.closeUserButtonIsVisible()).toBe(false);320 });321 it("doesn't display the 'delete' action", async () => {322 await UsersPage.selectUser(tempUsers[2].email);323 await UserDetailsPage.waitForLoad();324 expect(await UserDetailsPage.deleteUserButtonIsVisible()).toBe(false);325 });326 it("doesn't display the actions footer", async () => {327 await UsersPage.selectUser(tempUsers[2].email);328 await UserDetailsPage.waitForLoad();329 expect(await UserDetailsPage.userActionsFooterIsVisible()).toBe(false);330 });...
routes.js
Source:routes.js
...61 [routes.DASHBOARD]: /^(\/[a-z0-9-_]+\/dashboard|\/u\/[a-z0-9-_]+\/stream-manager)/i,62 [routes.CHANNEL_SQUAD]: /^\/[a-z0-9-_]+\/squad/i,63 [routes.CHANNEL]: /^\/[a-z0-9-_]+/i64};65function waitForLoad(type, context = null) {66 let timeout;67 let interval;68 const startTime = Date.now();69 return Promise.race([70 new Promise(resolve => {71 timeout = setTimeout(resolve, 15000);72 }),73 new Promise(resolve => {74 const loaded = loadPredicates[type];75 if (loaded(context)) {76 resolve();77 return;78 }79 interval = setInterval(() => loaded(context) && resolve(), 100);80 })81 ]).then(() => {82 debug.log(`waited for ${type} load: ${Date.now() - startTime}ms`);83 clearTimeout(timeout);84 clearInterval(interval);85 }).then(() => watcher.emit('load'));86}87function getRouteFromPath(path) {88 let route = null;89 for (const name of Object.keys(routeKeysToPaths)) {90 const regex = routeKeysToPaths[name];91 if (!regex.test(path)) continue;92 route = name;93 break;94 }95 // twitch's embed subdomain only supports channel view96 if (route === routes.HOMEPAGE && location.hostname === 'embed.twitch.tv') {97 return routes.CHANNEL;98 }99 return route;100}101function onRouteChange(location) {102 const lastPath = currentPath103 const lastRoute = currentRoute;104 const path = location.pathname;105 const route = getRouteFromPath(path);106 debug.log(`New route: ${location.pathname} as ${route}`);107 // trigger on all loads (like resize functions)108 watcher.emit('load');109 currentPath = path;110 currentRoute = route;111 if (currentPath === lastPath) return;112 if(!sidenav_loaded){113 sidenav_loaded = true114 waitForLoad('sidenav').then(() => {115 watcher.emit('load.sidenav')116 })117 }118 switch (route) {119 case routes.DIRECTORY_FOLLOWING:120 if (lastRoute === routes.DIRECTORY_FOLLOWING_LIVE) break;121 waitForLoad('following').then(() => watcher.emit('load.directory.following'));122 waitForLoad('followbar').then(() =>Â watcher.emit('load.followbar'));123 break;124 case routes.VOD:125 waitForLoad('vod').then(() => watcher.emit('load.vod'));126 waitForLoad('player').then(() => watcher.emit('load.player'));127 break;128 case routes.CHANNEL_SQUAD:129 waitForLoad('player').then(() => watcher.emit('load.player'));130 break;131 case routes.CHANNEL:132 waitForLoad('channel').then(() => watcher.emit('load.channel'));133 waitForLoad('player').then(() => watcher.emit('load.player'));134 waitForLoad('followbar').then(() =>Â watcher.emit('load.followbar'));135 break;136 case routes.HOMEPAGE:137 waitForLoad('homepage').then(() => watcher.emit('load.homepage'));138 break;139 }140}141module.exports = watcher_ => {142 watcher = watcher_;143 144 historyObserver.on('pushState', location => onRouteChange(location));145 historyObserver.on('replaceState', location => onRouteChange(location));146 historyObserver.on('popState', location => onRouteChange(location));147 onRouteChange(location);148 // force reload player when the player gets recreated149 domObserver.on('.persistent-player', (node, isConnected) => {150 if (!isConnected) return;151 waitForLoad('player').then(() => watcher.emit('load.player'));152 });...
entity-behavior.test.js
Source:entity-behavior.test.js
...7 sandbox = sinon.createSandbox();8 element = await fixture(html`<entity-behavior-test-component></entity-behavior-test-component>`);9 window.D2L.Siren.WhitelistBehavior._testMode(true);10 await new Promise(resolve => {11 function waitForLoad(e) {12 if (e.detail.entity.getLinkByRel('self').href === 'test/static-data/199.json') {13 element.removeEventListener('d2l-siren-entity-changed', waitForLoad);14 resolve();15 }16 }17 element.addEventListener('d2l-siren-entity-changed', waitForLoad);18 element.href = 'test/static-data/199.json';19 element.token = 'foozleberries';20 });21 });22 afterEach(() => {23 window.D2L.Siren.WhitelistBehavior._testMode(false);24 sandbox.restore();25 });26 describe('smoke test', () => {27 it('can be instantiated', () => {28 expect(element.is).to.equal('entity-behavior-test-component');29 });30 it('entity is set to static data', () => {31 expect(element.entity.entities[0].class).to.deep.equal(['richtext', 'description']);32 });33 });34 describe('href changed', () => {35 it('entity is set to new static data', (done) => {36 const oldEntity = element.entity;37 function waitForLoad(e) {38 if (e.detail.entity.getLinkByRel('self').href === 'test/static-data/200.json') {39 element.removeEventListener('d2l-siren-entity-changed', waitForLoad);40 expect(element.entity).to.not.deep.equal(oldEntity);41 done();42 }43 }44 element.addEventListener('d2l-siren-entity-changed', waitForLoad);45 element.href = 'test/static-data/200.json';46 });47 });48 describe('token changed', () => {49 it('entity is refetched', (done) => {50 const oldEntity = element.entity;51 function waitForLoad(e) {52 if (e.detail.entity.getLinkByRel('self').href === 'test/static-data/199.json') {53 element.removeEventListener('d2l-siren-entity-changed', waitForLoad);54 expect(element.entity).to.deep.equal(oldEntity);55 expect(element.entity).to.not.equal(oldEntity);56 done();57 }58 }59 element.addEventListener('d2l-siren-entity-changed', waitForLoad);60 element.token = 'foozleberries*foozleberries';61 });62 it('old listeners removed as details change', () => {63 window.D2L.Siren.EntityStore.clear();64 element.removeListener = null;65 const add = sandbox.spy(window.D2L.Siren.EntityStore, 'addListener');...
Using AI Code Generation
1var wpt = require('webpagetest');2var test = wpt('www.webpagetest.org');3test.runTest(url, { runs: 1, location: 'Dulles:Chrome', pollResults: 1 }, function(err, data) {4 if (err) {5 console.log('Error: ' + err);6 } else {7 console.log('Test Status: ' + data.statusText);8 if (data.statusCode == 200) {9 test.waitForTestComplete(data.data.testId, function(err, data) {10 if (err) {11 console.log('Error: ' + err);12 } else {13 console.log('Test Status: ' + data.statusText);14 if (data.statusCode == 200) {15 console.log(data.data.summary);16 }17 }18 });19 }20 }21});
Using AI Code Generation
1var wptools = require('wptools');2wptools.get('Barack Obama').then(function(page){3 page.waitForLoad().then(function(data){4 console.log(data);5 });6});7{ 8 langlinks: {
Using AI Code Generation
1 console.log("Page loaded");2});3##wptHook.waitForLoad(url,callback)4 console.log("Page loaded");5});6##wptHook.waitForLoad(url,timeout,callback)7 console.log("Page loaded");8});9##wptHook.waitForLoad(url,timeout,callback,checkInterval)10 console.log("Page loaded");11},1000);12##wptHook.waitForLoad(url,timeout,callback,checkInterval,ignoreHash)
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!!