How to use downloadFromGitHub method in Webdriverio

Best JavaScript code snippet using webdriverio-monorepo

nobg.js

Source:nobg.js Github

copy

Full Screen

1const config = require("../../config.json")2const { program } = require('commander');3const fs = require('fs');4const request = require('request');5const readline = require("readline");6const { isMissingThrow } = require('./misc/isMissing.js')7const { downloadFile } = require('./misc/downloader.js')8if (!config.removebg_api_key) throw new Error(`9 Missing removebg_api_key in config file config.json10 get your own api-key at https://www.remove.bg/dashboard#api-key11 and take example at config-example.json12`)13// const config = JSON.parse(fs.readFileSync(program.configFile));14async function downloadBackgroundLessPicCreateOutputFolderIfNotExistLOLSoLong(depute, opt) {15 isMissingThrow(depute, { uid: true, an_www_depute: { imgurl: true } })16 const { dlfolder } = opt17 if (fs.existsSync(dlfolder)) {18 downloadBackgroundLessPic(depute, opt);19 } else {20 console.log(`creating ${dlfolder}`)21 await fs.promises.mkdir(dlfolder, { recursive: true })22 await downloadBackgroundLessPic(depute, opt)23 }24}25async function downloadBackgroundLessPic(depute, opt) {26 const { dlfolder } = opt27 const filename = `${dlfolder}/img-nobg/${depute.uid}.png`28 if (program.overrideImg || !fs.existsSync(filename)) {29 try {30 opt.verbose && console.log(`trying download from github`)31 await downloadFromGithub(depute.uid, filename, opt)32 } catch (e) {33 if (e.response.status === 404) {34 fs.unlinkSync(filename) //remove empty file started to be created before error35 if (opt.removeBg) {36 opt.verbose && console.log(`trying download from remove.bg`)37 await downloadFromRemoveBg(depute, filename, opt)38 } else {39 console.log(`depute ${depute.uid} pic not found on github, try adding --remove-bg option to download it from paying remove.bg site`)40 }41 } else {42 console.error(`got error:${e.response.statusText} when trying to get bgless pic`)43 }44 }45 } else {46 console.log(`File ${filename} already exist. Skipping ${depute.uid}`)47 }48}49async function downloadFromGithub(uid, filename, opt = {}) {50 const imgurl = `https://raw.githubusercontent.com/brissa-a/lcdg-data/main/img-nobg/${uid}.png`51 //`https://github.com/brissa-a/la-cour-des-grands/raw/main/react-app/public/depute-pic/${uid}.png`52 opt.verbose && console.log(`Start download of ${imgurl}`)53 return downloadFile(imgurl, filename, opt)54}55async function downloadFromRemoveBg(depute, filename, opt) {56 console.log(`Downloading bgless ${depute.an_www_depute.imgurl} `)57 await new Promise((resolve, reject) => {58 request.post({59 url: 'https://api.remove.bg/v1.0/removebg',60 formData: {61 image_url: depute.an_www_depute.imgurl,62 size: 'preview',63 },64 headers: {65 'X-Api-Key': config.removebg_api_key66 },67 encoding: null68 }, function (error, response, body) {69 if (error) {70 console.error('Request failed:', error);71 reject()72 return;73 }74 if (response.statusCode != 200) {75 console.error('Error:', response.statusCode, body.toString('utf8'));76 reject()77 return;78 }79 fs.writeFileSync(filename, body);80 console.log(`Downloaded ${depute.uid}`)81 resolve();82 });83 });84}85async function mainDownloadAll() {86 program87 .description(`Download depute pic without background thanks to https://wwww.remove.bg`)88 .option('-i, --input-file <deputes file>', 'deputes.json input file path', 'dl/deputes.json')89 .option('-c, --config-file <file>', 'config.json file path', 'config.json')90 .option('-o, --output-folder <folder>', 'download folder', "dl/img-nobg/")91 .option('--override-img', 'override already download pic')92 .option('--only-one', 'download only the first depute for debugging purpose.')93 program.parse(process.argv);94 let deputes = JSON.parse(fs.readFileSync(program.inputFile));95 if (program.onlyOne) {96 deputes = [deputes[0]]97 }98 console.log(`Number of deputes: ${deputes.length}`)99 const rl = readline.createInterface({100 input: process.stdin,101 output: process.stdout102 });103 rl.question(`You are about to consume ${deputes.length * 0.25} credit are you sure ? (y/n)`, function (answer) {104 if (answer === "y") {105 for (depute of deputes) {106 downloadBackgroundLessPicCreateOutputFolderIfNotExistLOLSoLong(depute, program)107 }108 } else {109 console.log("Cancelling download bglesss")110 }111 rl.close();112 });113}114async function mainDownloadFromGithub() {115 program116 .description(`who cares`)117 .option('-f, --dlfolder <folder>' , 'download folder', "test-work/")118 .option('-d, --debug', 'run puppeteer headless')119 .option('-v, --verbose', 'log what\'s happening')120 .option('--override')121 .option('--remove-bg')122 //downloadFromGithub('PA722170', program)123 await downloadBackgroundLessPic({uid: 'PA722170'}, program)124 await downloadBackgroundLessPic({uid: 'unexisting'}, program)125}126if (require.main === module) mainDownloadFromGithub()...

