Best JavaScript code snippet using taiko
MSSqlAdapter.spec.js
Source:MSSqlAdapter.spec.js
...97 const adapter = new MSSqlAdapter(testConnectionOptions);98 });99 it('should use database(string).exists()', async () => {100 const adapter = new MSSqlAdapter(testConnectionOptions);101 let exists = await adapter.database(testConnectionOptions.database).existsAsync();102 expect(exists).toBeTrue();103 exists = await adapter.database('other_database').existsAsync();104 expect(exists).toBeFalse();105 await adapter.closeAsync();106 });107 it('should use database(string).create()', async () => {108 const adapter = new MSSqlAdapter(testConnectionOptions);109 await adapter.database('test_create_a_database').createAsync();110 let exists = await adapter.database('test_create_a_database').existsAsync();111 expect(exists).toBeTrue();112 await adapter.executeAsync('DROP DATABASE test_create_a_database;');113 exists = await adapter.database('test_create_a_database').existsAsync();114 expect(exists).toBeFalse();115 await adapter.closeAsync();116 });117 it('should use table(string).exists()', async () => {118 const adapter = new MSSqlAdapter(testConnectionOptions);119 let exists = await adapter.table(ProductModel.source).existsAsync();120 if (exists === false) {121 await adapter.table(ProductModel.source).create(ProductModel.fields);122 }123 exists = await adapter.table(ProductModel.source).existsAsync();124 expect(exists).toBeTrue();125 // drop table by executing SQL126 await adapter.executeAsync(`DROP TABLE [${ProductModel.source}];`);127 exists = await adapter.table(ProductModel.source).existsAsync();128 expect(exists).toBeFalse();129 await adapter.closeAsync();130 });131 it('should use table(string).create()', async () => {132 const adapter = new MSSqlAdapter(testConnectionOptions);133 let exists = await adapter.table(ProductModel.source).existsAsync();134 if (exists === true) {135 // drop table136 await adapter.executeAsync(`DROP TABLE [${ProductModel.source}];`);137 }138 await adapter.table(ProductModel.source).create(ProductModel.fields);139 exists = await adapter.table(ProductModel.source).existsAsync();140 expect(exists).toBeTrue();141 // drop table142 await adapter.executeAsync(`DROP TABLE [${ProductModel.source}];`);143 await adapter.closeAsync();144 });145 it('should use execute() for insert', async () => {146 const adapter = new MSSqlAdapter(testConnectionOptions);147 let exists = await adapter.table(EmployeeModel.source).existsAsync();148 if (exists === false) {149 await adapter.table(EmployeeModel.source).create(EmployeeModel.fields);150 }151 const sources = EmployeeModel.seed.map(item => {152 return new QueryExpression().insert(item).into(EmployeeModel.source);153 }).map(query => {154 return adapter.executeAsync(query);155 });156 await Promise.all(sources);157 const query = new QueryExpression().from(EmployeeModel.source)158 .where('LastName').equal('Davolio')159 .select('*');160 let res = await adapter.executeAsync(query);161 expect(res).toBeInstanceOf(Array);162 expect(res.length).toBe(1);163 expect(res[0].LastName).toBe('Davolio')164 // drop table165 await adapter.executeAsync(`DROP TABLE [${EmployeeModel.source}];`);166 await adapter.closeAsync();167 });168 it('should use execute() for update', async () => {169 const adapter = new MSSqlAdapter(testConnectionOptions);170 let exists = await adapter.table(EmployeeModel.source).existsAsync();171 if (exists === false) {172 await adapter.table(EmployeeModel.source).create(EmployeeModel.fields);173 }174 const sources = EmployeeModel.seed.map(item => {175 return new QueryExpression().insert(item).into(EmployeeModel.source);176 }).map(query => {177 return adapter.executeAsync(query);178 });179 await Promise.all(sources);180 const updateQuery = new QueryExpression().update(EmployeeModel.source)181 .set({182 LastName: 'Davolio-Arnold'183 })184 .where('LastName').equal('Davolio');185 await adapter.executeAsync(updateQuery);186 const query = new QueryExpression().from(EmployeeModel.source)187 .where('LastName').equal('Davolio-Arnold')188 .select('*');189 let res = await adapter.executeAsync(query);190 expect(res).toBeInstanceOf(Array);191 expect(res.length).toBe(1);192 expect(res[0].LastName).toBe('Davolio-Arnold');193 // drop table194 await adapter.executeAsync(`DROP TABLE [${EmployeeModel.source}];`);195 await adapter.closeAsync();196 });197 it('should use view(string).exists()', async () => {198 const adapter = new MSSqlAdapter(testConnectionOptions);199 let exists = await adapter.view(`EmployeesView`).existsAsync();200 expect(exists).toBeFalse();201 await adapter.table(EmployeeModel.source).create(EmployeeModel.fields);202 await adapter.view(`EmployeesView`).createAsync(new QueryExpression().from('Employees').select('*'));203 exists = await adapter.view(`EmployeesView`).existsAsync();204 expect(exists).toBeTrue();205 // drop view206 await adapter.view(`EmployeesView`).dropAsync();207 // drop table208 await adapter.executeAsync(`DROP TABLE [${EmployeeModel.source}];`);209 await adapter.closeAsync();210 });211 it('should use indexes(string).list()', async () => {212 const adapter = new MSSqlAdapter(testConnectionOptions);213 let exists = await adapter.table(ProductModel.source).existsAsync();214 if (exists === true) {215 // drop table216 await adapter.executeAsync(`DROP TABLE [${ProductModel.source}];`);217 }218 await adapter.table(ProductModel.source).create(ProductModel.fields);219 exists = await adapter.table(ProductModel.source).existsAsync();220 expect(exists).toBeTrue();221 // list indexes222 const indexes = await adapter.indexes(ProductModel.source).listAsync();223 expect(indexes).toBeTruthy();224 expect(indexes.length).toBeGreaterThan(0);225 // get index 0226 const index0 = indexes[0];227 expect(index0).toBeTruthy();228 expect(index0.columns[0]).toBe('ProductID');229 // drop table230 await adapter.executeAsync(`DROP TABLE [${ProductModel.source}];`);231 await adapter.closeAsync();232 });233 it('should use indexes(string).create()', async () => {234 const adapter = new MSSqlAdapter(testConnectionOptions);235 let exists = await adapter.table(ProductModel.source).existsAsync();236 if (exists === true) {237 // drop table238 await adapter.executeAsync(`DROP TABLE [${ProductModel.source}];`);239 }240 await adapter.table(ProductModel.source).create(ProductModel.fields);241 exists = await adapter.table(ProductModel.source).existsAsync();242 expect(exists).toBeTrue();243 await adapter.indexes(ProductModel.source).createAsync('INDEX_Product_Name', [244 "ProductName"245 ]);246 const indexes = await adapter.indexes(ProductModel.source).listAsync();247 const findIndex = indexes.find((x) => x.name === 'INDEX_Product_Name');248 expect(findIndex).toBeTruthy();249 // drop table250 await adapter.executeAsync(`DROP TABLE [${ProductModel.source}];`);251 await adapter.closeAsync();252 });253 it('should use indexes(string).drop()', async () => {254 const adapter = new MSSqlAdapter(testConnectionOptions);255 let exists = await adapter.table(ProductModel.source).existsAsync();256 if (exists === true) {257 // drop table258 await adapter.executeAsync(`DROP TABLE [${ProductModel.source}];`);259 }260 await adapter.table(ProductModel.source).create(ProductModel.fields);261 exists = await adapter.table(ProductModel.source).existsAsync();262 expect(exists).toBeTrue();263 await adapter.indexes(ProductModel.source).createAsync('INDEX_Product_Name', [264 "ProductName"265 ]);266 let drop = await adapter.indexes(ProductModel.source).dropAsync('INDEX_Product_Name');267 expect(drop).toBe(1);268 const indexes = await adapter.indexes(ProductModel.source).listAsync();269 const findIndex = indexes.find((x) => x.name === 'INDEX_Product_Name');270 expect(findIndex).toBeFalsy();271 // drop twice272 drop = await adapter.indexes(ProductModel.source).dropAsync('INDEX_Product_Name');273 expect(drop).toBe(0);274 // drop table275 await adapter.executeAsync(`DROP TABLE [${ProductModel.source}];`);...
model-existsAsync.js
Source:model-existsAsync.js
1var should = require('should');2var helper = require('../support/spec_helper');3describe("Model.existsAsync()", function() {4 var db = null;5 var Person = null;6 var good_id, bad_id;7 var setup = function () {8 return function (done) {9 Person = db.define("person", {10 name : String11 });12 return helper.dropSync(Person, function () {13 Person.create([{14 name: "Jeremy Doe"15 }, {16 name: "John Doe"17 }, {18 name: "Jane Doe"19 }], function (err, people) {20 good_id = people[0][Person.id];21 if (typeof good_id == "number") {22 // numeric ID23 bad_id = good_id * 100;24 } else {25 // string ID, keep same length..26 bad_id = good_id.split('').reverse().join('');27 }28 return done();29 });30 });31 };32 };33 before(function (done) {34 helper.connect(function (connection) {35 db = connection;36 return done();37 });38 });39 after(function () {40 return db.close();41 });42 describe("with an id", function () {43 before(setup());44 it("should return true if found", function () {45 return Person.existsAsync(good_id)46 .then(function (exists) {47 exists.should.be.true();48 });49 });50 it("should return false if not found", function () {51 return Person.existsAsync(bad_id)52 .then(function (exists) {53 exists.should.be.false();54 });55 });56 });57 describe("with a list of ids", function () {58 before(setup());59 it("should return true if found", function () {60 return Person.existsAsync([ good_id ])61 .then(function (exists) {62 exists.should.be.true();63 });64 });65 it("should return false if not found", function () {66 return Person.existsAsync([ bad_id ])67 .then(function (exists) {68 exists.should.be.false();69 });70 });71 });72 describe("with a conditions object", function () {73 before(setup());74 it("should return true if found", function () {75 return Person.existsAsync({ name: "John Doe" })76 .then(function (exists) {77 exists.should.be.true();78 });79 });80 it("should return false if not found", function () {81 return Person.existsAsync({ name: "Jack Doe" })82 .then(function (exists) {83 exists.should.be.false();84 });85 });86 });...
resolvePlugin.js
Source:resolvePlugin.js
...9 }10 11 if(file) {12 const rcPath = path.resolve(process.cwd(), file);13 if(await fs.existsAsync(rcPath)) {14 const rc = await fs.readAsync(rcPath);15 const contents = JSON.parse(rc);16 if(contents.prefix) prefix = contents.prefix;17 plugins = plugins.concat(parse(contents.plugins));18 }19 }20 21 const pluginMap = {};22 for(let i = 0; i < plugins.length; i++){23 const plugin = plugins[i];24 const path = await resolvePath(plugin[0], prefix);25 const pluginModule = require(path);26 const options = plugin[1];27 pluginMap[plugin[0]] = {28 path,29 module: pluginModule,30 options,31 async run(...args) {32 return await pluginModule(options, ...args);33 }34 }35 }36 const names = Object.keys(pluginMap);37 return names.map(name => ({ name, ...pluginMap[name] }));38}39async function resolvePath(plugin, prefix) {40 //check if plugin exists locally41 const local = path.resolve(process.cwd(), plugin);42 if(await fs.existsAsync(`${local}.js`) || 43 await fs.existsAsync(local)) 44 {45 return local.toString();46 }47 48 //apply prefix49 const moduleName = prefix ? `${prefix}-${plugin}` : plugin;50 51 //scan all node_modules with module.paths52 const nodeModulesPaths = module.paths;53 for(let i = 0; i < nodeModulesPaths.length; i++) {54 const nmPath = path.resolve(nodeModulesPaths[i], moduleName);55 if(await fs.existsAsync(nmPath)) {56 return nmPath.toString();57 }58 }59 //defaults to where the cli command is run60 //most likely where rc file exists61 return path.resolve(process.cwd(), "node_modules", moduleName);62}...
async.test.js
Source:async.test.js
1const { existsAsync } = require('../')({name: 'exists'})2test('exists.config.js exists', async () => {3 const stats = await existsAsync('__tests__/fixtures')4 expect(stats.fileName).toBe('exists.config.js')5})6test('exists.config.js exists in files directory', async () => {7 const stats = await existsAsync('__tests__/fixtures/a.js')8 expect(stats.fileName).toBe('exists.config.js')9})10test('exists.config.js exists in parent directory', async () => {11 const stats = await existsAsync('__tests__/fixtures/config/js')12 expect(stats.fileName).toBe('exists.config.js')13})14test('exists.config.js not exists', async () => {15 const stats = await existsAsync('__tests__/')16 expect(stats).toBeFalsy()17})18test('.existsrc.js exists', async () => {19 const stats = await existsAsync('__tests__/fixtures/rc/js')20 expect(stats.fileName).toBe('.existsrc.js')21})22test('exists.config.js folder not included', async () => {23 const stats = await existsAsync('__tests__/fixtures/rc/js/exists.config.js')24 expect(stats.fileName).toBe('.existsrc.js')25})26test('.existsrc.json exists', async () => {27 const stats = await existsAsync('__tests__/fixtures/rc/json')28 expect(stats.fileName).toBe('.existsrc.json')29})30test('.existsrc.yml exists', async () => {31 const stats = await existsAsync('__tests__/fixtures/rc/yml')32 expect(stats.fileName).toBe('.existsrc.yml')33})34test('.existsrc.yaml exists', async () => {35 const stats = await existsAsync('__tests__/fixtures/rc/yml/a')36 expect(stats.fileName).toBe('.existsrc.yaml')...
user-service.js
Source:user-service.js
...11 console.log("CreateAsync Error: ", err)12 })13 return user;14 }15 async function existsAsync(username) {16 let user = await Users.findOne({17 where: {18 username: username19 }20 }).catch(err => {21 console.log("ExistsAsync Error: ", err);22 })23 return user ? true : false; 24 }25 async function findByUsernameAndPasswordAsync(userData) {26 let user = await Users.findOne({27 where: {28 username: userData.username,29 password: userData.password...
save-service-to-file.js
Source:save-service-to-file.js
...3 async ({ generatedServices, destinationDir, overwrite }) => {4 for (const serviceName in generatedServices) {5 const generatedServiceCode = generatedServices[serviceName];6 const filePath = path.join(destinationDir, `${serviceName}.js`);7 if (await existsAsync(filePath) && !overwrite) {8 console.error(`NUT-IOC ERROR: ${filePath} file exists and overwrite option is false. So it is not created.`);9 } else {10 if (!(await existsAsync(destinationDir))) {11 await mkdirAsync(destinationDir);12 console.log(`NUT-IOC INFO: Generated directory path is ${destinationDir}`);13 }14 await writeFileAsync(filePath, generatedServiceCode);15 console.log(`NUT-IOC INFO: Writen file path is ${filePath}`);16 }17 }...
FileSystem.js
Source:FileSystem.js
...11}12class FileSystemCache {13 static async get(key) {14 const keyPath = preparePath(key);15 const exists = await existsAsync(keyPath);16 if (exists) {17 return await readFileAsync(keyPath, "utf8");18 } else {19 return false;20 }21 }22 static async set(key, value) {23 const keyPath = preparePath(key);24 return await writeFileAsync(keyPath, value, "utf8");25 }26 static async remove(key) {27 const keyPath = preparePath(key);28 const exists = await existsAsync(keyPath);29 if (exists) {30 return await unlinkAsync(keyPath);31 }32 return true;33 }34}...
index.js
Source:index.js
...3const existsAsync = require('./lib/existsAsync')4module.exports = function (options) {5 return {6 exists: exists(options),7 existsAsync: existsAsync(options)8 }...
Using AI Code Generation
1const { openBrowser, goto, closeBrowser } = require('taiko');2(async () => {3 try {4 await openBrowser();5 await goto("google.com");6 await closeBrowser();7 } catch (e) {8 console.error(e);9 } finally {10 }11})();
Using AI Code Generation
1const { openBrowser, goto, exists, closeBrowser } = require('taiko');2(async () => {3 try {4 await openBrowser();5 await goto("google.com");6 let result = await exists("Gmail");7 console.log(result);8 } catch (e) {9 console.error(e);10 } finally {11 await closeBrowser();12 }13})();
Using AI Code Generation
1const { openBrowser, goto, exists, closeBrowser } = require('taiko');2(async () => {3 try {4 await openBrowser();5 await exists("Gmail");6 await closeBrowser();7 } catch (e) {8 console.error(e);9 } finally {10 }11})();
Using AI Code Generation
1var assert = require('assert');2var { openBrowser, goto, write, click, closeBrowser, exists, existsAsync } = require('taiko');3(async () => {4 try {5 await openBrowser();6 await write("Taiko");7 await click("Google Search");8 await exists("Taiko is an open source automation framework for testing modern web applications.");9 assert.ok(await existsAsync("Taiko is an open source automation framework for testing modern web applications."));10 } catch (e) {11 console.error(e);12 } finally {13 await closeBrowser();14 }15})();
Using AI Code Generation
1const { exists, openBrowser, goto, closeBrowser } = require('taiko');2(async () => {3 try {4 await openBrowser();5 await goto("google.com");6 let elementExists = await exists("Google Search", 100);7 await closeBrowser();8 } catch (e) {9 console.error(e);10 } finally {11 }12})();13const { openBrowser, goto, closeBrowser, exists } = require('taiko');14(async () => {15 try {16 await openBrowser();17 await goto("google.com");18 let elementExists = await exists("Google Search");19 if(elementExists) {20 console.log("Element exists");21 }22 else {23 console.log("Element does not exists");24 }25 await closeBrowser();26 } catch (e) {27 console.error(e);28 } finally {29 }30})();
Using AI Code Generation
1const { openBrowser, goto, exists, closeBrowser } = require('taiko');2(async () => {3 try {4 await openBrowser({ headless: false });5 let element = await exists('Google Search');6 console.log(element);7 } catch (e) {8 console.error(e);9 } finally {10 await closeBrowser();11 }12})();13exists(selector, options)14const { openBrowser, goto, exists, closeBrowser } = require('taiko');15(async () => {16 try {17 await openBrowser({ headless: false });18 let element = await exists('Google Search');19 console.log(element);20 } catch (e) {21 console.error(e);22 } finally {23 await closeBrowser();24 }25})();26const { openBrowser, goto, exists, closeBrowser } = require('taiko');27(async () => {28 try {29 await openBrowser({ headless: false });30 let element = await exists('Google Search', { timeout: 5000 });31 console.log(element);32 } catch (e) {33 console.error(e);34 } finally {35 await closeBrowser();36 }37})();
Using AI Code Generation
1var taiko = require('taiko');2var path = require('path');3var fs = require('fs');4var assert = require('assert');5(async () => {6 try {7 await openBrowser();8 await write("Taiko");9 await press("Enter");10 await click("Taiko - Google Search");
Using AI Code Generation
1var { openBrowser, goto, closeBrowser, exists, button, existsAsync } = require('taiko');2(async () => {3 try {4 await openBrowser();5 await existsAsync(button("Google Search"));6 console.log("button exists");7 await closeBrowser();8 } catch (e) {9 console.error(e);10 } finally {11 }12})();13var { openBrowser, goto, closeBrowser, exists, button } = require('taiko');14(async () => {15 try {16 await openBrowser();17 await exists(button("Google Search"));18 console.log("button exists");19 await closeBrowser();20 } catch (e) {21 console.error(e);22 } finally {23 }24})();25var { openBrowser, goto, closeBrowser, text, button, write, click } = require('taiko');26(async () => {27 try {28 await openBrowser();29 await write("admin", into(text("Username")));30 await write("admin", into(text("Password")));31 await click(button("Login"));32 await closeBrowser();33 } catch (e) {34 console.error(e);35 } finally {36 }37})();38The problem is that the text boxes are not being found. I am using the text() method to find the text boxes. The text boxes are not found. I am using the following code to find the text boxes:39await write("admin", into(text("Username")));40await write("admin", into(text("Password")));41await write("admin", into(text("username")));42await write("admin", into(text("password")));
Using AI Code Generation
1(async () => {2 try {3 await openBrowser();4 await goto("google.com");5 var exists = await existsAsync("Google");6 if (exists) {7 console.log("Google text exists");8 } else {9 console.log("Google text does not exist");10 }11 await closeBrowser();12 } catch (e) {13 console.error(e);14 } finally {15 }16})();17(async () => {18 try {19 await openBrowser();20 await goto("google.com");21 var exists = await existsBeforeTimeout("Google");22 if (exists) {23 console.log("Google text exists");24 } else {25 console.log("Google text does not exist");26 }27 await closeBrowser();28 } catch (e) {29 console.error(e);30 } finally {31 }32})();33(async () => {34 try {35 await openBrowser();36 await goto("google.com");37 var exists = await existsAfterTimeout("Google", 5000);38 if (exists) {39 console.log("Google text exists");40 } else {41 console.log("Google text does not exist");42 }43 await closeBrowser();44 } catch (e) {45 console.error(e);46 } finally {47 }48})();49(async () => {50 try {51 await openBrowser();52 await goto("google.com");53 var exists = await existsAfterAction("Google");54 if (exists) {
Using AI Code Generation
1const { existsAsync } = require('taiko');2(async () => {3 let isElementPresent = await existsAsync('Element');4 console.log(isElementPresent);5})();6const { existsAsync } = require('taiko');7(async () => {8 let isElementPresent = await existsAsync('Element', { timeout: 1000 });9 console.log(isElementPresent);10})();11const { existsAsync } = require('taiko');12(async () => {13 let isElementPresent = await existsAsync('Element', { timeout: 1000, interval: 100 });14 console.log(isElementPresent);15})();16const { existsAsync } = require('taiko');17(async () => {18 let isElementPresent = await existsAsync('Element', { timeout: 1000, interval: 100, retryInterval: 100 });19 console.log(isElementPresent);20})();21const { existsAsync } = require('taiko');22(async () => {23 let isElementPresent = await existsAsync('Element', { timeout: 1000, interval: 100, retryInterval: 100, observe: true });24 console.log(isElementPresent);25})();
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!!