Best JavaScript code snippet using taiko
HighLightMessageRub.js
Source:HighLightMessageRub.js
1/**2 * Currently HighLightMessageRub just only contains messages get from responsed server command "hm" 3 * 4 * @export5 * @class HighLightMessageRub6 */7export default class HighLightMessageRub {8 constructor() {9 this.messages = {};10 this.intervalTimer = null;11 this.highLightNode = null;12 13 this._currentIndex = 0;14 }15 16 //TODO17 // addEventListeners() {18 // app.system.on('2lightmessage_updated', this._onHLMUpdated);19 // }20 21 // removeEventListeners() {22 // app.system.off('2lightmessage_updated', this._onHLMUpdated);23 // }24 25 // message: {msg, rc}26 pushMessage(message) {27 let updated = false;28 // if(this.messages[message.msg]) {29 // updated = this.getRepeatCount(this.messages[message.msg]) != message.rc;30 // }31 this.setMessage(message, updated);32 }33 getMessages() {34 return this.messages;35 }36 37 getMessage() {38 return this.getFirstMessage();39 }40 41 getFirstMessage() {42 let firstKey = Object.keys(this.messages)[this._currentIndex];43 return firstKey && this.messages[firstKey];44 }45 46 setMessage(message, updated = false) {47 this.messages[message.msg] = {48 msg: message.msg,49 rc: message.rc,50 updated51 };52 // if(updated) {53 // app.system.emit('2lightmessage_updated', this.messages[message.msg]);54 // }55 }56 57 getRepeatCount(message) {58 return message.rc;59 }60 61 getLastMessage() {62 let lastKey = Object.keys(this.messages)[Object.keys(this.messages).length - 1];63 return lastKey && this.messages[lastKey];64 }65 66 removeMessage(message) {67 if(message.rc == 0) {68 this.messages[message.msg] = null;69 delete this.messages[message.msg];70 }71 }72 73 runMessage(intervalTimer, highLightNode) {74 if(this.isEmptyStack()){75 intervalTimer.pause()76 return;77 }78 if(intervalTimer.isPaused())79 intervalTimer.resume()80 81 let hlm = this.getMessage();82 83 if(this._currentIndex >= Object.keys(this.messages).length) {84 this._currentIndex = 0;85 } else {86 this._currentIndex ++;87 }88 89 /**90 * hlm -> pause interval -> display message -> resume -> hlm91 */92 if (hlm && highLightNode && intervalTimer) {93 this.intervalTimer = intervalTimer;94 this.highLightNode = highLightNode;95 96 // pause timer97 this.intervalTimer.pause();98 99 // show hight light100 let txt = this.highLightNode.getComponent(cc.RichText) || this.highLightNode.getComponent(cc.label);101 // update text102 txt.string = hlm.msg; 103 104 this._runAnim(hlm);105 }106 }107 108 isEmptyStack() {109 return Object.keys(this.messages).length === 0;110 }111 112 _runAnim(hlm) {113 if(!this.highLightNode || !this.intervalTimer)114 return;115 let txtWidth = this.highLightNode.getContentSize().width;116 let montorWidth = cc.director.getWinSize().width;117 let nodePositionY = this.highLightNode.getPosition().y;118 let movingTime = (txtWidth + montorWidth / 2) / 85;119 let endPosition = cc.v2(0 - txtWidth - montorWidth / 2, nodePositionY);120 let action = cc.moveTo(movingTime, endPosition);121 122 let startPosition = cc.v2(this.highLightNode.getPosition());123 this._resetHighLightPosition();124 let rp = cc.sequence(action, cc.callFunc(() => {125 this.highLightNode.setPosition(startPosition);126 // if complete counting, resume timer interval127 hlm.rc--;128 this.removeMessage(hlm);129 this.intervalTimer.resume();130 }));131 this.highLightNode.runAction(rp); 132 }133 134 _onHLMUpdated(message) {135 if(message.updated) {136 this._resetHighLightPosition();137 this._runAnim(message);138 message.updated = false;139 }140 }141 142 _resetHighLightPosition() {143 if(!this.highLightNode)144 return;145 146 let startPosition = cc.v2(this.highLightNode.getPosition());147 this.highLightNode.stopAllActions();148 this.highLightNode.setPosition(startPosition);149 }...
traverse.js
Source:traverse.js
1/*------------------------------------------------------------------------2 * Traverser does a depth-first traversal of every node in the DOM tree3 * and turns it into a linear list, to which it maintains an internal4 * pointer. Call traverser.next() to return the next node in sequence.5 * We only spider document.body because we're not interested in6 * the <head>.7 *-----------------------------------------------------------------------*/8function Traverser()9{10 this.nodeList = [];11 this.delay = 500;12 this.index = 0;13 div = document.createElement("div");14 div.id = "highlight";15 document.body.appendChild(div);16 this.highlightNode = $("#highlight");17 this.highlightNode.css("position", "absolute");18 this.highlightNode.css("background", "rgba(0, 0, 0, 0.5)");19 this.highlightNode.css("color", "white");20 this.highlightNode.css("font", "11px helvetica");21 this.highlightNode.css("font-weight", "bold");22};23Traverser.prototype.traverse = function(element)24{25 traverser = this;26 27 if (element.nodeType == 1 || element.nodeType == 9)28 {29 /*------------------------------------------------------------------------30 * avoid iframes or we'll run into XSS security problems31 *-----------------------------------------------------------------------*/32 if (element.tagName.toLowerCase() == "iframe")33 return;34 el = $(element);35 el.contents().each(function()36 {37 child = this;38 if (child.nodeType == 1 || child.nodeType == 9)39 {40 traverser.nodeList.push(this);41 traverser.traverse(child);42 }43 });44 }45 return this.nodeList;46};47Traverser.prototype.next = function()48{49 var rv = this.nodeList[this.index];50 this.index = (this.index + 1) % this.nodeList.length;51 return rv;52};53Traverser.prototype.play = function(callback)54{55 this.iterateNodes(this.nodeList, callback)56};57Traverser.prototype.highlight = function(node)58{59 var rect = node.getBoundingClientRect();60 this.highlightNode.offset({ "left" : rect.left + window.pageXOffset, "top" : rect.top + window.pageYOffset });61 this.highlightNode.width(rect.right - rect.left);62 this.highlightNode.height(rect.bottom - rect.top);63 this.highlightNode.css("background", $(node).css("color"));64 this.highlightNode.text(node.tagName);...
tree.ts
Source:tree.ts
1'use strict';2import { Highlightable, SearchLocation } from './highlight'3import { TreeDataProvider, TreeItem, Event, EventEmitter, Command } from 'vscode'4class HighlightTreeProvider implements TreeDataProvider<HighlightNode> {5 public currentExpression: string6 public currentIndex: SearchLocation7 private _onDidChangeTreeData: EventEmitter<any> = new EventEmitter<any>();8 readonly onDidChangeTreeData: Event<any> = this._onDidChangeTreeData.event;9 10 constructor(public words: Highlightable[]) {}11 getTreeItem(element: HighlightNode): TreeItem {12 return element;13 }14 getChildren(element?: HighlightNode): Thenable<HighlightNode[]> {15 let nodes: HighlightNode[] = this.words.map(w => {16 return new HighlightNode(w.expression, w, this)17 })18 return Promise.resolve(nodes)19 }20 public refresh(): any {21 this._onDidChangeTreeData.fire();22 }23}24export class HighlightNode extends TreeItem {25 constructor(26 public readonly label: string,27 public readonly highlight: Highlightable,28 public provider: HighlightTreeProvider,29 public readonly command?: Command30 ) {31 super(label);32 }33 34 private getOpts(): string {35 const index = this.highlight.expression == this.provider.currentExpression ? 36 ` ${this.provider.currentIndex.index}/${this.provider.currentIndex.count}` : ''37 return this.highlight.ignoreCase && this.highlight.wholeWord ? 'both' :38 this.highlight.ignoreCase ? 'ignoreCase' :39 this.highlight.wholeWord ? 'wholeWord' : 'default' + index40 }41 get tooltip(): string {42 return `${this.label}-${this.getOpts()}`;43 }44 get description(): string {45 return this.getOpts()46 }47 contextValue = 'highlights';48}...
Using AI Code Generation
1const {openBrowser, goto, highlightNode} = require('taiko');2(async () => {3 try {4 await openBrowser();5 await goto("google.com");6 await highlightNode("input[name='q']");7 } catch (e) {8 console.error(e);9 } finally {10 closeBrowser();11 }12})();13const {openBrowser, goto, highlightElement} = require('taiko');14(async () => {15 try {16 await openBrowser();17 await goto("google.com");18 await highlightElement("input[name='q']");19 } catch (e) {20 console.error(e);21 } finally {22 closeBrowser();23 }24})();25const {openBrowser, goto, scrollTo} = require('taiko');26(async () => {27 try {28 await openBrowser();29 await goto("google.com");30 await scrollTo("input[name='q']");31 } catch (e) {32 console.error(e);33 } finally {34 closeBrowser();35 }36})();37const {openBrowser, goto, scrollDown} = require('taiko');38(async () => {39 try {40 await openBrowser();41 await goto("google.com");42 await scrollDown(100);43 } catch (e) {44 console.error(e);45 } finally {46 closeBrowser();47 }48})();49const {openBrowser, goto, scrollUp} = require('taiko');50(async () => {51 try {52 await openBrowser();53 await goto("google.com");54 await scrollUp(100);55 } catch (e) {56 console.error(e);57 } finally {58 closeBrowser();59 }60})();
Using AI Code Generation
1highlightNode("div", {class: "my-class"});2highlightNode("div", {class: "my-class"}, {selector: "css"});3highlightNode("div", {class: "my-class"}, {selector: "xpath"});4highlightNode("div", {class: "my-class"}, {selector: "css", index: 1});5highlightNode("div", {class: "my-class"}, {selector: "xpath", index: 1});6highlightNode("div", {class: "my-class"}, {selector: "css", index: 2});7highlightNode("div", {class: "my-class"}, {selector: "xpath", index: 2});8highlightNode("div", {class: "my-class"}, {selector: "css", index: 3});9highlightNode("div", {class: "my-class"}, {selector: "xpath", index: 3});10highlightNode("div", {class: "my-class"}, {selector: "css", index: 4});11highlightNode("div", {class: "my-class"}, {selector: "xpath", index: 4});12highlightNode("div", {class: "my-class"}, {selector: "css", index: 5});13highlightNode("div", {class: "my-class"}, {selector: "xpath", index: 5});14highlightNode("div", {class: "my-class"}, {selector: "css", index: 6});15highlightNode("div", {class: "my-class"}, {selector: "xpath", index: 6});16highlightNode("div", {class: "my-class"}, {selector: "css", index: 7});17highlightNode("div", {class: "my-class"}, {selector: "xpath", index: 7});18highlightNode("div", {class: "my-class"}, {selector: "css", index: 8});19highlightNode("div", {class: "my-class"}, {selector: "xpath", index: 8});20highlightNode("div", {class: "my-class"}, {selector: "css", index: 9});21highlightNode("div", {class: "my-class"}, {selector: "xpath", index: 9});22highlightNode("div", {class: "my-class"}, {selector: "css", index: 10});23highlightNode("div", {class: "my-class"}, {
Using AI Code Generation
1highlightNode("button");2highlightElement("button");3screenshot({ path: 'screenshot.png', fullPage: true });4setConfig({5});6openBrowser();7closeBrowser();8openTab();9closeTab();10switchTo('Google');11focus('input');12reload();
Using AI Code Generation
1const {highlightNode} = require('taiko');2highlightNode('div');3### highlightElement(element)4const {highlightElement} = require('taiko');5### highlight(selector)6const {highlight} = require('taiko');7highlight('div');8### clear(selector)9const {clear} = require('taiko');10clear('div');11### attach(selector, filePath)12const {attach} = require('taiko');13attach('div', './test.js');14### detach(selector, filePath)15const {detach} = require('taiko');16detach('div', './test.js');17### toRightOf(selector)18const {toRightOf} = require('taiko');19toRightOf('div');20### toLeftOf(selector)21const {toLeftOf} = require('taiko');22toLeftOf('div');23### above(selector)24const {above} = require('taiko');25above('div');26### below(selector)27const {below} = require('taiko');28below('div');29### near(selector)
Using AI Code Generation
1const { highlightNode } = require('taiko');2highlightNode('button');3### `openBrowser(options)`4const { openBrowser } = require('taiko');5(async () => {6 try {7 await openBrowser({headless: false});8 await openBrowser({args: ['--window-size=1920,1080']});9 await openBrowser({ignoreCertificateErrors: true});10 await openBrowser({host:'localhost', port: 9222});11 await openBrowser({observe: false});12 await openBrowser({observeTime: 1000});13 await openBrowser({dumpio: true});14 await openBrowser({executablePath: '/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary'});15 } catch (e) {16 console.error(e);17 } finally {18 }19})();20### `closeBrowser()`21const { openBrowser, closeBrowser } = require('taiko');22(async () => {23 try {24 await openBrowser();25 await closeBrowser();26 } catch (e) {27 console.error(e);28 } finally {29 }30})();31### `switchTo(target)`32const { openBrowser, goto, switchTo, closeBrowser } = require('taiko');33(async () => {34 try {35 await openBrowser();36 await switchTo("tab2");37 await switchTo("tab1");38 await switchTo("tab3");39 await switchTo("tab2");40 await switchTo("tab1");41 await switchTo("tab2");42 await switchTo("tab1");43 await switchTo("tab2");44 await switchTo("tab1");45 await switchTo("tab2");46 await switchTo("tab3");47 await switchTo("tab1");
Using AI Code Generation
1const { openBrowser, goto, highlightNode, unHighlightNode } = require('taiko');2(async () => {3 try {4 await openBrowser();5 await highlightNode('a');6 await unHighlightNode('a');7 } catch (e) {8 console.error(e);9 } finally {10 await closeBrowser();11 }12})();13const { openBrowser, goto, screenshot } = require('taiko');14(async () => {15 try {16 await openBrowser();17 await screenshot({ path: 'screenshot.png' });18 await screenshot({ path: 'screenshot.png', fullPage: false });19 } catch (e) {20 console.error(e);21 } finally {22 await closeBrowser();23 }24})();25const { openBrowser, goto, scrollDown } = require('taiko');26(async () => {27 try {28 await openBrowser();29 await scrollDown(100);30 } catch (e) {31 console.error(e);32 } finally {33 await closeBrowser();34 }35})();36const { openBrowser, goto, scrollUp } = require('taiko');37(async () => {38 try {39 await openBrowser();40 await scrollUp(100);41 } catch (e) {42 console.error(e);43 } finally {44 await closeBrowser();45 }46})();47const { openBrowser, goto, scrollTo } = require('taiko');48(async () => {49 try {50 await openBrowser();
Using AI Code Generation
1const { highlightNode } = require('taiko');2highlightNode('div', {3 backgroundColor: 'rgba(255, 0, 0, 0.5)',4});5module.exports = function(taiko) {6 taiko.myPlugin = () => {7 console.log('my plugin');8 };9};10const { openBrowser, goto, closeBrowser } = require('taiko');11const myPlugin = require('./myPlugin');12(async () => {13 try {14 await openBrowser();15 await goto('taiko.dev');16 await myPlugin();17 } catch (e) {18 console.error(e);19 } finally {20 await closeBrowser();21 }22})();23To create a new plugin, use the [taiko-plugin](
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!!