How to use existsAsync method in Puppeteer

Best JavaScript code snippet using puppeteer

MSSqlAdapter.spec.js

Source:MSSqlAdapter.spec.js Github

copy

Full Screen

...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}];`);...

Full Screen

Full Screen

model-existsAsync.js

Source:model-existsAsync.js Github

copy

Full Screen

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 });...

Full Screen

Full Screen

resolvePlugin.js

Source:resolvePlugin.js Github

copy

Full Screen

...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}...

Full Screen

Full Screen

async.test.js

Source:async.test.js Github

copy

Full Screen

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')...

Full Screen

Full Screen

user-service.js

Source:user-service.js Github

copy

Full Screen

...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...

Full Screen

Full Screen

save-service-to-file.js

Source:save-service-to-file.js Github

copy

Full Screen

...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 }...

Full Screen

Full Screen

FileSystem.js

Source:FileSystem.js Github

copy

Full Screen

...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}...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

...3const existsAsync = require('./lib/existsAsync')4module.exports = function (options) {5 return {6 exists: exists(options),7 existsAsync: existsAsync(options)8 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const puppeteer = require('puppeteer');2(async () => {3 const browser = await puppeteer.launch();4 const page = await browser.newPage();5 const exists = await page.$eval('body', el => el.textContent.includes('Example Domain'));6 console.log(exists);7 await browser.close();8})();9page.existsAsync(selector)10const puppeteer = require('puppeteer');11(async () => {12 const browser = await puppeteer.launch();13 const page = await browser.newPage();14 const exists = await page.$eval('body', el => el.textContent.includes('Example Domain'));15 console.log(exists);16 await browser.close();17})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const puppeteer = require('puppeteer');2(async () => {3 const browser = await puppeteer.launch();4 const page = await browser.newPage();5 const element = await page.$('#hplogo');6 const isElementVisible = await page.evaluate(element => {7 const style = window.getComputedStyle(element);8 return style && style.display !== 'none' && style.visibility !== 'hidden' && style.opacity !== '0';9 }, element);10 console.log(isElementVisible);11 await browser.close();12})();13MIT © [Saurabh Singh](

Full Screen

Using AI Code Generation

copy

Full Screen

1const puppeteer = require('puppeteer');2const fs = require('fs');3const util = require('util');4const existsAsync = util.promisify(fs.exists);5(async () => {6 const browser = await puppeteer.launch({headless: false});7 const page = await browser.newPage();8 const exists = await existsAsync('test.js');9 console.log(exists);10 await browser.close();11})();12const puppeteer = require('puppeteer');13const fs = require('fs-extra');14const existsAsync = fs.exists;15(async () => {16 const browser = await puppeteer.launch({headless: false});17 const page = await browser.newPage();18 const exists = await existsAsync('test.js');19 console.log(exists);20 await browser.close();21})();22const puppeteer = require('puppeteer');23const fs = require('fs');24const existsAsync = fs.exists;25(async () => {26 const browser = await puppeteer.launch({headless: false});27 const page = await browser.newPage();28 const exists = await existsAsync('test.js');29 console.log(exists);30 await browser.close();31})();32const puppeteer = require('puppeteer');33const fs = require('fs-extra');34const existsAsync = fs.exists;35(async () => {36 const browser = await puppeteer.launch({headless: false});37 const page = await browser.newPage();38 const exists = await existsAsync('test.js');39 console.log(exists);40 await browser.close();41})();42const puppeteer = require('puppeteer');43const fs = require('fs');44const existsAsync = fs.exists;45(async () => {46 const browser = await puppeteer.launch({headless: false});47 const page = await browser.newPage();48 const exists = await existsAsync('test.js');49 console.log(exists);50 await browser.close();51})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const puppeteer = require("puppeteer");2(async () => {3 const browser = await puppeteer.launch();4 const page = await browser.newPage();5 const element = await page.$("#hplogo");6 const exists = await element.asElement().existsAsync();7 console.log(exists);8 await browser.close();9})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const puppeteer = require('puppeteer');2const fs = require('fs');3const util = require('util');4const existsAsync = util.promisify(fs.exists);5async function run() {6 const browser = await puppeteer.launch({7 });8 const page = await browser.newPage();9 await page.screenshot({ path: 'google.png' });10 await browser.close();11}12run();13(async () => {14 const fileExists = await existsAsync('google.png');15 if (fileExists) {16 console.log('file exists!');17 } else {18 console.log('file does not exist!');19 }20})();

Full Screen

Using AI Code Generation

copy

Full Screen

1(async () => {2 const browser = await puppeteer.launch();3 const page = await browser.newPage();4 const element = await page.$('#hplogo');5 const exists = await page.evaluate(element => {6 return element !== null;7 }, element);8 console.log(exists);9 await browser.close();10})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const fs = require('fs');2const util = require('util');3const existsAsync = util.promisify(fs.exists);4(async () => {5 const result = await existsAsync('test.js');6 console.log(result);7})();8const fs = require('fs');9const util = require('util');10const existsAsync = util.promisify(fs.exists);11(async () => {12 const result = await existsAsync('test.js');13 console.log(result);14})();15const fs = require('fs');16const util = require('util');17const existsAsync = util.promisify(fs.exists);18(async () => {19 const result = await existsAsync('test.js');20 console.log(result);21})();

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Puppeteer automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful