How to use fs.rimraf method in Appium

Best JavaScript code snippet using appium

fs-specs.js

Source:fs-specs.js Github

copy

Full Screen

...28 });29 describe('mkdir', function () {30 let dirName = path.resolve(__dirname, 'tmp');31 it('should make a directory that does not exist', async function () {32 await fs.rimraf(dirName);33 await fs.mkdir(dirName);34 let exists = await fs.hasAccess(dirName);35 exists.should.be.true;36 });37 it('should not complain if the dir already exists', async function () {38 let exists = await fs.hasAccess(dirName);39 exists.should.be.true;40 await fs.mkdir(dirName);41 });42 it('should still throw an error if something else goes wrong', async function () {43 await fs.mkdir('/bin/foo').should.be.rejected;44 });45 });46 it('hasAccess', async function () {47 (await fs.exists(existingPath)).should.be.ok;48 let nonExistingPath = path.resolve(__dirname, 'wrong-specs.js');49 (await fs.hasAccess(nonExistingPath)).should.not.be.ok;50 });51 it('exists', async function () {52 (await fs.exists(existingPath)).should.be.ok;53 let nonExistingPath = path.resolve(__dirname, 'wrong-specs.js');54 (await fs.exists(nonExistingPath)).should.not.be.ok;55 });56 it('readFile', async function () {57 (await fs.readFile(existingPath, 'utf8')).should.contain('readFile');58 });59 describe('copyFile', function () {60 it('should be able to copy a file', async function () {61 let newPath = path.resolve(await tempDir.openDir(), 'fs-specs.js');62 await fs.copyFile(existingPath, newPath);63 (await fs.readFile(newPath, 'utf8')).should.contain('readFile');64 });65 it('should throw an error if the source does not exist', async function () {66 await fs.copyFile('/sdfsdfsdfsdf', '/tmp/bla').should.eventually.be.rejected;67 });68 });69 it('rimraf', async function () {70 let newPath = path.resolve(await tempDir.openDir(), 'fs-specs.js');71 await fs.copyFile(existingPath, newPath);72 (await fs.exists(newPath)).should.be.true;73 await fs.rimraf(newPath);74 (await fs.exists(newPath)).should.be.false;75 });76 it('sanitizeName', function () {77 fs.sanitizeName(':file?.txt', {78 replacement: '-',79 }).should.eql('-file-.txt');80 });81 it('rimrafSync', async function () {82 let newPath = path.resolve(await tempDir.openDir(), 'fs-specs.js');83 await fs.copyFile(existingPath, newPath);84 (await fs.exists(newPath)).should.be.true;85 fs.rimrafSync(newPath);86 (await fs.exists(newPath)).should.be.false;87 });...

Full Screen

Full Screen

basics-e2e-specs.js

Source:basics-e2e-specs.js Github

copy

Full Screen

...58 // travis can't write to /tmp, so let's create a tmp directory59 try {60 await fs.mkdir(TEMP_DIR);61 } catch (e) {}62 await fs.rimraf(altTmpDir);63 });64 after(async function () {65 await fs.rimraf(TEMP_DIR);66 });67 test(" (1)", {68 launchTimeout: {global: 60000, afterSimLaunch: 10000},69 tmpDir: altTmpDir70 }, {71 afterCreate: (instruments) => { instruments.tmpDir.should.equal(altTmpDir); },72 afterLaunch: async () => {73 (await fs.exists(altTmpDir)).should.be.ok;74 (await fs.exists(path.resolve(altTmpDir, 'instrumentscli0.trace'))).should.be.ok;75 }76 });77 // test(" (2)", {78 // launchTimeout: {global: 60000, afterSimLaunch: 10000},79 // tmpDir: altTmpDir80 // }, {81 // afterCreate: function (instruments) { instruments.tmpDir.should.equal(altTmpDir); },82 // afterLaunch: async function () {83 // (await fs.exists(altTmpDir)).should.be.ok;84 // // tmp dir is deleted at startup so trace file is not incremented85 // (await fs.exists(path.resolve(altTmpDir, 'instrumentscli0.trace'))).should.be.ok;86 // }87 // });88 });89 describe.skip("using different trace dir", function () {90 let altTraceDir = path.resolve(TEMP_DIR, 'abcd');91 before(async function () {92 // travis can't write to /tmp, so let's create a tmp directory93 try {94 await fs.mkdir(TEMP_DIR);95 } catch (e) {}96 await fs.rimraf(altTraceDir);97 });98 after(async function () {99 await fs.rimraf(TEMP_DIR);100 });101 test(" (1)", {102 launchTimeout: {global: 60000, afterSimLaunch: 10000},103 traceDir: altTraceDir104 }, {105 afterCreate: (instruments) => {106 instruments.tmpDir.should.equal('/tmp/appium-instruments');107 },108 afterLaunch: async () => {109 (await fs.exists(altTraceDir)).should.be.ok;110 (await fs.exists(path.resolve(altTraceDir, 'instrumentscli0.trace')))111 .should.be.ok;112 }113 });...

