How to use waitForMessage method in qawolf

Best JavaScript code snippet using qawolf

browser_RemotePageManager.js

Source:browser_RemotePageManager.js Github

copy

Full Screen

...5var { RemotePages, RemotePageManager } = Cu.import("resource://gre/modules/RemotePageManager.jsm", {});6function failOnMessage(message) {7 ok(false, "Should not have seen message " + message.name);8}9function waitForMessage(port, message, expectedPort = port) {10 return new Promise((resolve) => {11 function listener(message) {12 is(message.target, expectedPort, "Message should be from the right port.");13 port.removeMessageListener(listener);14 resolve(message);15 }16 port.addMessageListener(message, listener);17 });18}19function waitForPort(url, createTab = true) {20 return new Promise((resolve) => {21 RemotePageManager.addRemotePageListener(url, (port) => {22 RemotePageManager.removeRemotePageListener(url);23 waitForMessage(port, "RemotePage:Load").then(() => resolve(port));24 });25 if (createTab)26 gBrowser.selectedTab = gBrowser.addTab(url);27 });28}29function waitForPage(pages) {30 return new Promise((resolve) => {31 function listener({ target }) {32 pages.removeMessageListener("RemotePage:Init", listener);33 waitForMessage(target, "RemotePage:Load").then(() => resolve(target));34 }35 pages.addMessageListener("RemotePage:Init", listener);36 gBrowser.selectedTab = gBrowser.addTab(TEST_URL);37 });38}39function swapDocShells(browser1, browser2) {40 // Swap frameLoaders.41 browser1.swapDocShells(browser2);42 // Swap permanentKeys.43 let tmp = browser1.permanentKey;44 browser1.permanentKey = browser2.permanentKey;45 browser2.permanentKey = tmp;46}47// Test that opening a page creates a port, sends the load event and then48// navigating to a new page sends the unload event. Going back should create a49// new port50add_task(function* init_navigate() {51 let port = yield waitForPort(TEST_URL);52 is(port.browser, gBrowser.selectedBrowser, "Port is for the correct browser");53 let loaded = new Promise(resolve => {54 function listener() {55 gBrowser.selectedBrowser.removeEventListener("load", listener, true);56 resolve();57 }58 gBrowser.selectedBrowser.addEventListener("load", listener, true);59 gBrowser.loadURI("about:blank");60 });61 yield waitForMessage(port, "RemotePage:Unload");62 // Port should be destroyed now63 try {64 port.addMessageListener("Foo", failOnMessage);65 ok(false, "Should have seen exception");66 }67 catch (e) {68 ok(true, "Should have seen exception");69 }70 try {71 port.sendAsyncMessage("Foo");72 ok(false, "Should have seen exception");73 }74 catch (e) {75 ok(true, "Should have seen exception");76 }77 yield loaded;78 gBrowser.goBack();79 port = yield waitForPort(TEST_URL, false);80 port.sendAsyncMessage("Ping2");81 let message = yield waitForMessage(port, "Pong2");82 port.destroy();83 gBrowser.removeCurrentTab();84});85// Test that opening a page creates a port, sends the load event and then86// closing the tab sends the unload event87add_task(function* init_close() {88 let port = yield waitForPort(TEST_URL);89 is(port.browser, gBrowser.selectedBrowser, "Port is for the correct browser");90 let unloadPromise = waitForMessage(port, "RemotePage:Unload");91 gBrowser.removeCurrentTab();92 yield unloadPromise;93 // Port should be destroyed now94 try {95 port.addMessageListener("Foo", failOnMessage);96 ok(false, "Should have seen exception");97 }98 catch (e) {99 ok(true, "Should have seen exception");100 }101 try {102 port.sendAsyncMessage("Foo");103 ok(false, "Should have seen exception");104 }105 catch (e) {106 ok(true, "Should have seen exception");107 }108});109// Tests that we can send messages to individual pages even when more than one110// is open111add_task(function* multiple_ports() {112 let port1 = yield waitForPort(TEST_URL);113 is(port1.browser, gBrowser.selectedBrowser, "Port is for the correct browser");114 let port2 = yield waitForPort(TEST_URL);115 is(port2.browser, gBrowser.selectedBrowser, "Port is for the correct browser");116 port2.addMessageListener("Pong", failOnMessage);117 port1.sendAsyncMessage("Ping", { str: "foobar", counter: 0 });118 let message = yield waitForMessage(port1, "Pong");119 port2.removeMessageListener("Pong", failOnMessage);120 is(message.data.str, "foobar", "String should pass through");121 is(message.data.counter, 1, "Counter should be incremented");122 port1.addMessageListener("Pong", failOnMessage);123 port2.sendAsyncMessage("Ping", { str: "foobaz", counter: 5 });124 message = yield waitForMessage(port2, "Pong");125 port1.removeMessageListener("Pong", failOnMessage);126 is(message.data.str, "foobaz", "String should pass through");127 is(message.data.counter, 6, "Counter should be incremented");128 let unloadPromise = waitForMessage(port2, "RemotePage:Unload");129 gBrowser.removeTab(gBrowser.getTabForBrowser(port2.browser));130 yield unloadPromise;131 try {132 port2.addMessageListener("Pong", failOnMessage);133 ok(false, "Should not have been able to add a new message listener to a destroyed port.");134 }135 catch (e) {136 ok(true, "Should not have been able to add a new message listener to a destroyed port.");137 }138 port1.sendAsyncMessage("Ping", { str: "foobar", counter: 0 });139 message = yield waitForMessage(port1, "Pong");140 is(message.data.str, "foobar", "String should pass through");141 is(message.data.counter, 1, "Counter should be incremented");142 unloadPromise = waitForMessage(port1, "RemotePage:Unload");143 gBrowser.removeTab(gBrowser.getTabForBrowser(port1.browser));144 yield unloadPromise;145});146// Tests that swapping browser docshells doesn't break the ports147add_task(function* browser_switch() {148 let port1 = yield waitForPort(TEST_URL);149 is(port1.browser, gBrowser.selectedBrowser, "Port is for the correct browser");150 let browser1 = gBrowser.selectedBrowser;151 port1.sendAsyncMessage("SetCookie", { value: "om nom" });152 let port2 = yield waitForPort(TEST_URL);153 is(port2.browser, gBrowser.selectedBrowser, "Port is for the correct browser");154 let browser2 = gBrowser.selectedBrowser;155 port2.sendAsyncMessage("SetCookie", { value: "om nom nom" });156 port2.addMessageListener("Cookie", failOnMessage);157 port1.sendAsyncMessage("GetCookie");158 let message = yield waitForMessage(port1, "Cookie");159 port2.removeMessageListener("Cookie", failOnMessage);160 is(message.data.value, "om nom", "Should have the right cookie");161 port1.addMessageListener("Cookie", failOnMessage);162 port2.sendAsyncMessage("GetCookie", { str: "foobaz", counter: 5 });163 message = yield waitForMessage(port2, "Cookie");164 port1.removeMessageListener("Cookie", failOnMessage);165 is(message.data.value, "om nom nom", "Should have the right cookie");166 swapDocShells(browser1, browser2);167 is(port1.browser, browser2, "Should have noticed the swap");168 is(port2.browser, browser1, "Should have noticed the swap");169 // Cookies should have stayed the same170 port2.addMessageListener("Cookie", failOnMessage);171 port1.sendAsyncMessage("GetCookie");172 message = yield waitForMessage(port1, "Cookie");173 port2.removeMessageListener("Cookie", failOnMessage);174 is(message.data.value, "om nom", "Should have the right cookie");175 port1.addMessageListener("Cookie", failOnMessage);176 port2.sendAsyncMessage("GetCookie", { str: "foobaz", counter: 5 });177 message = yield waitForMessage(port2, "Cookie");178 port1.removeMessageListener("Cookie", failOnMessage);179 is(message.data.value, "om nom nom", "Should have the right cookie");180 swapDocShells(browser1, browser2);181 is(port1.browser, browser1, "Should have noticed the swap");182 is(port2.browser, browser2, "Should have noticed the swap");183 // Cookies should have stayed the same184 port2.addMessageListener("Cookie", failOnMessage);185 port1.sendAsyncMessage("GetCookie");186 message = yield waitForMessage(port1, "Cookie");187 port2.removeMessageListener("Cookie", failOnMessage);188 is(message.data.value, "om nom", "Should have the right cookie");189 port1.addMessageListener("Cookie", failOnMessage);190 port2.sendAsyncMessage("GetCookie", { str: "foobaz", counter: 5 });191 message = yield waitForMessage(port2, "Cookie");192 port1.removeMessageListener("Cookie", failOnMessage);193 is(message.data.value, "om nom nom", "Should have the right cookie");194 let unloadPromise = waitForMessage(port2, "RemotePage:Unload");195 gBrowser.removeTab(gBrowser.getTabForBrowser(browser2));196 yield unloadPromise;197 unloadPromise = waitForMessage(port1, "RemotePage:Unload");198 gBrowser.removeTab(gBrowser.getTabForBrowser(browser1));199 yield unloadPromise;200});201// Tests that removeMessageListener in chrome works202add_task(function* remove_chrome_listener() {203 let port = yield waitForPort(TEST_URL);204 is(port.browser, gBrowser.selectedBrowser, "Port is for the correct browser");205 // This relies on messages sent arriving in the same order. Pong will be206 // sent back before Pong2 so if removeMessageListener fails the test will fail207 port.addMessageListener("Pong", failOnMessage);208 port.removeMessageListener("Pong", failOnMessage);209 port.sendAsyncMessage("Ping", { str: "remove_listener", counter: 27 });210 port.sendAsyncMessage("Ping2");211 yield waitForMessage(port, "Pong2");212 let unloadPromise = waitForMessage(port, "RemotePage:Unload");213 gBrowser.removeCurrentTab();214 yield unloadPromise;215});216// Tests that removeMessageListener in content works217add_task(function* remove_content_listener() {218 let port = yield waitForPort(TEST_URL);219 is(port.browser, gBrowser.selectedBrowser, "Port is for the correct browser");220 // This relies on messages sent arriving in the same order. Pong3 would be221 // sent back before Pong2 so if removeMessageListener fails the test will fail222 port.addMessageListener("Pong3", failOnMessage);223 port.sendAsyncMessage("Ping3");224 port.sendAsyncMessage("Ping2");225 yield waitForMessage(port, "Pong2");226 let unloadPromise = waitForMessage(port, "RemotePage:Unload");227 gBrowser.removeCurrentTab();228 yield unloadPromise;229});230// Test RemotePages works231add_task(function* remote_pages_basic() {232 let pages = new RemotePages(TEST_URL);233 let port = yield waitForPage(pages);234 is(port.browser, gBrowser.selectedBrowser, "Port is for the correct browser");235 // Listening to global messages should work236 let unloadPromise = waitForMessage(pages, "RemotePage:Unload", port);237 gBrowser.removeCurrentTab();238 yield unloadPromise;239 pages.destroy();240 // RemotePages should be destroyed now241 try {242 pages.addMessageListener("Foo", failOnMessage);243 ok(false, "Should have seen exception");244 }245 catch (e) {246 ok(true, "Should have seen exception");247 }248 try {249 pages.sendAsyncMessage("Foo");250 ok(false, "Should have seen exception");251 }252 catch (e) {253 ok(true, "Should have seen exception");254 }255});256// Test sending messages to all remote pages works257add_task(function* remote_pages_multiple() {258 let pages = new RemotePages(TEST_URL);259 let port1 = yield waitForPage(pages);260 let port2 = yield waitForPage(pages);261 let pongPorts = [];262 yield new Promise((resolve) => {263 function listener({ name, target, data }) {264 is(name, "Pong", "Should have seen the right response.");265 is(data.str, "remote_pages", "String should pass through");266 is(data.counter, 43, "Counter should be incremented");267 pongPorts.push(target);268 if (pongPorts.length == 2)269 resolve();270 }271 pages.addMessageListener("Pong", listener);272 pages.sendAsyncMessage("Ping", { str: "remote_pages", counter: 42 });273 });274 // We don't make any guarantees about which order messages are sent to known275 // pages so the pongs could have come back in any order.276 isnot(pongPorts[0], pongPorts[1], "Should have received pongs from different ports");277 ok(pongPorts.indexOf(port1) >= 0, "Should have seen a pong from port1");278 ok(pongPorts.indexOf(port2) >= 0, "Should have seen a pong from port2");279 // After destroy we should see no messages280 pages.addMessageListener("RemotePage:Unload", failOnMessage);281 pages.destroy();282 gBrowser.removeTab(gBrowser.getTabForBrowser(port1.browser));283 gBrowser.removeTab(gBrowser.getTabForBrowser(port2.browser));284});285// Test sending various types of data across the boundary286add_task(function* send_data() {287 let port = yield waitForPort(TEST_URL);288 is(port.browser, gBrowser.selectedBrowser, "Port is for the correct browser");289 let data = {290 integer: 45,291 real: 45.78,292 str: "foobar",293 array: [1, 2, 3, 5, 27]294 };295 port.sendAsyncMessage("SendData", data);296 let message = yield waitForMessage(port, "ReceivedData");297 ok(message.data.result, message.data.status);298 gBrowser.removeCurrentTab();299});300// Test sending an object of data across the boundary301add_task(function* send_data2() {302 let port = yield waitForPort(TEST_URL);303 is(port.browser, gBrowser.selectedBrowser, "Port is for the correct browser");304 let data = {305 integer: 45,306 real: 45.78,307 str: "foobar",308 array: [1, 2, 3, 5, 27]309 };310 port.sendAsyncMessage("SendData2", {data});311 let message = yield waitForMessage(port, "ReceivedData2");312 ok(message.data.result, message.data.status);313 gBrowser.removeCurrentTab();...

Full Screen

Full Screen

start.js

Source:start.js Github

copy

Full Screen

...17 opts.command,18 opts.options19 );20 if (opts.waitForMessage) {21 proc.stdout.on('data', function waitForMessage(data) {22 if (data.toString().match(opts.waitForMessage)) {23 if (callback) {24 callback();25 }26 }27 });28 }29 if (!opts.silent) {30 proc.stdout.pipe(process.stdout);31 proc.stderr.pipe(process.stderr);32 }33 if (opts.logFile) {34 var logStream = fs.createWriteStream(opts.logFile, {flags: 'a'});35 proc.stdout.pipe(logStream);...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const qawolf = require("qawolf");2const browser = await qawolf.launch();3await qawolf.create();4await browser.type("input[name=q]", "qawolf");5await browser.press("input[name=q]", "Enter");6const message = await qawolf.waitForMessage();7console.log(message);8await qawolf.stopVideos();9await browser.close();10const qawolf = require("qawolf");11const browser = await qawolf.launch();12await qawolf.create();13await browser.type("input[name=q]", "qawolf");14await browser.press("input[name=q]", "Enter");15const message = await qawolf.waitForMessage();16console.log(message);17await qawolf.stopVideos();18await browser.close();19const qawolf = require("qawolf");20const browser = await qawolf.launch();21await qawolf.create();22await browser.type("input[name=q]", "qawolf");23await browser.press("input[name=q]", "Enter");24const message = await qawolf.waitForMessage();25console.log(message);26await qawolf.stopVideos();27await browser.close();28const qawolf = require("qawolf");29const browser = await qawolf.launch();30await qawolf.create();31await browser.type("input[name=q]", "qawolf");32await browser.press("input[name=q]", "Enter");33const message = await qawolf.waitForMessage();34console.log(message);35await qawolf.stopVideos();36await browser.close();37const qawolf = require("qawolf");38const browser = await qawolf.launch();39await qawolf.create();40await browser.type("input[name=q]", "qawolf");41await browser.press("input[name=q]", "Enter");42const message = await qawolf.waitForMessage();43console.log(message);44await qawolf.stopVideos();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { launch, firefox } = require("qawolf");2(async () => {3 const browser = await launch({ browser: firefox });4 const page = await browser.newPage();5 await page.click("input[name='q']");6 await page.type("input[name='q']", "hello world");7 await page.press("input[name='q']", "Enter");8 await browser.close();9})();10const { chromium } = require("playwright");11(async () => {12 const browser = await chromium.launch();13 const page = await browser.newPage();14 await page.click("input[name='q']");15 await page.type("input[name='q']", "hello world");16 await page.press("input[name='q']", "Enter");17 await browser.close();18})();19const puppeteer = require("puppeteer");20(async () => {21 const browser = await puppeteer.launch();22 const page = await browser.newPage();23 await page.click("input[name='q']");24 await page.type("input[name='q']", "hello world");25 await page.press("input[name='q']", "Enter");26 await browser.close();27})();28const playwright = require("playwright");29(async () => {30 for (const browserType of BROWSER) {31 const browser = await playwright[browserType].launch();32 const context = await browser.newContext();33 const page = await context.newPage();34 await page.click("input[name='q']");35 await page.type("input[name='q']", "hello world");36 await page.press("input[name='q']", "Enter");37 await browser.close();38 }39})();40const playwright = require("playwright");41(async () => {42 for (const browserType of BROWSER) {43 const browser = await playwright[browserType].launch();44 const context = await browser.newContext();45 const page = await context.newPage();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { Browser, waitForMessage } = require("qawolf");2const { test, expect } = require("@playwright/test");3test.describe("Test", () => {4 let browser;5 let page;6 test.beforeAll(async () => {7 browser = await Browser.launch();8 });9 test.beforeEach(async () => {10 page = await browser.newPage();11 });12 test.afterEach(async () => {13 await page.close();14 });15 test.afterAll(async () => {16 await browser.close();17 });18 test("Test", async () => {19 await page.click("input[name=\"q\"]");20 await page.fill("input[name=\"q\"]", "Hello World");21 await page.click("input[name=\"btnK\"]");22 const message = await waitForMessage(page, "search");23 expect(message).toEqual("Hello World");24 });25});26import { test, expect } from "@playwright/test";27import { Browser, waitForMessage } from "qawolf";28test.describe("Test", () => {29 let browser;30 let page;31 test.beforeAll(async () => {32 browser = await Browser.launch();33 });34 test.beforeEach(async () => {35 page = await browser.newPage();36 });37 test.afterEach(async () => {38 await page.close();39 });40 test.afterAll(async () => {41 await browser.close();42 });43 test("Test", async () => {44 await page.click("input[name=\"q\"]");45 await page.fill("input[name=\"q\"]", "Hello World");46 await page.click("input[name=\"btnK\"]");47 const message = await waitForMessage(page, "search");48 expect(message).toEqual("Hello World");49 });50});51import { test, expect } from "@playwright/test";52import { Browser, waitForMessage } from "qawolf";53test.describe("Test", () => {54 let browser;55 let page;56 test.beforeAll(async () => {57 browser = await Browser.launch();58 });59 test.beforeEach(async () => {60 page = await browser.newPage();61 });

Full Screen

Using AI Code Generation

copy

Full Screen

1const { waitForMessage } = require("qawolf");2const message = await waitForMessage();3const { sendMessage } = require("qawolf");4sendMessage({ type: "click", selector: "#my-button" });5const { waitForMessage } = require("qawolf");6const message = await waitForMessage();7const { sendMessage } = require("qawolf");8sendMessage({ type: "click", selector: "#my-button" });9const { waitForMessage } = require("qawolf");10const message = await waitForMessage();11const { sendMessage } = require("qawolf");12sendMessage({ type: "click", selector: "#my-button" });13const { waitForMessage } = require("qawolf");14const message = await waitForMessage();15const { sendMessage } = require("qawolf");16sendMessage({ type: "click", selector: "#my-button" });17const { waitForMessage } = require("qawolf");18const message = await waitForMessage();19const { sendMessage } = require("qawolf");20sendMessage({ type: "click", selector: "#my-button" });

Full Screen

Using AI Code Generation

copy

Full Screen

1const { launch, browserType, devices } = require("qawolf");2const page = await browser.page();3await page.waitForMessage("message");4await page.click("text=Hello World");5await browser.close();6const { launch, browserType, devices } = require("qawolf");7const page = await browser.page();8await page.waitForMessage("message");9await page.click("text=Hello World");10await browser.close();11const { launch, browserType, devices } = require("qawolf");12const page = await browser.page();13await page.waitForMessage("message");14await page.click("text=Hello World");15await browser.close();16const { launch, browserType, devices } = require("qawolf");17const page = await browser.page();18await page.waitForMessage("message");19await page.click("text=Hello World");20await browser.close();21const { launch, browserType, devices } = require("qawolf");

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