Best JavaScript code snippet using qawolf
service.ts
Source:service.ts
...106 state.assigned_runner_id = null;107 void SideEffects.emit('updateServiceState', {108 serviceName,109 });110 servicesWorkflow.bring(serviceName).actions.assignRunner({111 spec: service.spec,112 });113 logger.info('start run');114 } catch (err) {115 console.error(err);116 }117 },118 async assignRunner({ spec }: { spec: ServiceSpec }) {119 if (state.state !== 'pending-assignment') {120 logger.info(`service not in pending assignment: ${state.state}`);121 return null;122 }123 const runnerId = runnerRoundRobin.getNext();124 if (!runnerId) {125 logger.info(`no available runner found`);126 logger.info(`waiting for a runner to join`);127 return;128 }129 logger.info(`assigning to ${runnerId}`);130 state.state = 'assigned';131 state.assigned_runner_id = runnerId;132 void SideEffects.emit('updateServiceState', {133 serviceName,134 });135 await runnersWorkflow136 .get(runnerId)137 .actions.assignService({ serviceName, spec }, { promise: true });138 },139 async retryAssign({ spec }: { spec: ServiceSpec }, api) {140 if (141 state.state === 'pending-assignment' ||142 (state.state === 'assigned' && !state.current_task_id)143 ) {144 state.state = 'pending-assignment';145 state.assigned_runner_id = null;146 state.current_task_id = null;147 state.current_task_state = null;148 await api.do(serviceEntity.actions.assignRunner, { spec });149 }150 },151 taskCreating({ taskId }: { taskId: string }) {152 state.state = 'running';153 state.current_task_id = taskId;154 state.current_task_state = 'creating';155 },156 taskRunning({ taskId }: { taskId: string }) {157 state.current_task_state = 'running';158 },159 taskStopping({ taskId }: { taskId: string }) {160 state.current_task_state = 'stopping';161 },162 taskStopped({ taskId }: { taskId: string }) {163 state.state = 'off';164 state.current_task_state = 'stopped';165 },166 taskExited({ taskId }: { taskId: string }) {167 state.state = 'off';168 state.current_task_state = 'exited';169 },170 },171 });172 return serviceEntity;173};174const logger = baseLogger.extend('services');175export const servicesWorkflow = {176 ...createGroup({177 name: 'services',178 initEntity: createServiceWorkflow,179 leaveEntity: async (entity) => {180 await entity.actions.remove(null, { promise: true });181 },182 }),183 ...createEntity(null, {184 actions: {185 /**186 * Retry assignment for each service in pending-assignment187 */188 async assignPendingAssigments(a: void) {189 if (!runnerRoundRobin.length) {190 logger.info(`no runner available`);191 return;192 }193 const pendingServices = servicesWorkflow194 .keys()195 .map((k) => servicesWorkflow.get(k))196 .filter((service) => {197 return service.state.state === 'pending-assignment';198 });199 const services = await Service.getIn(200 pendingServices.map((s) => s.state.name)201 );202 services.forEach((service) => {203 servicesWorkflow.get(service.name).actions.assignRunner({204 spec: service.spec,205 });206 });207 },208 },209 }),...
LogisticsDeliveriesNCR.jsx
Source:LogisticsDeliveriesNCR.jsx
...55 return <ReactTable filterable data={this.props.deliveries} columns={logisticsDeliveryNCRColumns}56 defaultPageSize={10} className="data-table -striped -highlight" />;57 }58 }59 assignRunner() {60 let data = {61 "orderlineIds": this.state.selectedOrderlines,62 "runnerContact": `${this.state.selectedRunner.phoneNumber}`,63 "runnerId": this.state.selectedRunner.email,64 "runnerName": this.state.selectedRunner.name,65 "user": this.props.user66 };67 this.props.assignRunnerToOrderlinesDelivery(data);68 }69 selectRunner(e) {70 let runner = this.props.runners.filter(function (obj) {71 return obj.email == e.target.value;72 });73 this.setState({74 selectedRunner: runner[0]75 });76 }77 render() {78 return <section className="">79 <h1>Deliveries (NCR)</h1><br />80 {this.props.runners ? <select onChange={(e) => { this.selectRunner(e) }} className={styles.orderProcessSelect}>81 <option value=""> -- Select Runner -- </option>82 {this.props.runners.map((runner, i) => {83 return <option key={i} value={runner.email}>{runner.name}</option>;84 })}85 </select> : null}86 <button className={styles.btnBlack} onClick={(e) => { this.assignRunner(e) }}>Assign</button>87 <br /><br />88 {this.renderDeliveries()}89 </section>90 }91}92function matchDispatchToProps(dispatch) {93 return bindActionCreators({94 getOrderlinesForNCRDelivery,95 getAllRunners,96 assignRunnerToOrderlinesDelivery97 }, dispatch);98}99function mapStateToProps(state) {100 return {...
LogisticsPickupsNCR.jsx
Source:LogisticsPickupsNCR.jsx
...55 return <ReactTable filterable data={this.props.pickups} columns={logisticsPickupNCRColumns}56 defaultPageSize={10} className="data-table -striped -highlight" />;57 }58 }59 assignRunner() {60 let data = {61 "orderlineIds": this.state.selectedOrderlines,62 "runnerContact": `${this.state.selectedRunner.phoneNumber}`,63 "runnerId": this.state.selectedRunner.email,64 "runnerName": this.state.selectedRunner.name,65 "user": this.props.user66 };67 this.props.assignRunnerToOrderlinesPickup(data);68 }69 selectRunner(e) {70 let runner = this.props.runners.filter(function (obj) {71 return obj.email == e.target.value;72 });73 this.setState({74 selectedRunner: runner[0]75 });76 }77 render() {78 return <section className="">79 <h1>Pickups (NCR)</h1><br />80 {this.props.runners ? <select onChange={(e) => { this.selectRunner(e) }} className={styles.orderProcessSelect}>81 <option value=""> -- Select Runner -- </option>82 {this.props.runners.map((runner, i) => {83 return <option key={i} value={runner.email}>{runner.name}</option>;84 })}85 </select> : null}86 <button onClick={(e) => { this.assignRunner(e) }} className={styles.btnBlack}>Assign</button>87 <br /><br />88 {this.renderpickups()}89 </section>90 }91}92function matchDispatchToProps(dispatch) {93 return bindActionCreators({94 assignRunnerToOrderlinesPickup,95 getAllRunners,96 getOrderLinesForNCRPickup97 }, dispatch);98}99function mapStateToProps(state) {100 return {...
energy.js
Source:energy.js
1var platform = require('platform'),2 util = require('util'),3 _ = require('lodash');4module.exports = Energy;5Energy.getFor = function(energy) {6 if (!Game.myGame.energies) Game.myGame.energies = {};7 var energies = Game.myGame.energies;8 if (energies[energy.id]) {9 return energies[energy.id];10 } else {11 var nrg = platform.construct(Energy, energy);12 energies[energy.id] = nrg;13 return nrg;14 }15};16platform.inherit(Energy, platform.Base);17function Energy(energy) {18 this.base();19 this.energy = energy;20 this.on('tick', this.checkAlive);21 this.on('runner.full', this.relieveRunner);22 this.runners = [];23}24Energy.prototype.assignRunner = function(runner) {25 this.runners.push(runner);26 runner.assignment = this.energy;27};28Energy.prototype.relieveRunner = function(runner) {29 var i = this.runners.indexOf(runner);30 if (i != -1) {31 this.runners.splice(i, 1);32 runner.assignment = null;33 }34};35Energy.prototype.checkAlive = function() {36 this.alive = !!(this.energy && this.energy.energy);37 if (!this.alive) {38 this.broadcast('energyDepleted', this);39 this.dispose();40 }41};42Energy.prototype.getRunnerCapacity = function() {43 var cap = 0;44 _.forEach(this.runners, function(runner) {45 cap += runner.energyCapacity - runner.energy;46 });47 return cap;48};49Energy.prototype.getUnclaimedEnergy = function() {50 return Math.max(0, this.energy.energy - this.getRunnerCapacity());...
Using AI Code Generation
1const { assignRunner } = require("qawolf");2const { create } = require("qawolf");3const { launch } = require("qawolf");4const { register } = require("qawolf");5const { save } = require("qawolf");6const { start } = require("qawolf");7const { stop } = require("qawolf");8const { upload } = require("qawolf");9const { wait } = require("qawolf");10const { waitFor } = require("qawolf");11const { waitForPage } = require("qawolf");12const { waitForSelector } = require("qawolf");13const { waitForUrl } = require("qawolf");14const { waitForXPath } = require("qawolf");15const { click } = require("qawolf");16const { doubleClick } = require("qawolf");17const { dragAndDrop } = require("qawolf");18const { focus } = require("qawolf");19const { hover } = require("qawolf");20const { press } = require("qawolf");21const { scroll } = require("qawolf");22const { scrollTo } = require("qawolf");
Using AI Code Generation
1const { assignRunner } = require("qawolf");2const { chromium } = require("playwright");3const { launch } = require("qawolf");4const { toMatchImageSnapshot } = require("jest-image-snapshot");5expect.extend({ toMatchImageSnapshot });6describe("test", () => {7 let browser;8 let page;9 beforeAll(async () => {10 browser = await chromium.launch();11 });12 afterAll(async () => {13 await browser.close();14 });15 beforeEach(async () => {16 page = await browser.newPage();17 await assignRunner(page);18 });19 afterEach(async () => {20 await page.close();21 });22 it("test", async () => {23 await page.click("text=Sign in");24 await page.fill("input[name=\"identifier\"]", "test");25 await page.press("input[name=\"identifier\"]", "Enter");26 await page.fill("input[name=\"password\"]", "test");27 await page.press("input[name=\"password\"]", "Enter");28 await page.click("text=Search");29 await page.fill("input[name=\"q\"]", "test");30 await page.press("input[name=\"q\"]", "Enter");
Using AI Code Generation
1const { assignRunner } = require('qawolf');2const { chrome } = require('qawolf');3(async () => {4 const browser = await chrome.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 await assignRunner(page, 'test');8 await page.click('text=Get Started');9 await page.click('text=Login');10 await page.fill('input[name="email"]', '
Using AI Code Generation
1const { assignRunner } = require("qawolf");2assignRunner("testId", "runnerId");3const { assignTest } = require("qawolf");4assignTest("runnerId", "testId");5const { createRunner } = require("qawolf");6createRunner("runnerName");7const { createTest } = require("qawolf");8createTest("testName");9const { deleteRunner } = require("qawolf");10deleteRunner("runnerId");11const { deleteTest } = require("qawolf");12deleteTest("testId");13const { getRunners } = require("qawolf");14getRunners();15const { getTests } = require("qawolf");16getTests();17const { getTest } = require("qawolf");18getTest("testId");19const { getRunner } = require("qawolf");20getRunner("runnerId");21const { renameRunner } = require("qawolf");22renameRunner("runnerId", "newRunnerName");23const { renameTest } = require("qawolf");24renameTest("testId", "newTestName");25const { run } = require("qawolf");26run("testId");27const { updateTest } = require("qawolf");28updateTest("testId", "
Using AI Code Generation
1const { assignRunner } = require("qawolf");2const qawolf = require("qawolf");3const browser = await qawolf.launch();4const context = await browser.newContext();5const page = await context.newPage();6const runner = await assignRunner(page);7const code = await qawolf.create(page, runner);8const code = await qawolf.create(page, runner);9const browser = await qawolf.browser();10const context = await qawolf.context();11const page = await qawolf.page();12await browser.close();13await context.close();14await page.close();15const { assignRunner } = require("qawolf");16const qawolf = require("qawolf");17const browser = await qawolf.launch();18const context = await browser.newContext();19const page = await context.newPage();20const runner = await assignRunner(page);21const code = await qawolf.create(page, runner);22const code = await qawolf.create(page, runner);23const browser = await qawolf.browser();24const context = await qawolf.context();25const page = await qawolf.page();26await browser.close();27await context.close();28await page.close();
Using AI Code Generation
1const { assignRunner } = require("qawolf");2const runner_id = "3b3d3e3f-3g3h-3i3j-3k3l-3m3n3o3p3q3r";3assignRunner(runner_id);4const { create } = require("qawolf");5create();6const { create } = require("qawolf");7create();8const { create } = require("qawolf");9create();10const { create } = require("qawolf");11create();12const { create } = require("qawolf");13create();14const { create } = require("qawolf");15create();16const { create } = require("qawolf");17create();18const { create } = require("qawolf");19create();20const { create } = require("qawolf");21create();22const { create } = require("qawolf");23create();24const { create } = require("qawolf");25create();26const { create } = require("qawolf");27create();
Using AI Code Generation
1const { assignRunner } = require('qawolf');2(async () => {3 await assignRunner({ runnerId: 'runnerId', testId: 'testId' });4})();5const { runTest } = require('qawolf');6(async () => {7 await runTest({ testId: 'testId' });8})();9const { deleteRunner } = require('qawolf');10(async () => {11 await deleteRunner({ runnerId: 'runnerId' });12})();13const { runTest } = require('qawolf');14(async () => {15 await runTest({ testId: 'testId' });16})();17const { deleteRunner } = require('qawolf');18(async () => {19 await deleteRunner({ runnerId: 'runnerId' });20})();
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!!