Full Screen

Full Screen

screenshots.js

Source:screenshots.js Github

copy

Full Screen

...6import { fs, tempDir, util } from 'appium-support';7let commands = {};8async function getScreenshotWithIdevicelib (udid, isLandscape) {9 const pathToScreenshotTiff = await tempDir.path({prefix: `screenshot-${udid}`, suffix: '.tiff'});10 await fs.rimraf(pathToScreenshotTiff);11 const pathToResultPng = await tempDir.path({prefix: `screenshot-${udid}`, suffix: '.png'});12 await fs.rimraf(pathToResultPng);13 try {14 try {15 await exec('idevicescreenshot', ['-u', udid, pathToScreenshotTiff]);16 } catch (e) {17 throw new Error(`Cannot take a screenshot from the device '${udid}' using ` +18 `idevicescreenshot. Original error: ${e.message}`);19 }20 let sipsArgs = ['-s', 'format', 'png', pathToScreenshotTiff, '--out', pathToResultPng];21 if (isLandscape) {22 sipsArgs = ['-r', '-90', ...sipsArgs];23 }24 try {25 // The sips tool is only present on Mac OS26 await exec('sips', sipsArgs);27 } catch (e) {28 throw new Error(`Cannot convert a screenshot from TIFF to PNG using sips tool. ` +29 `Original error: ${e.message}`);30 }31 if (!await fs.exists(pathToResultPng)) {32 throw new Error(`Cannot convert a screenshot from TIFF to PNG. The conversion ` +33 `result does not exist at '${pathToResultPng}'`);34 }35 return (await fs.readFile(pathToResultPng)).toString('base64');36 } finally {37 await fs.rimraf(pathToScreenshotTiff);38 await fs.rimraf(pathToResultPng);39 }40}41async function isIdevicescreenshotAvailable () {42 return !!(await fs.which('idevicescreenshot'));43}44commands.getScreenshot = async function () {45 const getScreenshotFromWDA = async () => {46 const data = await this.proxyCommand('/screenshot', 'GET');47 if (!_.isString(data)) {48 throw new Error(`Unable to take screenshot. WDA returned '${JSON.stringify(data)}'`);49 }50 return data;51 };52 try {...

Full Screen

Full Screen

simulator-common-specs.js

Source:simulator-common-specs.js Github

copy

Full Screen

1// transpile:mocha2import SimulatorXcode6 from '../../lib/simulator-xcode-6';3import SimulatorXcode7 from '../../lib/simulator-xcode-7';4import chai from 'chai';5import chaiAsPromised from 'chai-as-promised';6import _ from 'lodash';7import sinon from 'sinon';8import { fs } from '@appium/support';9import B from 'bluebird';10chai.should();11chai.use(chaiAsPromised);12let simulatorClasses = {13 SimulatorXcode6,14 SimulatorXcode715};16for (let [name, simClass] of _.toPairs(simulatorClasses)) {17 describe(`common methods - ${name}`, function () {18 let sim;19 beforeEach(function () {20 sim = new simClass('123', '6.0.0');21 });22 it('should exist', function () {23 simClass.should.exist;24 });25 it('should return a path for getDir()', function () {26 sim.getDir().should.exist;27 });28 it('should return an array for getAppDirs()', async function () {29 let stub = sinon.stub(sim, 'getAppDir').returns(B.resolve(['/App/Path/']));30 sim._platformVersion = 9.1;31 let dirs = await sim.getAppDirs('test');32 dirs.should.have.length(2);33 dirs.should.be.a('array');34 stub.restore();35 });36 describe('cleanCustomApp', function () {37 let sandbox;38 let appBundleId = 'com.some.app';39 beforeEach(function () {40 sandbox = sinon.createSandbox();41 sandbox.spy(fs, 'rimraf');42 });43 afterEach(function () {44 sandbox.restore();45 });46 it('should not delete anything if no directories are found', async function () {47 sandbox.stub(sim, 'getPlatformVersion').returns(B.resolve(7.1));48 sandbox.stub(sim, 'getAppDir').returns(B.resolve());49 await sim.cleanCustomApp('someApp', 'com.some.app');50 sinon.assert.notCalled(fs.rimraf);51 });52 it('should delete app directories', async function () {53 sandbox.stub(sim, 'getPlatformVersion').returns(B.resolve(7.1));54 sandbox.stub(sim, 'getAppDirs').returns(B.resolve(['/some/path', '/another/path']));55 await sim.cleanCustomApp('someApp', 'com.some.app');56 sinon.assert.called(fs.rimraf);57 });58 it('should delete plist file for iOS8+', async function () {59 sandbox.stub(sim, 'getPlatformVersion').returns(B.resolve(9));60 sandbox.stub(sim, 'getAppDirs').returns(B.resolve(['/some/path', '/another/path']));61 await sim.cleanCustomApp('someApp', appBundleId);62 sinon.assert.calledWithMatch(fs.rimraf, /plist/);63 });64 it('should not delete plist file for iOS7.1', async function () {65 sandbox.stub(sim, 'getPlatformVersion').returns(B.resolve(7.1));66 sandbox.stub(sim, 'getAppDirs').returns(B.resolve(['/some/path', '/another/path']));67 await sim.cleanCustomApp('someApp', appBundleId);68 sinon.assert.neverCalledWithMatch(fs.rimraf, /plist/);69 });70 });71 it('should return a path for getLogDir', function () {72 const home = process.env.HOME;73 process.env.HOME = __dirname;74 let logDir = sim.getLogDir();75 logDir.should.equal(`${__dirname}/Library/Logs/CoreSimulator/123`);76 process.env.HOME = home;77 });78 describe('getPlatformVersion', function () {79 let statStub;80 let platformVersion = 8.9;81 beforeEach(function () {82 statStub = sinon.stub(sim, 'stat').returns({sdk: platformVersion});83 });84 afterEach(function () {85 statStub.restore();86 });87 it('should get the correct platform version', async function () {88 let pv = await sim.getPlatformVersion();89 pv.should.equal(platformVersion);90 });91 it('should only call stat once', async function () {92 let pv = await sim.getPlatformVersion();93 pv.should.equal(platformVersion);94 statStub.calledOnce.should.be.true;95 });96 });97 });...

Full Screen

Full Screen

build-webdriveragent.js

Source:build-webdriveragent.js Github

copy

Full Screen

...17 for (const wdaPath of18 await fs.glob('WebDriverAgent-*', {cwd: derivedDataPath, absolute: true})19 ) {20 log.info(`Deleting existing WDA: '${wdaPath}'`);21 await fs.rimraf(wdaPath);22 }23 // Clean and build24 await exec('npx', ['gulp', 'clean:carthage']);25 log.info('Running ./Scripts/build.sh');26 let env = {TARGET: 'runner', SDK: 'sim'};27 try {28 await exec('/bin/bash', ['./Scripts/build.sh'], {env, cwd: rootDir});29 } catch (e) {30 log.error(`===FAILED TO BUILD FOR ${xcodeVersion}`);31 log.error(e.stdout);32 log.error(e.stderr);33 log.error(e.message);34 throw e;35 }36 // Create bundles folder37 const pathToBundles = path.resolve(rootDir, 'bundles');38 await mkdirp(pathToBundles);39 // Start creating zip40 const uncompressedDir = path.resolve(rootDir, 'uncompressed');41 await fs.rimraf(uncompressedDir);42 await mkdirp(uncompressedDir);43 log.info('Creating zip');44 // Move contents of the root to folder called "uncompressed"45 await exec('rsync', [46 '-av', '.', uncompressedDir,47 '--exclude', 'node_modules',48 '--exclude', 'build',49 '--exclude', 'ci-jobs',50 '--exclude', 'lib',51 '--exclude', 'test',52 '--exclude', 'bundles',53 '--exclude', 'azure-templates',54 ], {cwd: rootDir});55 // Move DerivedData/WebDriverAgent-* from Library to "uncompressed" folder56 const wdaPath = (await fs.glob(`${derivedDataPath}/WebDriverAgent-*`))[0];57 await mkdirp(path.resolve(uncompressedDir, 'DerivedData'));58 await fs.rename(wdaPath, path.resolve(uncompressedDir, 'DerivedData', 'WebDriverAgent'));59 // Compress the "uncompressed" bundle as a Zip60 const pathToZip = path.resolve(pathToBundles, `webdriveragent-xcode_${xcodeVersion}.zip`);61 await zip.toArchive(62 pathToZip, {cwd: path.join(rootDir, 'uncompressed')}63 );64 log.info(`Zip bundled at "${pathToZip}"`);65 // Now just zip the .app and place it in the root directory66 // This zip file will be published to NPM67 const wdaAppBundle = 'WebDriverAgentRunner-Runner.app';68 const appBundlePath = path.join(uncompressedDir, 'DerivedData', 'WebDriverAgent',69 'Build', 'Products', 'Debug-iphonesimulator', wdaAppBundle);70 const appBundleZipPath = path.join(rootDir, `${wdaAppBundle}.zip`);71 await fs.rimraf(appBundleZipPath);72 log.info(`Created './${wdaAppBundle}.zip'`);73 await zip.toArchive(appBundleZipPath, {cwd: appBundlePath});74 log.info(`Zip bundled at "${appBundleZipPath}"`);75 // Clean up the uncompressed directory76 await fs.rimraf(uncompressedDir);77}78if (require.main === module) {79 asyncify(buildWebDriverAgent);80}...

Full Screen

Full Screen

crowdin-sync-translations.js

Source:crowdin-sync-translations.js Github

copy

Full Screen

...71 continue;72 }73 const dstPath = path.resolve(RESOURCES_ROOT, name);74 if (await fs.exists(dstPath)) {75 await fs.rimraf(dstPath);76 }77 await fs.mv(currentPath, path.resolve(RESOURCES_ROOT, name), {78 mkdirp: true79 });80 log.info(`Successfully updated resources for the '${name}' language`);81 }82 } finally {83 await fs.rimraf(tmpRoot);84 }85 } finally {86 await fs.rimraf(zipPath);87 }88}...