Full Screen

Full Screen

3rdPartyDocs.js

Source:3rdPartyDocs.js Github

copy

Full Screen

...28 const categoryDir = path.join(DOCS_ROOT_DIR, category === 'api' ? 'api' : '')29 await fs.ensureDir(categoryDir)30 for (const { packageName, title, githubUrl, npmUrl, suppressBuildInfo, locations, location = githubReadme, branch = 'master' } of packages3rdParty) {31 const readme = locations32 ? await Promise.all(locations.map((l) => downloadFromGitHub(githubUrl, branch, l)))33 .then((readmes) => readmes.join('\n'))34 : await downloadFromGitHub(githubUrl, branch, location)35 const id = `${packageName}`.replace(/@/g, '').replace(/\//g, '-')36 const doc = normalizeDoc(readme, githubUrl, branch,37 buildPreface(id, title, nameSingular, `${githubUrl}/edit/${branch}/${location}`),38 suppressBuildInfo ? [] : buildInfo(packageName, githubUrl, npmUrl))39 await fs.writeFile(path.join(categoryDir, `_${id}.md`), doc, { encoding: 'utf-8' })40 if (namePlural === 'Testrunner') {41 return42 }43 if (!sidebars[category][namePlural]) {44 sidebars[category][namePlural] = []45 }46 // eslint-disable-next-line no-console47 console.log(`Generated docs for ${packageName}`)48 sidebars[category][namePlural].push(...

Full Screen

Full Screen

_screenshot.js

Source:_screenshot.js Github

copy

Full Screen

1"use strict";2const path = require('path');3const child_process = require('child_process');4const mapnik = require('mapnik');5const SHA = process.env.TRAVIS_COMMIT;6const LFS_BASE_URL = 'https://media.githubusercontent.com/media/angular/material2';7/**8 * Generates a screenshot from the current state of the Protractor test and compares it to the9 * previous stored screenshot. If the screenshots do not match or if no existing screenshot is10 * found, an error will be thrown. In both cases, the new screenshot will be stored so that it can11 * be added to git.12 */13class Screenshot {14 /**15 * @param {string} id A unique identifier used for the screenshot16 */17 constructor(id) {18 this.id = id;19 this.path = path.resolve(__dirname, '..', 'screenshots', id + '.screenshot.png');20 this.url = `${LFS_BASE_URL}/${SHA}/screenshots/${encodeURIComponent(id)}.screenshot.png`;21 browser.takeScreenshot().then(png => this.storeScreenshot(png));22 }23 /**24 * Stores a local copy of the screenshot for future comparison25 * @param {string} png The base64-encoded screenshot generated from the current browser state26 */27 storeScreenshot(png) {28 console.info(`[STATUS] Generated new screenshot for "${this.id}"`);29 this.png = mapnik.Image.fromBytes(new Buffer(png, 'base64'));30 if (SHA) {31 this.downloadFromGithub();32 } else {33 this.compareScreenshots();34 }35 }36 /**37 * Since we are using `git-lfs`, screenshots are not necessarily available within our local38 * directory. To get around this, we download the latest screenshot from Github.39 */40 downloadFromGithub() {41 console.info(`[STATUS] Downloading screenshot from Github: ${this.url} => ${this.path}`);42 child_process.execSync(`curl ${this.url} > "${this.path}"`);43 this.compareScreenshots();44 }45 /**46 * Compares the generated screenshot to the existing screenshot. If it does not match, an error47 * will be thrown.48 */49 compareScreenshots() {50 console.info(`[STATUS] Comparing screenshots`);51 try {52 let referenceScreenshot = mapnik.Image.open(this.path);53 this.overwriteExistingScreenshot();54 if (referenceScreenshot.compare(this.png)) {55 throw new Error(`screenshot "${this.id}" has changed.`);56 } else {57 console.info('[STATUS] Screenshot has not changed');58 }59 } catch (e) {60 console.info(`[STATUS] No reference screenshot found`);61 this.overwriteExistingScreenshot();62 throw new Error(`screenshot "${this.id}" was not found.`);63 }64 }65 /**66 * Replaces the existing screenshot with the newly generated one.67 */68 overwriteExistingScreenshot() {69 console.info(`[STATUS] Saving new screenshot`);70 this.png.save(this.path);71 }72}...

Full Screen

Full Screen

cli.js

Source:cli.js Github

copy

Full Screen

1require("dotenv").config()2const parseArgs = require("minimist")3const downloadFromGithub = require("./github"),4 parseRepository = require("./parser"),5 folder = require("./folder"),6 s3 = require("./s3");7const { local } = require("../config")8const putSpace = () => {9 console.log("\n\n")10}11const hasKeyS3 = () => {12 return (process.env.AWS_ACCESS_KEY_ID && process.env.AWS_SECRET_ACCESS_KEY)13}14const validArgs = (args) => {15 if (!args.branch)16 throw new Error("Please include --branch [master|beta].")17 if (args.branch !== "master" && args.branch !== "beta")18 throw new Error("Unrecognized branch. Options: [master|beta].")19 return args20}21const downloadLatest = async () => {22 try {23 const args = validArgs(parseArgs(process.argv.slice(2)))24 const branch = args.branch25 putSpace()26 await folder.clear(local.all)27 await folder.create(local.all)28 await folder.create(local.staging)29 await downloadFromGithub(branch)30 await parseRepository(branch)31 putSpace()32 console.log("Finished.")33 putSpace()34 } catch (e) {35 return console.error(e.message)36 }37}38const updateBranch = async () => {39 try {40 const args = validArgs(parseArgs(process.argv.slice(2)))41 const branch = args.branch42 const verbose = args.verbose ? true : false;43 if (!hasKeyS3())44 return console.error("To use this script you need to define environment variables.")45 putSpace()46 await folder.clear(local.all)47 await folder.create(local.all)48 await folder.create(local.staging)49 await downloadFromGithub(branch)50 await parseRepository(branch)51 await folder.clear(local.staging)52 await s3.clearFolder(branch)53 putSpace()54 const upload_results = await s3.uploadTemplates(branch, verbose)55 putSpace()56 const manifest = upload_results.map(d => d.value)57 const manifest_results = await s3.uploadManifest(branch, manifest)58 console.log("Finished.")59 putSpace()60 } catch (e) {61 return console.error(e)62 }63}64module.exports = {65 downloadLatest: downloadLatest,66 updateBranch: updateBranch...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

1const { prompt, Separator } = require('inquirer');2const fs = require('fs-extra');3const path = require('path');4const upath = require('upath');5const chalk = require('chalk');6const { downloadFromGithub } = require('@wya/toolkit-utils');7const { resolve } = path;8const { log } = console;9module.exports = class InitManager {10 constructor(options = {}) {11 const defaultOptions = {12 // TODO13 };14 this.options = { ...defaultOptions, ...options };15 this.cwd = process.cwd();16 this.sourceDir = this.options.sourceDir;17 if (this.options.config) {18 this.configDir = path.resolve(this.options.config);19 }20 }21 _getQuesion() {22 return [23 {24 type: 'input',25 name: 'project',26 message: 'Project name:',27 validate(val) {28 if (val !== '') {29 return true;30 }31 return 'Project name is required!';32 }33 },34 {35 type: 'input',36 name: 'place',37 message: 'Where to init the project:',38 default: process.cwd()39 },40 {41 type: 'list',42 name: 'branch',43 message: 'Select branch:',44 // 可提供分支45 choices: [46 'master' 47 ],48 validate(val) {49 if (val !== '') {50 return true;51 }52 return 'branch is required!';53 }54 }55 ];56 }57 /**58 * 用于准备当前应用程序上下文的异步方法59 * 其中包含加载页面和插件、应用插件等。60 */61 async process() {62 prompt(this._getQuesion())63 .then((opts = {}) => {64 // options65 let { project, place, branch } = opts;66 67 let options = {68 owner: 'wya-team',69 repo: 'vue-env',70 ref: branch || 'master',71 path: 'templates',72 dest: `${place}/${project}`73 };74 log(chalk`{yellow ${JSON.stringify(options, null, '\t')}}`);75 downloadFromGithub(options);76 })77 .catch(e => {78 log(chalk`{red ${e}}`);79 });80 }...

Full Screen

Full Screen

run.js

Source:run.js Github

copy

Full Screen

1const yargs = require('yargs/yargs')2const { hideBin } = require('yargs/helpers')3const { downloadFromGithub } = require("./lib/github");4const argv = yargs(hideBin(process.argv))5 .usage("Usage: $0 [options] [git-repository] [glob-patterns ...]")6 .example("$0 aistyler/yanc/main '**'")7 .options({8 "b": {9 alias: "branch",10 describe: "target branch name. e.g. 'master'",11 type: "string",12 },13 "t": {14 alias: "tag",15 describe: "target tag name. e.g. 'v1.0.0'",16 type: "string",17 },18 "V": {19 alias: "verbose",20 default: false,21 describe: "verbose output",22 type: "boolean",23 },24 "f": {25 alias: "force",26 default: false,27 describe: "*overwrite* the existing files",28 type: "boolean",29 },30 "d": {31 alias: "dryrun",32 default: false,33 describe: "Dry run",34 type: "boolean",35 },36 "topLevelDot": {37 default: true,38 describe: "include top-level dot(.) files",39 type: "boolean",40 },41 "o": {42 alias: "outdir",43 default: "./",44 describe: "Output directory",45 type: "string",46 }47 })48 .demandCommand(1)49 .help('h')50 .epilog('copyright 2019')51 .argv;52//console.log(argv);53(async() => await downloadFromGithub(54 argv._[0], // github repository55 argv._.slice(1), // glob patterns56 { // options57 branch: argv.branch,58 tag: argv.tag,59 verbose: argv.verbose,60 force: argv.force,61 dryrun: argv.dryrun,62 topLevelDot: argv.topLevelDot,63 outdir: argv.outdir,64 }...

Full Screen

Full Screen

github.js

Source:github.js Github

copy

Full Screen

1var util = require('./util.js');2var exports = module.exports = function (option) {3 exports.repos = option.repos || 'https://codeload.github.com/';4 exports.postfix = '/tar.gz/';5};6function downloadFromGithub(address, version, cb, progress) {7 util.download(exports.repos + address + exports.postfix + version, null, cb, progress);8}9function downloadFromMirror(address, version, cb, progress) {10 var parts = address.split('/');11 var ns = parts[0];12 var repos = parts[1];13 var folder = ns.substring(4);14 util.download('http://fis-cloud.bj.bcebos.com/' + folder + '/' + repos + '/' + version + '/all.tar.gz?responseContentDisposition=attachment', null, function(error) {15 if (error) {16 console.log('Download From Mirror fail, fallback to github self.');17 return downloadFromGithub(address, version, cb, progress);18 }19 return cb.apply(this, arguments);20 }, progress);21}22exports.prototype.download = function (id, cb, progress) {23 if (!id) {24 cb(new Error('must given a component ID'));25 return;26 }27 var c = id.split('@');28 if (!c[1]) {29 c[1] = 'master';30 }31 if (c[0].indexOf('fis-components/') === 0 || c[0].indexOf('fis-scaffold/') === 0) {32 return downloadFromMirror(c[0], c[1], cb, progress);33 }34 downloadFromGithub(c[0], c[1], cb, progress);...

Full Screen

Full Screen

downloadAwesomeResources.js

Source:downloadAwesomeResources.js Github

copy

Full Screen

...3const { downloadFromGitHub } = require('../utils')4exports.downloadAwesomeResources = async function () {5 const basePath = path.join(__dirname, '..', '..')6 const newDocsPath = path.join(basePath, 'website', 'community', 'Resources.md')7 const content = await downloadFromGitHub('https://raw.githubusercontent.com/webdriverio-community/awesome-webdriverio', 'main')8 let lines = content.toString().split(/\n/)9 lines = lines.slice(lines.findIndex((line) => line.includes('WebdriverIO Ecosystem')))10 await fs.promises.writeFile(newDocsPath, `---11id: resources12title: Resources13custom_edit_url: https://github.com/webdriverio-community/awesome-webdriverio/edit/main/README.md14---15There are many wonderful curated resources the WebdriverIO community has put together.16Make sure to contribute yours at [\`awesome-webdriverio\`](https://github.com/webdriverio-community/awesome-webdriverio)!17${lines.join('\n')}`)...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriverio = require('webdriverio');2var options = {3 desiredCapabilities: {4 }5};6 .remote(options)7 .init()8 .url('

Full Screen

Using AI Code Generation

copy

Full Screen

1const { remote } = require('webdriverio');2(async () => {3 const browser = await remote({4 capabilities: {5 }6 })7 await browser.downloadFromGitHub('webdriverio', 'webdriverio', 'v5.0.0', '

Full Screen

Using AI Code Generation

copy

Full Screen

1const { remote } = require('webdriverio');2(async () => {3 const browser = await remote({4 capabilities: {5 }6 })7 const download = await browser.downloadFromGitHub('webdriverio', 'webdriverio');8 console.log(download)9 await browser.deleteSession()10})().catch((e) => console.error(e))

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriverio = require('webdriverio');2var options = {3 desiredCapabilities: {4 }5};6var client = webdriverio.remote(options);7 .init()8 .downloadFromGitHub('webdriverio', 'webdriverio', 'v4.0.0', 'webdriverio-v4.0.0.zip')9 .end();10 .init()11 .downloadFromGitHub('webdriverio', 'webdriverio', '', 'webdriverio.zip')12 .end();13 .init()14 .downloadFromGitHub('webdriverio', 'webdriverio', 'v4.0.0')15 .end();16 .init()17 .downloadFromGitHub('webdriverio', 'webdriverio')18 .end();19 .init()20 .downloadFromGitHub('webdriverio', 'webdriverio', '', 'webdriverio.zip')21 .end();22 .init()23 .downloadFromGitHub('webdriverio', 'webdriverio', 'v4.0.0')24 .end();25 .init()26 .downloadFromGitHub('webdriverio', 'webdriverio')27 .end();

Full Screen

Using AI Code Generation

copy

Full Screen

1const download = require('download-git-repo');2const webdriverio = require('webdriverio');3const options = {4 desiredCapabilities: {5 }6};7 .remote(options)8 .init()9 .url('

Full Screen

Using AI Code Generation

copy

Full Screen

1const download = require('download')2const { downloadFromGitHub } = require('webdriverio/build/utils')3const { remote } = require('webdriverio')4describe('webdriver.io page', () => {5 it('should have the right title', async () => {6 const browser = await remote({7 capabilities: {8 }9 })

Full Screen

Using AI Code Generation

copy

Full Screen

1const download = require('download');2const path = require('path');3const fs = require('fs');4const downloadPath = path.resolve(__dirname, 'downloads');5const downloadFromGitHub = require('./downloadFromGitHub');6downloadFromGitHub('

Full Screen

WebdriverIO Tutorial

Wondering what could be a next-gen browser and mobile test automation framework that is also simple and concise? Yes, that’s right, it's WebdriverIO. Since the setup is very easy to follow compared to Selenium testing configuration, you can configure the features manually thereby being the center of attraction for automation testing. Therefore the testers adopt WedriverIO to fulfill their needs of browser testing.

Learn to run automation testing with WebdriverIO tutorial. Go from a beginner to a professional automation test expert with LambdaTest WebdriverIO tutorial.

Chapters

  1. Running Your First Automation Script - Learn the steps involved to execute your first Test Automation Script using WebdriverIO since the setup is very easy to follow and the features can be configured manually.

  2. Selenium Automation With WebdriverIO - Read more about automation testing with WebdriverIO and how it supports both browsers and mobile devices.

  3. Browser Commands For Selenium Testing - Understand more about the barriers faced while working on your Selenium Automation Scripts in WebdriverIO, the ‘browser’ object and how to use them?

  4. Handling Alerts & Overlay In Selenium - Learn different types of alerts faced during automation, how to handle these alerts and pops and also overlay modal in WebdriverIO.

  5. How To Use Selenium Locators? - Understand how Webdriver uses selenium locators in a most unique way since having to choose web elements very carefully for script execution is very important to get stable test results.

  6. Deep Selectors In Selenium WebdriverIO - The most popular automation testing framework that is extensively adopted by all the testers at a global level is WebdriverIO. Learn how you can use Deep Selectors in Selenium WebdriverIO.

  7. Handling Dropdown In Selenium - Learn more about handling dropdowns and how it's important while performing automated browser testing.

  8. Automated Monkey Testing with Selenium & WebdriverIO - Understand how you can leverage the amazing quality of WebdriverIO along with selenium framework to automate monkey testing of your website or web applications.

  9. JavaScript Testing with Selenium and WebdriverIO - Speed up your Javascript testing with Selenium and WebdriverIO.

  10. Cross Browser Testing With WebdriverIO - Learn more with this step-by-step tutorial about WebdriverIO framework and how cross-browser testing is done with WebdriverIO.

Run Webdriverio 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