Best JavaScript code snippet using appium
create.js
Source:create.js
1/**2 * Copyright (c) 2016 Chris Baker <mail.chris.baker@gmail.com>3 *4 * Permission is hereby granted, free of charge, to any person obtaining a copy5 * of this software and associated documentation files (the "Software"), to deal6 * in the Software without restriction, including without limitation the rights7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell8 * copies of the Software, and to permit persons to whom the Software is9 * furnished to do so, subject to the following conditions:10 *11 * The above copyright notice and this permission notice shall be included in12 * all copies or substantial portions of the Software.13 *14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE20 * SOFTWARE.21 *22 */23const assert = require('assert');24const Action = require('..');25Object.defineProperty(Object.prototype, 'ignored', {26 value: 'ignored',27 enumerable: true,28 writable: true29});30describe('creating an action', function () {31 let action;32 let jacks;33 let props;34 function create() {35 return Action.create(action);36 }37 function perform() {38 return create()(jacks, props);39 }40 function error() {41 try {42 perform();43 assert(false, 'Creating the action should throw an error');44 }45 catch (err) {46 return err;47 }48 }49 beforeEach(function () {50 action = {51 jackTypes: { },52 propTypes: { },53 perform: function () { }54 };55 jacks = { };56 props = { };57 });58 it('should return a function', function () {59 assert.equal(typeof create(), 'function');60 });61 describe('without an action', function () {62 beforeEach(function () {63 action = undefined;64 });65 it('should throw an ActionCreateError', function () {66 assert.equal(error().name, 'ActionCreateError');67 });68 it('should have a message', function () {69 assert.equal(error().message, 'An action is required');70 });71 });72 describe('without jack types', function () {73 beforeEach(function () {74 action.jackTypes = undefined;75 action.perform = function (jacks) {76 return jacks;77 };78 });79 it('should default to an empty object', function () {80 assert.deepEqual(perform(), { });81 });82 });83 describe('without prop types', function () {84 beforeEach(function () {85 action.propTypes = undefined;86 action.perform = function (jacks, props) {87 return props;88 };89 });90 it('should default to an empty object', function () {91 assert.deepEqual(perform(), { });92 });93 });94 describe('without a perform function', function () {95 beforeEach(function () {96 action.perform = undefined;97 });98 it('should throw an ActionCreateError', function () {99 assert.equal(error().name, 'ActionCreateError');100 });101 it('should have a message', function () {102 assert.equal(error().message, 'An action perform function is required');103 });104 });105 describe('with an optional property', function () {106 beforeEach(function () {107 action.propTypes.s = Action.Types.string;108 action.perform = function (jacks, props) {109 return props.s;110 };111 props.s = 's';112 });113 it('should perform the action', function () {114 assert.equal(perform(), 's');115 });116 });117 describe('without an optional property', function () {118 beforeEach(function () {119 action.propTypes.s = Action.Types.string;120 action.perform = function (jacks, props) {121 return props.s;122 };123 });124 it('should perform the action', function () {125 assert.equal(perform(), undefined);126 });127 });128 describe('with a required property', function () {129 beforeEach(function () {130 action.propTypes.s = Action.Types.string.isRequired;131 action.perform = function (jacks, props) {132 return props.s;133 };134 props.s = 's';135 });136 it('should perform the action', function () {137 assert.equal(perform(), 's');138 });139 });140 describe('without a required property', function () {141 beforeEach(function () {142 action.propTypes.s = Action.Types.string.isRequired;143 action.perform = function (jacks, props) {144 return props.s;145 };146 });147 it('should throw an ActionValidateError', function () {148 assert.equal(error().name, 'ActionValidateError');149 });150 it('should have a message', function () {151 assert.equal(error().message, 'The action could not be validated');152 });153 it('should have the errors', function () {154 assert.equal(error().errors.props.s, 'Required');155 });156 });157 describe('with a string', function () {158 beforeEach(function () {159 action.propTypes.s = Action.Types.string;160 action.perform = function (jacks, props) {161 return props.s;162 };163 });164 describe('that is valid', function () {165 beforeEach(function () {166 props.s = 's';167 });168 it('should perform the action', function () {169 assert.equal(perform(), 's');170 });171 });172 describe('that is invalid', function () {173 beforeEach(function () {174 props.s = 0;175 });176 it('should throw an ActionValidateError', function () {177 assert.equal(error().name, 'ActionValidateError');178 });179 it('should have a message', function () {180 assert.equal(error().message, 'The action could not be validated');181 });182 it('should have the errors', function () {183 assert.equal(error().errors.props.s,184 'Expected type to be "string" but found "number"');185 });186 });187 });188 describe('with a date', function () {189 beforeEach(function () {190 action.propTypes.d = Action.Types.date;191 action.perform = function (jacks, props) {192 return props.d;193 };194 });195 describe('that is valid', function () {196 beforeEach(function () {197 props.d = '2000-01-01';198 });199 it('should perform the action', function () {200 assert.equal(perform().toISOString(), '2000-01-01T00:00:00.000Z');201 });202 });203 describe('that is invalid', function () {204 beforeEach(function () {205 props.d = 'foo';206 });207 it('should throw an ActionValidateError', function () {208 assert.equal(error().name, 'ActionValidateError');209 });210 it('should have a message', function () {211 assert.equal(error().message, 'The action could not be validated');212 });213 it('should have the errors', function () {214 assert.equal(error().errors.props.d,215 'Expected type to be "date" but found "string"');216 });217 });218 });219 describe('with an email', function () {220 beforeEach(function () {221 action.propTypes.e = Action.Types.email;222 action.perform = function (jacks, props) {223 return props.e;224 };225 });226 describe('that is valid', function () {227 beforeEach(function () {228 props.e = 'john@doe.com';229 });230 it('should perform the action', function () {231 assert.equal(perform(), 'john@doe.com');232 });233 });234 describe('that is invalid', function () {235 beforeEach(function () {236 props.e = 'john';237 });238 it('should throw an ActionValidateError', function () {239 assert.equal(error().name, 'ActionValidateError');240 });241 it('should have a message', function () {242 assert.equal(error().message, 'The action could not be validated');243 });244 it('should have the errors', function () {245 assert.equal(error().errors.props.e,246 'An email address must have a domain');247 });248 });249 });250 describe('with a number', function () {251 beforeEach(function () {252 action.propTypes.n = Action.Types.number;253 action.perform = function (jacks, props) {254 return props.n;255 };256 });257 describe('that is valid', function () {258 beforeEach(function () {259 props.n = 0;260 });261 it('should perform the action', function () {262 assert.equal(perform(), 0);263 });264 });265 describe('that is invalid', function () {266 beforeEach(function () {267 props.n = '';268 });269 it('should throw an ActionValidateError', function () {270 assert.equal(error().name, 'ActionValidateError');271 });272 it('should have a message', function () {273 assert.equal(error().message, 'The action could not be validated');274 });275 it('should have the errors', function () {276 assert.equal(error().errors.props.n,277 'Expected type to be "number" but found "string"');278 });279 });280 });281 describe('with a function', function () {282 beforeEach(function () {283 action.propTypes.f = Action.Types.func;284 action.perform = function (jacks, props) {285 return props.f;286 };287 });288 describe('that is valid', function () {289 beforeEach(function () {290 props.f = function () {291 return 'foo';292 };293 });294 it('should perform the action', function () {295 assert.equal(perform()(), 'foo');296 });297 });298 describe('that is invalid', function () {299 beforeEach(function () {300 props.f = '';301 });302 it('should throw an ActionValidateError', function () {303 assert.equal(error().name, 'ActionValidateError');304 });305 it('should have a message', function () {306 assert.equal(error().message, 'The action could not be validated');307 });308 it('should have the errors', function () {309 assert.equal(error().errors.props.f,310 'Expected type to be "function" but found "string"');311 });312 });313 });314 describe('with a shape', function () {315 beforeEach(function () {316 action.propTypes.o = Action.Types.shape({317 s: Action.Types.string.isRequired,318 n: Action.Types.number.isRequired,319 f: Action.Types.func.isRequired320 });321 action.perform = function (jacks, props) {322 return props.o;323 };324 });325 describe('that is valid', function () {326 beforeEach(function () {327 function Shape() {328 this.s = '';329 this.n = 5;330 }331 Shape.prototype.square = function (n) {332 return n * n;333 };334 Shape.prototype.f = function () {335 return this.square(this.n);336 };337 props.o = new Shape();338 });339 it('should perform the action', function () {340 assert.equal(perform().s, '');341 assert.equal(perform().n, 5);342 assert.equal(perform().f(), 25);343 });344 });345 describe('that is invalid', function () {346 beforeEach(function () {347 props.o = '';348 });349 it('should throw an ActionValidateError', function () {350 assert.equal(error().name, 'ActionValidateError');351 });352 it('should have a message', function () {353 assert.equal(error().message, 'The action could not be validated');354 });355 it('should have the errors', function () {356 assert.equal(error().errors.props.o,357 'Expected type to be "object" but found "string"');358 });359 });360 });361 describe('with a boolean', function () {362 beforeEach(function () {363 action.propTypes.b = Action.Types.bool;364 action.perform = function (jacks, props) {365 return props.b;366 };367 });368 describe('that is valid', function () {369 beforeEach(function () {370 props.b = true;371 });372 it('should perform the action', function () {373 assert.equal(perform(), true);374 });375 });376 describe('that is invalid', function () {377 beforeEach(function () {378 props.b = '';379 });380 it('should throw an ActionValidateError', function () {381 assert.equal(error().name, 'ActionValidateError');382 });383 it('should have a message', function () {384 assert.equal(error().message, 'The action could not be validated');385 });386 it('should have the errors', function () {387 assert.equal(error().errors.props.b,388 'Expected type to be "boolean" but found "string"');389 });390 });391 });392 describe('with an array', function () {393 beforeEach(function () {394 action.propTypes.a = Action.Types.array;395 action.perform = function (jacks, props) {396 return props.a;397 };398 });399 describe('that is valid', function () {400 beforeEach(function () {401 props.a = [];402 });403 it('should perform the action', function () {404 assert.deepEqual(perform(), []);405 });406 });407 describe('that is invalid', function () {408 beforeEach(function () {409 props.a = '';410 });411 it('should throw an ActionValidateError', function () {412 assert.equal(error().name, 'ActionValidateError');413 });414 it('should have a message', function () {415 assert.equal(error().message, 'The action could not be validated');416 });417 it('should have the errors', function () {418 assert.equal(error().errors.props.a,419 'Expected type to be "array" but found "string"');420 });421 });422 });423 describe('with a custom validator', function () {424 beforeEach(function () {425 action.propTypes.n = Action.Types.number.optional(function (n) {426 if (n & 1) {427 throw new Error('Expected number to be even');428 }429 return n / 2;430 });431 action.perform = function (jacks, props) {432 return props.n;433 };434 });435 describe('that passes', function () {436 beforeEach(function () {437 props.n = 6;438 });439 it('should return the result', function () {440 assert.equal(perform(), 3);441 });442 });443 describe('that fails', function () {444 beforeEach(function () {445 props.n = 7;446 });447 it('should throw an ActionValidateError', function () {448 assert.equal(error().name, 'ActionValidateError');449 });450 it('should have a message', function () {451 assert.equal(error().message, 'The action could not be validated');452 });453 it('should have the errors', function () {454 assert.equal(error().errors.props.n, 'Expected number to be even');455 });456 });457 });458 describe('without a default jack', function () {459 beforeEach(function () {460 action.jackTypes.n = Action.Types.number.isRequired;461 action.getDefaultJacks = function () {462 return { n: 42 };463 };464 action.perform = function (jacks) {465 return jacks.n;466 };467 });468 it('should use the default', function () {469 assert.deepEqual(perform(), 42);470 });471 });472 describe('with a default jack', function () {473 beforeEach(function () {474 action.jackTypes.n = Action.Types.number.isRequired;475 action.getDefaultJacks = function () {476 return { n: 42 };477 };478 action.perform = function (jacks) {479 return jacks.n;480 };481 jacks.n = 13;482 });483 it('should use the supplied value', function () {484 assert.deepEqual(perform(), 13);485 });486 });487 describe('without a default prop', function () {488 beforeEach(function () {489 action.propTypes.n = Action.Types.number.isRequired;490 action.getDefaultProps = function () {491 return { n: 42 };492 };493 action.perform = function (jacks, props) {494 return props.n;495 };496 });497 it('should use the default', function () {498 assert.deepEqual(perform(), 42);499 });500 });501 describe('with a default prop', function () {502 beforeEach(function () {503 action.propTypes.n = Action.Types.number.isRequired;504 action.getDefaultProps = function () {505 return { n: 42 };506 };507 action.perform = function (jacks, props) {508 return props.n;509 };510 props.n = 13;511 });512 it('should use the supplied value', function () {513 assert.deepEqual(perform(), 13);514 });515 });516 describe('without jacks', function () {517 beforeEach(function () {518 jacks = undefined;519 action.perform = function (jacks) {520 return jacks;521 };522 });523 it('should default to an empty object', function () {524 assert.deepEqual(perform(), { });525 });526 });527 describe('without props', function () {528 beforeEach(function () {529 props = undefined;530 action.perform = function (jacks, props) {531 return props;532 };533 });534 it('should default to an empty object', function () {535 assert.deepEqual(perform(), { });536 });537 });...
SaveAsActionSpec.js
Source:SaveAsActionSpec.js
...155 expect(SaveAsAction.appliesTo(actionContext)).toBe(false);156 });157 it("uses the editor capability to save the object", function () {158 mockEditorCapability.save.and.returnValue(Promise.resolve());159 return action.perform().then(function () {160 expect(mockEditorCapability.save).toHaveBeenCalled();161 });162 });163 it("uses the editor capability to finish editing the object", function () {164 return action.perform().then(function () {165 expect(mockEditorCapability.finish.calls.count()).toBeGreaterThan(0);166 });167 });168 it("returns to browse after save", function () {169 spyOn(action, "save");170 action.save.and.returnValue(mockPromise(mockDomainObject));171 action.perform();172 expect(mockActionCapability.perform).toHaveBeenCalledWith(173 "navigate"174 );175 });176 it("prompts the user for object details", function () {177 action.perform();178 expect(mockDialogService.getUserInput).toHaveBeenCalled();179 });180 describe("in order to keep the user in the loop", function () {181 var mockDialogHandle;182 beforeEach(function () {183 mockDialogHandle = jasmine.createSpyObj("dialogHandle", ["dismiss"]);184 mockDialogService.showBlockingMessage.and.returnValue(mockDialogHandle);185 });186 it("shows a blocking dialog indicating that saving is in progress", function () {187 mockEditorCapability.save.and.returnValue(new Promise(function () {}));188 action.perform();189 expect(mockDialogService.showBlockingMessage).toHaveBeenCalled();190 expect(mockDialogHandle.dismiss).not.toHaveBeenCalled();191 });192 it("hides the blocking dialog after saving finishes", function () {193 return action.perform().then(function () {194 expect(mockDialogService.showBlockingMessage).toHaveBeenCalled();195 expect(mockDialogHandle.dismiss).toHaveBeenCalled();196 });197 });198 it("notifies if saving succeeded", function () {199 return action.perform().then(function () {200 expect(mockNotificationService.info).toHaveBeenCalled();201 expect(mockNotificationService.error).not.toHaveBeenCalled();202 });203 });204 it("notifies if saving failed", function () {205 mockCopyService.perform.and.returnValue(Promise.reject("some failure reason"));206 action.perform().then(function () {207 expect(mockNotificationService.error).toHaveBeenCalled();208 expect(mockNotificationService.info).not.toHaveBeenCalled();209 });210 });211 });212 });213 }...
CreateActionSpec.js
Source:CreateActionSpec.js
...133 beforeEach(function () {134 capabilities.action.getActions.and.returnValue([mockEditAction]);135 });136 it("uses the instantiation capability when performed", function () {137 action.perform();138 expect(mockParent.useCapability).toHaveBeenCalledWith("instantiation", jasmine.any(Object));139 });140 it("uses the edit action if available", function () {141 action.perform();142 expect(mockEditAction.perform).toHaveBeenCalled();143 });144 it("uses the save-as action if object does not have an edit action" +145 " available", function () {146 capabilities.action.getActions.and.returnValue([]);147 capabilities.action.perform.and.returnValue(mockPromise(undefined));148 capabilities.editor.save.and.returnValue(promise);149 action.perform();150 expect(capabilities.action.perform).toHaveBeenCalledWith("save-as");151 });152 describe("uses to editor capability", function () {153 beforeEach(function () {154 capabilities.action.getActions.and.returnValue([]);155 capabilities.action.perform.and.returnValue(promise);156 capabilities.editor.save.and.returnValue(promise);157 });158 it("to save the edit if user saves dialog", function () {159 action.perform();160 expect(promise.then).toHaveBeenCalled();161 promise.then.calls.mostRecent().args[0]();162 expect(capabilities.editor.save).toHaveBeenCalled();163 });164 it("to finish the edit if user cancels dialog", function () {165 action.perform();166 promise.then.calls.mostRecent().args[1]();167 expect(capabilities.editor.finish).toHaveBeenCalled();168 });169 });170 });171 });172 }...
CancelActionSpec.js
Source:CancelActionSpec.js
...110 " performed", function () {111 mockDomainObject.getModel.and.returnValue({persisted: 1});112 //Return true from navigate action113 capabilities.action.perform.and.returnValue(mockPromise(true));114 action.perform();115 // Should have called finish116 expect(capabilities.editor.finish).toHaveBeenCalled();117 // Definitely shouldn't call save!118 expect(capabilities.editor.save).not.toHaveBeenCalled();119 });120 it("navigates to object if existing using navigate action", function () {121 mockDomainObject.getModel.and.returnValue({persisted: 1});122 //Return true from navigate action123 capabilities.action.perform.and.returnValue(mockPromise(true));124 action.perform();125 expect(capabilities.action.perform).toHaveBeenCalledWith("navigate");126 });127 it("navigates to parent if new using navigate action", function () {128 mockDomainObject.getModel.and.returnValue({persisted: undefined});129 action.perform();130 expect(parentCapabilities.action.perform).toHaveBeenCalledWith("navigate");131 });132 });133 }...
Utils.js
Source:Utils.js
1/**2 * Classe util pour créer facilement des elements du monde3 */4var Utils = function () {5 this.loader = new THREE.JSONLoader();6}7/**8 * Creation du skybox9 * @return nothing10 */11Utils.prototype.createWorld = function () {12 var utils = this;13 this.loader.load("/javascripts/Maps/bgd2.js", function (geometry, materials) {14 var mesh = new THREE.Mesh(geometry, new THREE.MeshFaceMaterial(materials));15 mesh.name = "bgdCube";16 mesh.material.depthWrite = false;17 mesh.receiveShadow = false;18 mesh.scale.set(-2000, -2000, -2000);19 window.scene.add(mesh);20 });21}22/**23 * Créé des astéroides24 * @param {[number]} position tableau de position25 * @param {[number]} rotation tableau de rotation26 * @param {[number]} scale tableau d'échelle27 * @param {[function]} collision_action_perform handler de collision28 * @return {[]}29 */30Utils.prototype.createAsteroid = function (position, rotation, scale, collision_action_perform) {31 var utils = this;32 loader.load("/javascripts/Maps/asteroid.js", function (geometry, materials) {33 var mesh = new Physijs.BoxMesh(geometry, new THREE.MeshFaceMaterial(materials), 10000 * weight);34 mesh.position = position;35 mesh.rotation = rotation;36 mesh.scale = scale;37 mesh.receiveShadow = true;38 mesh.castShadow = true;39 mesh.name = "asteroid";40 mesh.addEventListener('collision', function (other_object, relative_velocity, relative_rotation, contact_normal) {41 utils.collision_action_perform(this, other_object);42 });43 scene.add(mesh);44 });45};46/**47 * Créé un vaisseau (pas la map vaisseau)48 * @param {number} position position49 * @param {number} rotation rotation50 * @param {number} scale échelle51 * @param {function} collision_action_perform handler de collision52 * @return {nothing}53 */54Utils.prototype.createShip = function (position, rotation, scale, collision_action_perform) {55 var utils = this;56 loader.load('/javascripts/Maps/ship.js', function (geometry, materials) {57 var mesh = new Physijs.BoxMesh(geometry, new THREE.MeshFaceMaterial(materials), 1e10);58 mesh.rotation = rotation;59 mesh.position = position;60 mesh.scale = scale;61 mesh.material.shading = THREE.FlatShading;62 mesh.receiveShadow = true;63 mesh.castShadow = true;64 mesh.addEventListener('collision', function (other_object) {65 utils.collision_action_perform(this, other_object);66 })67 scene.add(mesh);68 })69}70/**71 * Créé un loot72 * @param {number} position position73 * @param {number} rotation rotation74 * @param {number} scale scale75 * @param {string} type Type d'objet a crééer76 * @param {function} collision_action_perform handler de collision77 * @return {nothing}78 */79Utils.prototype.createLoot = function (position, rotation, scale, type, collision_action_perform) {80 var utils = this;81 var texture, mesh;82 texture = THREE.ImageUtils.loadTexture('/javascripts/Maps/' + type + '.jpg');83 mesh = new Physijs.BoxMesh(cube,84 new THREE.MeshLambertMaterial({85 map: texture86 }),87 0);88 mesh.name = "toHighlight";89 mesh.position = position;90 mesh.rotation = rotation;91 mesh.scale = scale;92 mesh.position.y += 1;93 mesh.addEventListener('collision', function (other_object, relative_velocity, relative_rotation, contact_normal) {94 utils.collision_action_perform(this, other_object, relative_velocity, relative_rotation, contact_normal);95 })96 window.scene.add(mesh);97}98/**99 * Handler de collision100 * @param {Mesh} first_object Object appelant la fonction101 * @param {Mesh} second_object Object en relation avec l'appelant102 * @return {nothing}103 */104Utils.prototype.collision_action_perform = function (first_object, second_object, relative_velocity, relative_rotation, contact_normal) {105 var utils = this;106 //TODO big switch107 if (first_object.name === "asteroid"){108 if (second_object.name === "bullet") {109 }110 }111 if (first_object.name === "wall_breakable"){112 if (second_object.name === "bullet") {113 first_object.life--;114 if (first_object.life === 0) {115 window.scene.remove(first_object); 116 //Création de petit bout de mur117 var i = 5;118 while (i--) {119 var miniwall = new Physijs.BoxMesh(120 new THREE.CubeGeometry(10, 10, 10),121 new THREE.MeshLambertMaterial({122 map: THREE.ImageUtils.loadTexture('/javascripts/Maps/shiphull-Porte2.jpg')123 }),124 10125 );126 var nb = Math.random();127 var signe = "";128 if (nb >= 0.5)129 signe = 1;130 else131 signe = -1132 miniwall.position.x = first_object.position.x + (Math.random() * signe);133 miniwall.position.y = first_object.position.y + (Math.random() * signe);134 miniwall.position.z = first_object.position.z + (Math.random() * signe);135 136 scene.add(miniwall);137 }138 }139 } 140 }141 if (first_object.name === "mechant_robot"){142 if (second_object.name === "bullet") 143 }144 if (first_object.name === "super_mechant_robot"){145 if (second_object.name === "bullet") 146 }147 148}149if (typeof module !== 'undefined' && typeof module.exports !== 'undefined')150 module.exports = Utils;151else...
EditAndComposeActionSpec.js
Source:EditAndComposeActionSpec.js
...86 };87 action = new EditAndComposeAction(actionContext);88 });89 it("adds to the parent's composition when performed", function () {90 action.perform();91 expect(mockComposition.add)92 .toHaveBeenCalledWith(mockDomainObject);93 });94 it("enables edit mode for objects that have an edit action", function () {95 mockActionCapability.getActions.and.returnValue([mockEditAction]);96 action.perform();97 expect(mockEditAction.perform).toHaveBeenCalled();98 });99 it("Does not enable edit mode for objects that do not have an" +100 " edit action", function () {101 mockActionCapability.getActions.and.returnValue([]);102 action.perform();103 expect(mockEditAction.perform).not.toHaveBeenCalled();104 expect(mockComposition.add)105 .toHaveBeenCalledWith(mockDomainObject);106 });107 });108 }...
MakeAndModelFilter.js
Source:MakeAndModelFilter.js
1class MakeAndModelFilter{2 _makeAndModelButtonLocator = 'span*=MAKE & MODEL';3 _makeLogoWrapperLocator = '.make-logo-select-wrap';4 _applyFilterButtonLocator ='[data-qa=styled-modal] [class*=ApplyFiltersButton]'5 _trimsTextLocator = Selector.getByQa('trims-text');6 _makeAndModelTextLocator = Selector.getByQa('make-model-text');7 _selectorCheckmarkLocator = Selector.getByQa('checkmark');8 _selectAllTrimLocator = '.select-all-trims';9 _backToModelsButtonLocator = '.back-to-models';10 _backToMakesButtonLocator = '.back-to-makes';11 12 get getCarMakeAndModelTabPO() {13 return (async () => await Action.getPageObject(this._makeAndModelButtonLocator))();14 }15 get getCarMakeLogoWrapperPO() {16 return (async () => await Action.getPageObject(this._makeLogoWrapperLocator))();17 }18 get getApplyFilterButtonPO() {19 return (async () =>20 await Action.getPageObject(21 this._applyFilterButtonLocator22 ))();23 }24 get getCarTrimTextPO() {25 return (async () =>26 await Action.getPageObject(this._trimsTextLocator))();27 }28 get getCarMakeModelTextPO() {29 return (async () =>30 await Action.getPageObject(this._makeAndModelTextLocator, true))();31 }32 get getCheckMarksPO() {33 return (async () =>34 await Action.getPageObject(this._selectorCheckmarkLocator, true))();35 }36 get getCheckMarkPO() {37 return (async () =>38 await Action.getPageObject(this._selectorCheckmarkLocator, false, 0))();39 }40 get getAllSelectedTrimsPO() {41 return (async () =>42 await Action.getPageObject(this._selectAllTrimLocator, false, 0))();43 }44 get getBackToModelsButton() {45 return (async () =>46 await Action.getPageObject(this._backToModelsButtonLocator, false, 0))();47 }48 get getBackToMakesButton() {49 return (async () =>50 await Action.getPageObject(this._backToMakesButtonLocator, false, 0))();51 }52 async clickMakeAndModelButton() {53 await Action.performClick(await this.getCarMakeAndModelTabPO);54 }55 56 async clickApplyFilterButton() {57 await Action.performClick(await this.getApplyFilterButtonPO);58 await browser.pause(Constants.defaultWait);59 }60 async clickMake(name) {61 await Action.performClick(await this.make(name));62 }63 async clickModel(name) {64 await Action.performClick(await this.make(name));65 }66 async scrollToTop() {67 await Action.scrollToView(await this.getCarMakeLogoWrapperPO);68 }69 async make(name) {70 const makeAndModel = await Action.getPageObject(`.make-model-text=${name}`);71 return await makeAndModel.$('div');72 }73 async model(name) {74 return this.make(name);75 }76 async getObjectByText(text) {77 return await Action.getPageObject(`*=${text}`, false, 0);78 }79 async clickViewTrims() {80 await Action.performClick(await this.getCarTrimTextPO);81 await browser.pause(Constants.defaultWait);82 }83 async clickText(text) {84 await Action.performClick(await this.getObjectByText(text));85 await browser.pause(Constants.defaultWait);86 }87 async clickBackToMakeButton() {88 await Action.performClick(await this.getBackToMakesButton);89 }90 async clickBackToModelsButton() {91 await Action.performClick(await this.getBackToModelsButton);92 }93 async clickTrimCountByTrimText(text) {94 const trims = await Action.getPageObject(95 this._makeAndModelTextLocator,96 5000,97 true98 );99 // eslint-disable-next-line no-restricted-syntax100 for (const trim of trims) {101 const trimType = await trim.getText();102 if (trimType === text) {103 await Action.performClick(trim);104 }105 }106 }107 async getTrimCountByTrimText(text) {108 let count = 0;109 const trims = await this.getCarMakeModelTextPO;110 // eslint-disable-next-line no-restricted-syntax111 for (const trim of trims) {112 const trimType = await trim.getText();113 if (trimType === text) {114 count += 1;115 }116 }117 return count;118 }119 async isTextVisible(text) {120 return await Action.isPageObjectVisible(await this.getObjectByText(text));121 }122 async isSelectAllTrimsVisible() {123 return await Action.isPageObjectVisible(await this.getAllSelectedTrimsPO);124 }125 async countVisibleCheckMarks() {126 const checkMarks = await this.getCheckMarksPO;127 return checkMarks.length;128 }129 async isCheckMarkVisible() {130 return await Action.isPageObjectVisible(await this.getCheckMarkPO);131 }132 133 async isMakeAndModeldWrapperVisible() {134 return await Action.isPageObjectVisible(135 await await Action.getPageObject(136 Selector.getByQa('mobile-list'),137 false,138 0139 )140 );141 }142}...
index.js
Source:index.js
1// server/index.js2const express = require("express");3var fs = require('fs'); 4var _ = require('lodash');5const bodyParser = require('body-parser');6const path = require("path");7var userJSON = require('../../src/data/reports.json');8910const PORT = process.env.PORT || 3001;1112const app = express();1314app.use(bodyParser.json());1516app.listen(PORT, () => {17 console.log(`Server listening on ${PORT}`);18});1920app.put("/reports/:reportId", (req, res) => {21 // console.log(req);22 if(req.params.reportId) {2324 // Check req.body.actionPerform is resolve or block and get id.25 var reportId = req.params.reportId.split(":")[1];2627 if(req.body.actionPerform === "Block") {28 29 var returnedObj = _.find(userJSON.elements, {id: reportId});30 31 // Find item index using _.findIndex 32 var index = _.findIndex(userJSON.elements, {id: reportId});3334 returnedObj.ticketState = "CLOSED";35 36 // Replace item at index using native splice37 userJSON.elements.splice(index, 1, returnedObj);38 39 console.log("reportId ", reportId);40 console.log("actionPerform ", req.body.actionPerform);4142 // Write new changes to the reports.json file.43 fs.writeFileSync(path.resolve(__dirname, '../../src/data/reports.json'), JSON.stringify(userJSON));44 res.json({message: "Success"});45 } else {46 var returnedObj = _.find(userJSON.elements, {id: reportId});47 48 // Find item index using _.findIndex 49 var index = _.findIndex(userJSON.elements, {id: reportId});5051 returnedObj.ticketState = "RESOLVED";52 53 // Replace item at index using native splice54 userJSON.elements.splice(index, 1, returnedObj);55 56 console.log("reportId ", reportId);57 console.log("actionPerform ", req.body.actionPerform);5859 // Write new changes to the reports.json file.60 fs.writeFileSync(path.resolve(__dirname, '../../src/data/reports.json'), JSON.stringify(userJSON));61 res.json({message: "Success"});62 }63 } else {64 res.json({message: "Not a valid id"});65 }6667});
...
Using AI Code Generation
1var wdio = require('webdriverio');2var options = {3 desiredCapabilities: {4 }5};6 .remote(options)7 .init()8 .title(function(err, res) {9 console.log('Title was: ' + res.value);10 })11 .end();12var wdio = require('webdriverio');13var options = {14 desiredCapabilities: {15 }16};17 .remote(options)18 .init()19 .title(function(err, res) {20 console.log('Title was: ' + res.value);21 })22 .end();23var wdio = require('webdriverio');24var options = {25 desiredCapabilities: {26 }27};28 .remote(options)29 .init()30 .title(function(err, res) {31 console.log('Title was: ' + res.value);32 })33 .end();34var wdio = require('webdriverio');35var options = {36 desiredCapabilities: {37 }38};39 .remote(options)40 .init()41 .title(function(err, res) {42 console.log('Title was: ' + res.value);43 })44 .end();45var wdio = require('webdriverio');46var options = {47 desiredCapabilities: {48 }49};50 .remote(options)51 .init()52 .title(function(err, res) {53 console.log('Title was: ' + res.value);54 })55 .end();
Using AI Code Generation
1let action = new wd.TouchAction(driver);2action.press({x: 100, y: 100})3 .moveTo({x: 200, y: 200})4 .release();5action.perform();6let action = new wd.TouchAction(driver);7action.tap({x: 100, y: 100})8 .perform();9let action = new wd.TouchAction(driver);10action.longPress({x: 100, y: 100})11 .release()12 .perform();13let action = new wd.TouchAction(driver);14action.tap({x: 100, y: 100})15 .perform();16let action = new wd.TouchAction(driver);17action.longPress({x: 100, y: 100})18 .release()19 .perform();20let action = new wd.TouchAction(driver);21action.tap({x: 100, y: 100})22 .perform();23let action = new wd.TouchAction(driver);24action.longPress({x: 100, y: 100})25 .release()26 .perform();27let action = new wd.TouchAction(driver);28action.tap({x: 100, y: 100})29 .perform();30let action = new wd.TouchAction(driver);31action.longPress({x: 100, y: 100})32 .release()33 .perform();34let action = new wd.TouchAction(driver);35action.tap({x: 100, y: 100})36 .perform();37let action = new wd.TouchAction(driver);38action.longPress({x: 100, y: 100})39 .release()40 .perform();41let action = new wd.TouchAction(driver);42action.tap({x: 100, y: 100})43 .perform();
Using AI Code Generation
1var action = driver.perform();2action.tap({x: 100, y: 100}).perform();3action.longPress({x: 100, y: 100}).perform();4action.moveTo({x: 100, y: 100}).perform();5action.release({x: 100, y: 100}).perform();6action.wait({ms: 1000}).perform();7action.press({x: 100, y: 100}).perform();8action.moveTo({x: 100, y: 100}).perform();9action.release({x: 100, y: 100}).perform();10action.perform();11var action = driver.perform();12action.tap({x: 100, y: 100}).perform();13action.longPress({x: 100, y: 100}).perform();14action.moveTo({x: 100, y: 100}).perform();15action.release({x: 100, y: 100}).perform();16action.wait({ms: 1000}).perform();17action.press({x: 100, y: 100}).perform();18action.moveTo({x: 100, y: 100}).perform();19action.release({x: 100, y: 100}).perform();20action.perform();
Using AI Code Generation
1var action = new wd.TouchAction(driver);2action.tap({el: el, x: 100, y: 100});3action.perform();4driver.quit();5var action = new wd.TouchAction(driver);6action.tap({el: el, x: 100, y: 100});7action.release();8driver.quit();9var action = new wd.TouchAction(driver);10action.tap({el: el, x: 100, y: 100});11action.wait(1000);12driver.quit();13var action = new wd.TouchAction(driver);14action.tap({el: el, x: 100, y: 100});15action.moveTo({el: el, x: 200, y: 200});16driver.quit();17var action = new wd.TouchAction(driver);18action.tap({el: el, x: 100, y: 100});19action.scroll({el: el, x: 200, y: 200});20driver.quit();21var action = new wd.TouchAction(driver);22action.tap({el: el, x: 100, y: 100});23action.scrollFromElement({el: el, x: 200, y: 200});24driver.quit();25var action = new wd.TouchAction(driver);26action.tap({el: el, x: 100, y: 100});27action.longPress({el: el, x: 200, y: 200});28driver.quit();
Using AI Code Generation
1action.perform();2action.perform();3action.perform();4action.perform();5action.moveToElement(startX, startY, endX, endY).release().perform();6action.moveToElement(startX, startY, endX, endY).release().perform();7action.moveToElement(startX, startY, endX, endY).release().perform();8action.moveToElement(startX, startY, endX, endY).release().perform();9action.press(startX, startY).moveTo(endX, endY).release().perform();10action.press(startX, startY).moveTo(endX, endY).release().perform();11action.press(startX, startY).moveTo(endX, endY).release().perform();12action.press(startX, startY).moveTo(endX, endY).release().perform();13action.press(startX, startY).waitAction(waitTime).moveTo(endX, endY).release().perform();14action.press(startX, startY).waitAction(waitTime).moveTo(endX, endY).release().perform();15action.press(startX, startY).waitAction(waitTime).moveTo(endX, endY).release().perform();16action.press(startX, startY).waitAction(waitTime).moveTo(endX, endY).release().perform();17action.press(startX, startY).wait
Using AI Code Generation
1driver.perform(function() {2 driver.elementByAccessibilityId('showAlert').click();3 driver.elementByAccessibilityId('OK').click();4});5driver.elementByAccessibilityId('showAlert').click();6driver.elementByAccessibilityId('OK').click();7driver.elementByAccessibilityId('showAlert').click();8driver.elementByAccessibilityId('OK').click();9driver.elementByAccessibilityId('showAlert').click();10driver.elementByAccessibilityId('OK').click();11driver.elementByAccessibilityId('showAlert').click();12driver.elementByAccessibilityId('OK').click();13driver.elementByAccessibilityId('showAlert').click();14driver.elementByAccessibilityId('OK').click();15driver.elementByAccessibilityId('showAlert').click();16driver.elementByAccessibilityId('OK').click();17driver.perform(function() {18 driver.elementByAccessibilityId('showAlert').click();19 driver.elementByAccessibilityId('OK').click();20});21driver.elementByAccessibilityId('showAlert').click();22driver.elementByAccessibilityId('OK').click();23driver.elementByAccessibilityId('showAlert').click();24driver.elementByAccessibilityId('OK').click();25driver.elementByAccessibilityId('showAlert').click();26driver.elementByAccessibilityId('OK').click();27driver.elementByAccessibilityId('showAlert').click();
Using AI Code Generation
1var driver = require('driver');2var assert = require('assert');3var wd = require('wd');4var should = require('should');5var _ = require('underscore');6var Q = require('q');7var desired = {8};9var driver = wd.promiseChainRemote('localhost', 4723);10 .init(desired)11 .setImplicitWaitTimeout(5000)12 .elementByClassName('android.widget.TextView')13 .click()14 .elementByName('App')15 .click()
Using AI Code Generation
1var element = driver.findElement(By.id("element_id"));2var action = new Actions(driver);3action.longPress(element).perform();4var element = driver.findElement(By.id("element_id"));5var action = new Actions(driver);6action.doubleTap(element).perform();7var element = driver.findElement(By.id("element_id"));8var action = new Actions(driver);9action.contextClick(element).perform();10var element = driver.findElement(By.id("element_id"));11var action = new Actions(driver);12action.dragAndDrop(element, target).perform();13var element = driver.findElement(By.id("element_id"));14var action = new Actions(driver);15action.moveToElement(element).perform();16var element = driver.findElement(By.id("element_id"));17var action = new Actions(driver);18action.press(element).release().perform();19var element = driver.findElement(By.id("element_id"));20var action = new Actions(driver);21action.keyDown(element, Key.CONTROL).perform();22var element = driver.findElement(By.id("element_id"));23var action = new Actions(driver);24action.keyUp(element, Key.CONTROL).perform();25var element = driver.findElement(By.id("element_id"));26var action = new Actions(driver);27action.sendKeys(element, "test").perform();28var element = driver.findElement(By.id("element_id"));29var action = new Actions(driver);30action.clickAndHold(element).perform();31var element = driver.findElement(By.id("element_id"));32var action = new Actions(driver);33action.release(element).perform();34var element = driver.findElement(By.id("element_id"));35var action = new Actions(driver);36action.sendKeys(element, "test").perform();
Using AI Code Generation
1var driver = wd.promiseChainRemote();2driver.init(desired).then(function(){3 driver.performTouchAction([4 {action: 'press', x: 100, y: 200},5 {action: 'moveTo', x: 100, y: 400},6 {action: 'release'}7 ]);8});9driver.quit();10info: [debug] Pushing command to appium work queue: "au.getElementByAccessibilityId('test')"11info: [debug] Sending command to instruments: au.getElementByAccessibilityId('test')12info: [debug] [INST] 2015-06-26 13:36:11 +0000 Debug: Got new command 9 from instruments: au.getElementByAccessibilityId('test')13info: [debug] [INST] 2015-06-26 13:36:11 +0000 Debug: evaluating au.getElementByAccessibilityId('test')14info: [debug] Socket data received (25 bytes)15info: [debug] Got result from instruments: {"status":7,"value":"No element found"}16info: [debug] Responding to client with error: {"status":7,"value":{"message":"An element could not be
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!!