Full Screen

Full Screen

storage-client-e2e-specs.js

Source:storage-client-e2e-specs.js Github

copy

Full Screen

...23 versions: ['2.35', '2.34'],24 })).length.should.be.greaterThan(0);25 (await fs.readdir(tmpRoot)).length.should.be.eql(2);26 } finally {27 await fs.rimraf(tmpRoot);28 }29 });30 it('should retrieve chromedrivers by minBrowserVersion (non exact match)', async function () {31 const tmpRoot = await tempDir.openDir();32 const client = new ChromedriverStorageClient({33 chromedriverDir: tmpRoot,34 });35 try {36 (await client.syncDrivers({37 minBrowserVersion: '44',38 })).length.should.be.greaterThan(0);39 (await fs.readdir(tmpRoot)).length.should.be.greaterThan(0);40 } finally {41 await fs.rimraf(tmpRoot);42 }43 });44 it('should retrieve chromedrivers by minBrowserVersion (exact match)', async function () {45 const tmpRoot = await tempDir.openDir();46 const client = new ChromedriverStorageClient({47 chromedriverDir: tmpRoot,48 });49 try {50 (await client.syncDrivers({51 minBrowserVersion: '74',52 })).length.should.be.greaterThan(0);53 (await fs.readdir(tmpRoot)).length.should.be.greaterThan(0);54 } finally {55 await fs.rimraf(tmpRoot);56 }57 });...

Full Screen

Full Screen

files.js

Source:files.js Github

copy

Full Screen

1var copy, fs, rimraf, rm;2fs = require("fs");3rimraf = require("rimraf");4copy = function(path, sourcePath, targetPath, cb) {5 var readStream, writeStream;6 targetPath = path.replace(sourcePath, targetPath);7 readStream = fs.createReadStream(path);8 writeStream = fs.createWriteStream(targetPath);9 readStream.on("error", cb);10 writeStream.on("error", cb);11 writeStream.on("finish", cb);12 return readStream.pipe(writeStream);13};14rm = function(path, sourcePath, targetPath, cb) {15 targetPath = path.replace(sourcePath, targetPath);16 return rimraf(targetPath, cb);17};18module.exports = {19 rm: rm,20 copy: copy...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var rimraf = require('rimraf');2rimraf('/path/to/dir', function() { console.log('done'); });3var rimraf = require('fs').rimraf;4rimraf('/path/to/dir', function() { console.log('done'); });5var rimraf = require('fs-extra').rimraf;6rimraf('/path/to/dir', function() { console.log('done'); });7var rimraf = require('rimraf');8rimraf('/path/to/dir', function() { console.log('done'); });9var rimraf = require('rimraf');10rimraf('/path/to/dir', function() { console.log('done'); });11var rimraf = require('rimraf');12rimraf('/path/to/dir', function() { console.log('done'); });13var rimraf = require('rimraf');14rimraf('/path/to/dir', function() { console.log('done'); });15var rimraf = require('rimraf');16rimraf('/path/to/dir', function() { console.log('done'); });17var rimraf = require('rimraf');18rimraf('/path/to/dir', function() { console.log('done'); });19var rimraf = require('rimraf');20rimraf('/path/to/dir', function() { console.log('done'); });21var rimraf = require('rimraf');22rimraf('/path/to/dir', function() { console.log('done'); });23var rimraf = require('rimraf');24rimraf('/path/to/dir', function() { console.log('done'); });25var rimraf = require('rimraf');26rimraf('/path/to/dir', function() { console.log('done'); });

Full Screen

Using AI Code Generation

copy

Full Screen

1var rimraf = require('rimraf');2var path = require('path');3var appium = require('appium');4var wd = require('wd');5var server = appium();6var driver = wd.promiseChainRemote('localhost', 4723);7var desired = {8 app: path.resolve(__dirname, 'app.apk'),9};10server.listen(4723, function() {11 driver.init(desired).then(function() {12 }).then(function() {13 }).then(function() {14 }).then(function() {15 }).then(function() {16 }).then(function() {17 }).then(function() {18 }).then(function() {19 }).then(function() {20 }).then(function() {21 }).then(function() {22 }).then(function() {23 }).then(function() {24 }).then(function() {25 }).then(function() {26 }).then(function() {

Full Screen

Using AI Code Generation

copy

Full Screen

1var rimraf = require("rimraf");2rimraf("path/to/dir", function (err) {3 if (err) {4 console.log("error");5 } else {6 console.log("success");7 }8});9var rimraf = require("rimraf");10rimraf("path/to/dir", function (err) {11 if (err) {12 console.log("error");13 } else {14 console.log("success");15 }16});17var rimraf = require("rimraf");18rimraf("path/to/dir", function (err) {19 if (err) {20 console.log("error");21 } else {22 console.log("success");23 }24});25var rimraf = require("rimraf");26rimraf("path/to/dir", function (err) {27 if (err) {28 console.log("error");29 } else {30 console.log("success");31 }32});33var rimraf = require("rimraf");34rimraf("path/to/dir", function (err) {35 if (err) {36 console.log("error");37 } else {38 console.log("success");39 }40});41var rimraf = require("rimraf");42rimraf("path/to/dir", function (err) {43 if (err) {44 console.log("error");45 } else {46 console.log("success");47 }48});49var rimraf = require("rimraf");50rimraf("path/to/dir", function (err) {51 if (err) {52 console.log("error");53 } else {54 console.log("success");55 }56});57var rimraf = require("rimraf");58rimraf("path/to/dir", function (err) {59 if (err) {60 console.log("error");61 } else {62 console.log("success");63 }64});65var rimraf = require("rimraf");66rimraf("path/to

Full Screen

Using AI Code Generation

copy

Full Screen

1var rimraf = require('rimraf');2rimraf('./appium.log', function (err) {3 console.log(err);4});5var rimraf = require('rimraf');6rimraf('./appium.log', function (err) {7 console.log(err);8});9var fs = require('fs');10fs.unlink('./appium.log', function (err) {11 console.log(err);12});13var fs = require('fs');14fs.unlinkSync('./appium.log');15console.log('file deleted');16var fs = require('fs');17fs.unlinkSync('./appium.log');18console.log('file deleted');19var fs = require('fs');20fs.unlink('./appium.log', function (err) {21 console.log(err);22});

Full Screen

Using AI Code Generation

copy

Full Screen

1var rimraf = require('rimraf');2var path = require('path');3var testFolder = path.resolve(__dirname, 'testFolder');4rimraf(testFolder, function(err) {5 console.log(err);6});7var rimraf = require('rimraf');8var path = require('path');9var testFolder = path.resolve(__dirname, 'testFolder');10rimraf(testFolder, function(err) {11 console.log(err);12});

Full Screen

Using AI Code Generation

copy

Full Screen

1var rimraf = require('rimraf');2rimraf('/Users/username/AppData/Local/Temp/adb', function (err) {3 if (err) {4 console.log('Error: ' + err);5 } else {6 console.log('success');7 }8});

Full Screen

Using AI Code Generation

copy

Full Screen

1var rimraf = require("rimraf");2rimraf("C:\\Users\\Test\\Desktop\\Appium\\", function (err) {3 if (err) {4 console.log("Error while deleting the folder");5 } else {6 console.log("Folder deleted successfully");7 }8});9var fs = require("fs");10fs.rmdir("C:\\Users\\Test\\Desktop\\Appium\\", function (err) {11 if (err) {12 console.log("Error while deleting the folder");13 } else {14 console.log("Folder deleted successfully");15 }16});

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