Best JavaScript code snippet using appium-xcuitest-driver
whichFallback.js
Source:whichFallback.js
1// TODO: properly rewrite tests by using sinon2import { module, test } from "qunit";3import whichFallbackInjector from "inject-loader!utils/node/fs/whichFallback";4module( "utils/node/fs/whichFallback" );5test( "No fallback", async assert => {6 assert.expect( 24 );7 let expected;8 let isExecutable = () => true;9 const { default: whichFallback } = whichFallbackInjector({10 "path": {},11 "utils/node/resolvePath": {},12 "utils/node/platform": {13 platform: "linux"14 },15 "utils/node/fs/stat": {16 isExecutable,17 async stat() {18 assert.ok( false, "Should not get called" );19 }20 },21 "utils/node/fs/which": async ( path, callback ) => {22 assert.step( path );23 if ( path !== expected ) {24 throw new Error();25 }26 assert.strictEqual( callback, isExecutable, "Uses the correct verification callback" );27 return path;28 }29 });30 await assert.rejects(31 whichFallback( "" ),32 new Error( "Missing executable name" ),33 "Rejects on missing executable"34 );35 await assert.rejects(36 whichFallback( "foo" ),37 new Error( "Executables were not found" ),38 "Rejects"39 );40 assert.checkSteps( [ "foo" ], "Calls which() in correct order" );41 await assert.rejects(42 whichFallback([ "foo", "bar" ]),43 new Error( "Executables were not found" ),44 "Rejects"45 );46 assert.checkSteps( [ "foo", "bar" ], "Calls which() in correct order" );47 await assert.rejects(48 whichFallback({ linux: "foo", darwin: "bar" }),49 new Error( "Executables were not found" ),50 "Rejects"51 );52 assert.checkSteps( [ "foo" ], "Calls which() in correct order" );53 await assert.rejects(54 whichFallback({ linux: [ "foo", "baz" ], darwin: "bar" }),55 new Error( "Executables were not found" ),56 "Rejects"57 );58 assert.checkSteps( [ "foo", "baz" ], "Calls which() in correct order" );59 expected = "bar";60 await ( async () => {61 const resolvedPath = await whichFallback([ "foo", "bar", "baz" ]);62 assert.strictEqual( resolvedPath, "bar", "Resolves with correct path" );63 assert.checkSteps( [ "foo", "bar" ], "Calls which() in correct order" );64 })();65 isExecutable = () => false;66 await ( async () => {67 const resolvedPath = await whichFallback( "bar", null, isExecutable );68 assert.strictEqual( resolvedPath, "bar", "Resolves with correct path" );69 assert.checkSteps( [ "bar" ], "Calls which() in correct order" );70 })();71});72test( "Fallback only", async assert => {73 assert.expect( 73 );74 let expected;75 let isExecutable = () => true;76 const { default: whichFallback } = whichFallbackInjector({77 "path": {78 join( ...args ) {79 assert.step( "join" );80 return args.join( "/" );81 }82 },83 "utils/node/platform": {84 platform: "linux"85 },86 "utils/node/resolvePath": path => {87 assert.step( "resolvePath" );88 assert.step( path );89 return path;90 },91 "utils/node/fs/stat": {92 isExecutable,93 async stat( path, callback ) {94 assert.step( "stat" );95 assert.step( path );96 if ( expected !== path ) {97 throw new Error();98 }99 assert.strictEqual( callback, isExecutable, "Uses correct verification callback" );100 return path;101 }102 },103 "utils/node/fs/which": async () => {104 assert.ok( false, "Should not get called" );105 }106 });107 await assert.rejects(108 whichFallback( "a", "/A", null, true ),109 new Error( "Executables were not found" ),110 "Rejects"111 );112 assert.checkSteps(113 [114 "resolvePath", "/A",115 "join", "stat", "/A/a"116 ],117 "Calls methods in correct order"118 );119 await assert.rejects(120 whichFallback( [ "a", "b" ], [ "/A", "/B" ], null, true ),121 new Error( "Executables were not found" ),122 "Rejects"123 );124 assert.checkSteps(125 [126 "resolvePath", "/A",127 "join", "stat", "/A/a",128 "join", "stat", "/A/b",129 "resolvePath", "/B",130 "join", "stat", "/B/a",131 "join", "stat", "/B/b"132 ],133 "Calls methods in correct order"134 );135 await assert.rejects(136 whichFallback(137 [ "a", "b" ],138 {139 linux: [ "/A", "/B" ],140 darwin: [ "/C", "/D" ]141 },142 null,143 true144 ),145 new Error( "Executables were not found" ),146 "Rejects"147 );148 assert.checkSteps(149 [150 "resolvePath", "/A",151 "join", "stat", "/A/a",152 "join", "stat", "/A/b",153 "resolvePath", "/B",154 "join", "stat", "/B/a",155 "join", "stat", "/B/b"156 ],157 "Calls methods in correct order"158 );159 expected = "/B/b";160 await ( async () => {161 const path = await whichFallback( [ "a", "b", "c" ], [ "/A", "/B", "/C" ], null, true );162 assert.strictEqual( path, expected, "Resolves" );163 assert.checkSteps(164 [165 "resolvePath", "/A",166 "join", "stat", "/A/a",167 "join", "stat", "/A/b",168 "join", "stat", "/A/c",169 "resolvePath", "/B",170 "join", "stat", "/B/a",171 "join", "stat", "/B/b"172 ],173 "Calls methods in correct order"174 );175 })();176 isExecutable = () => false;177 await ( async () => {178 const path = await whichFallback( "b", "/B", isExecutable, true );179 assert.strictEqual( path, expected, "Resolves" );180 assert.checkSteps(181 [182 "resolvePath", "/B",183 "join", "stat", "/B/b"184 ],185 "Calls methods in correct order"186 );187 })();188});189test( "With fallback", async assert => {190 assert.expect( 49 );191 let expected;192 let isExecutable = () => true;193 const check = name => async ( path, callback ) => {194 assert.step( name );195 assert.step( path );196 if ( expected !== path ) {197 throw new Error();198 }199 assert.strictEqual( callback, isExecutable, "Uses correct verification callback" );200 return path;201 };202 const { default: whichFallback } = whichFallbackInjector({203 "path": {204 join( ...args ) {205 assert.step( "join" );206 return args.join( "/" );207 }208 },209 "utils/node/platform": {210 platform: "linux"211 },212 "utils/node/resolvePath": path => {213 assert.step( "resolvePath" );214 assert.step( path );215 return path;216 },217 "utils/node/fs/stat": {218 isExecutable,219 stat: check( "stat" )220 },221 "utils/node/fs/which": check( "which" )222 });223 await assert.rejects(224 whichFallback( [ "a", "b" ], [ "/A", "/B" ] ),225 new Error( "Executables were not found" ),226 "Rejects"227 );228 assert.checkSteps(229 [230 "which", "a",231 "which", "b",232 "resolvePath", "/A",233 "join", "stat", "/A/a",234 "join", "stat", "/A/b",235 "resolvePath", "/B",236 "join", "stat", "/B/a",237 "join", "stat", "/B/b"238 ],239 "Calls methods in correct order"240 );241 expected = "b";242 await ( async () => {243 const resolvedPath = await whichFallback( [ "a", "b" ], [ "/A", "/B" ] );244 assert.strictEqual( resolvedPath, expected, "Resolves" );245 assert.checkSteps(246 [247 "which", "a",248 "which", "b"249 ],250 "Calls methods in correct order"251 );252 })();253 expected = "/B/a";254 await ( async () => {255 const resolvedPath = await whichFallback( [ "a", "b" ], [ "/A", "/B" ] );256 assert.strictEqual( resolvedPath, expected, "Resolves" );257 assert.checkSteps(258 [259 "which", "a",260 "which", "b",261 "resolvePath", "/A",262 "join", "stat", "/A/a",263 "join", "stat", "/A/b",264 "resolvePath", "/B",265 "join", "stat", "/B/a"266 ],267 "Calls methods in correct order"268 );269 })();...
screenshots-specs.js
Source:screenshots-specs.js
1import sinon from 'sinon';2import XCUITestDriver from '../../..';3import { fs, tempDir } from 'appium-support';4const simctlModule = require('node-simctl');5const teenProcessModule = require('teen_process');6describe('screenshots commands', function () {7 let driver;8 let proxyStub;9 const base64Response = 'aGVsbG8=';10 beforeEach(function () {11 driver = new XCUITestDriver();12 proxyStub = sinon.stub(driver, 'proxyCommand');13 });14 afterEach(function () {15 proxyStub.reset();16 });17 describe('getScreenshot', function () {18 describe('simulator', function () {19 let simctlStub = sinon.stub(simctlModule, 'getScreenshot');20 afterEach(function () {21 simctlStub.reset();22 });23 it('should get a screenshot from WDA if no errors are detected', async function () {24 proxyStub.returns(base64Response);25 driver.opts.realDevice = false;26 await driver.getScreenshot();27 proxyStub.calledOnce.should.be.true;28 proxyStub.firstCall.args[0].should.eql('/screenshot');29 proxyStub.firstCall.args[1].should.eql('GET');30 simctlStub.notCalled.should.be.true;31 });32 it('should get a screenshot from simctl if WDA call fails and Xcode version >= 8.1', async function () {33 proxyStub.returns(null);34 simctlStub.returns(base64Response);35 driver.opts.realDevice = false;36 driver.xcodeVersion = {37 versionFloat: 8.338 };39 const result = await driver.getScreenshot();40 result.should.equal(base64Response);41 proxyStub.calledOnce.should.be.true;42 simctlStub.calledOnce.should.be.true;43 });44 });45 describe('real device', function () {46 it('should get a screenshot from WDA if no errors are detected', async function () {47 proxyStub.returns(base64Response);48 driver.opts.realDevice = true;49 await driver.getScreenshot();50 proxyStub.calledOnce.should.be.true;51 proxyStub.firstCall.args[0].should.eql('/screenshot');52 proxyStub.firstCall.args[1].should.eql('GET');53 });54 describe('idevicescreenshot', function () {55 const tiffPath = '/some/file.tiff';56 const pngPath = '/some/file.png';57 const udid = '1234';58 const toolName = 'idevicescreenshot';59 const pngFileContent = 'blabla';60 let fsExistsStub;61 let fsWhichStub;62 let fsRimRafStub;63 let fsReadFileStub;64 let execStub;65 let pathStub;66 beforeEach(function () {67 driver.opts.realDevice = true;68 driver.opts.udid = udid;69 });70 afterEach(function () {71 for (const stub of [fsExistsStub, fsWhichStub, fsReadFileStub, fsRimRafStub, execStub, pathStub]) {72 if (stub) {73 stub.restore();74 }75 }76 });77 describe('success', function () {78 beforeEach(function () {79 fsExistsStub = sinon.stub(fs, 'exists');80 fsExistsStub.returns(true);81 fsWhichStub = sinon.stub(fs, 'which');82 fsWhichStub.returns(toolName);83 fsRimRafStub = sinon.stub(fs, 'rimraf');84 fsReadFileStub = sinon.stub(fs, 'readFile');85 fsReadFileStub.returns(pngFileContent);86 execStub = sinon.stub(teenProcessModule, 'exec');87 pathStub = sinon.stub(tempDir, 'path');88 pathStub.withArgs({prefix: `screenshot-${udid}`, suffix: '.tiff'}).returns(tiffPath);89 pathStub.withArgs({prefix: `screenshot-${udid}`, suffix: '.png'}).returns(pngPath);90 });91 afterEach(function () {92 fsWhichStub.calledOnce.should.be.true;93 fsWhichStub.firstCall.args[0].should.eql(toolName);94 execStub.calledTwice.should.be.true;95 execStub.firstCall.args[0].should.eql(toolName);96 execStub.firstCall.args[1].should.eql(['-u', udid, tiffPath]);97 execStub.secondCall.args[0].should.eql('sips');98 execStub.secondCall.args[1].should.eql(99 ['-r', '-90', '-s', 'format', 'png', tiffPath, '--out', pngPath]);100 fsRimRafStub.callCount.should.eql(4);101 fsReadFileStub.calledOnce.should.be.true;102 fsReadFileStub.firstCall.args[0].should.eql(pngPath);103 pathStub.calledTwice.should.be.true;104 });105 it('should use idevicescreenshot if WDA fails', async function () {106 proxyStub.onFirstCall().returns(null);107 proxyStub.onSecondCall().returns('LANDSCAPE');108 (await driver.getScreenshot()).should.eql(pngFileContent.toString('base64'));109 proxyStub.callCount.should.eql(2);110 proxyStub.firstCall.args.should.eql(['/screenshot', 'GET']);111 proxyStub.secondCall.args.should.eql(['/orientation', 'GET']);112 });113 it('should use idevicescreenshot if specified in realDeviceScreenshotter cap', async function () {114 proxyStub.onFirstCall().returns('LANDSCAPE');115 driver.opts.realDeviceScreenshotter = 'idevicescreenshot';116 (await driver.getScreenshot()).should.eql(pngFileContent.toString('base64'));117 proxyStub.callCount.should.eql(1);118 });119 });120 describe('failure', function () {121 beforeEach(function () {122 proxyStub.onFirstCall().returns(null);123 fsWhichStub = sinon.stub(fs, 'which');124 fsWhichStub.throws(new Error('No program found'));125 });126 afterEach(function () {127 fsWhichStub.calledOnce.should.be.true;128 fsWhichStub.firstCall.args[0].should.eql(toolName);129 });130 it('should throw an error if idevicescreenshot is not available and realDeviceScreenshotter set', async function () {131 driver.opts.realDeviceScreenshotter = 'idevicescreenshot';132 await driver.getScreenshot().should.eventually.be.rejectedWith(/No 'idevicescreenshot' program found/);133 });134 });135 });136 });137 });...
location-specs.js
Source:location-specs.js
1import sinon from 'sinon';2import XCUITestDriver from '../../..';3import { fs } from 'appium-support';4import * as teenProcess from 'teen_process';5describe('location commands', function () {6 const udid = '1234';7 const toolName = 'idevicelocation';8 const driver = new XCUITestDriver();9 const proxySpy = sinon.stub(driver, 'proxyCommand');10 afterEach(function () {11 proxySpy.reset();12 });13 describe('setLocation', function () {14 let execStub;15 let fsWhichStub;16 beforeEach(function () {17 execStub = sinon.stub(teenProcess, 'exec');18 fsWhichStub = sinon.stub(fs, 'which');19 });20 afterEach(function () {21 execStub.restore();22 fsWhichStub.restore();23 });24 it('should fail when location object is wrong', async function () {25 await driver.setGeoLocation({}).should.be.rejectedWith('Both latitude and longitude should be set');26 });27 describe('on real device', function () {28 beforeEach(function () {29 driver.opts.udid = udid;30 driver.opts.realDevice = true;31 });32 it('should use idevicelocation to set a location', async function () {33 fsWhichStub.returns(toolName);34 await driver.setGeoLocation({latitude: '1.234', longitude: '2.789'});35 execStub.calledOnce.should.be.true;36 execStub.firstCall.args[0].should.eql(toolName);37 execStub.firstCall.args[1].should.eql(['-u', udid, '1.234', '2.789']);38 });39 it('should use idevicelocation to set a location with negative values', async function () {40 fsWhichStub.returns(toolName);41 await driver.setGeoLocation({latitude: 1.234, longitude: -2});42 execStub.calledOnce.should.be.true;43 execStub.firstCall.args[0].should.eql(toolName);44 execStub.firstCall.args[1].should.eql(['-u', udid, '1.234', '--', '-2']);45 });46 it('should fail when idevicelocation doesnt exist on the host', async function () {47 fsWhichStub.throws();48 await driver.setGeoLocation({49 latitude: '1.234',50 longitude: '2.789'}51 ).should.be.rejectedWith(`idevicelocation doesn't exist on the host`);52 });53 });54 describe('on simulator', function () {55 let deviceSetLocationSpy;56 beforeEach(function () {57 driver.opts.realDevice = false;58 deviceSetLocationSpy = sinon.spy();59 driver.opts.device = {60 setGeolocation: deviceSetLocationSpy,61 };62 });63 afterEach(function () {64 deviceSetLocationSpy.resetHistory();65 });66 it('should set string coordinates', async function () {67 await driver.setGeoLocation({latitude: '1.234', longitude: '2.789'});68 deviceSetLocationSpy.firstCall.args[0].should.eql('1.234');69 deviceSetLocationSpy.firstCall.args[1].should.eql('2.789');70 });71 it('should set number coordinates', async function () {72 await driver.setGeoLocation({latitude: 1, longitude: -2});73 deviceSetLocationSpy.firstCall.args[0].should.eql('1');74 deviceSetLocationSpy.firstCall.args[1].should.eql('-2');75 });76 });77 });...
which.js
Source:which.js
1// TODO: properly rewrite tests by using sinon2import { module, test } from "qunit";3import whichInjector from "inject-loader!utils/node/fs/which";4module( "utils/node/fs/which" );5test( "Relative or absolute path", async assert => {6 assert.expect( 6 );7 const isFile = () => {};8 const { default: which } = whichInjector({9 "utils/node/env-path": {10 paths: []11 },12 "utils/node/fs/stat": {13 async stat( dir, callback ) {14 assert.strictEqual( dir, "foo/bar", "Tries to find foo/bar" );15 assert.strictEqual( callback, isFile, "Uses correct directory validation" );16 return dir;17 }18 },19 "path": {20 sep: "/"21 }22 });23 await assert.rejects(24 which(),25 new Error( "Missing file" ),26 "Rejects on missing file"27 );28 await assert.rejects(29 which( "" ),30 new Error( "Missing file" ),31 "Rejects on empty file"32 );33 await assert.rejects(34 which( "foo", isFile ),35 new Error( "Could not find foo" ),36 "Rejects if file can't be found"37 );38 const resolvedPath = await which( "foo/bar", isFile );39 assert.strictEqual( resolvedPath, "foo/bar", "Finds foo/bar" );40});41test( "Path iteration", async assert => {42 assert.expect( 26 );43 let expected;44 const isFile = () => {};45 const { default: which } = whichInjector({46 "utils/node/env-path": {47 paths: [48 "/path/to/a",49 "/path/to/b"50 ]51 },52 "utils/node/fs/stat": {53 async stat( path, callback ) {54 assert.step( "stat" );55 assert.step( path );56 assert.strictEqual( callback, isFile, "Uses correct directory validation" );57 if ( path !== expected ) {58 throw new Error( "fail" );59 }60 return path;61 }62 },63 "path": {64 sep: "/",65 join( ...paths ) {66 assert.step( "join" );67 return paths.join( "/" );68 }69 }70 });71 await assert.rejects(72 which( "foo", isFile ),73 new Error( "Could not find foo" ),74 "Rejects"75 );76 assert.checkSteps(77 [78 "join", "stat", "/path/to/a/foo",79 "join", "stat", "/path/to/b/foo"80 ],81 "Calls functions in correct order"82 );83 expected = "/path/to/b/foo";84 await ( async () => {85 const path = await which( "foo", isFile );86 assert.strictEqual( path, expected, "Resolves with correct path" );87 assert.checkSteps(88 [89 "join", "stat", "/path/to/a/foo",90 "join", "stat", "/path/to/b/foo"91 ],92 "Calls functions in correct order"93 );94 })();95 expected = "/path/to/a/foo";96 await ( async () => {97 const path = await which( "foo", isFile );98 assert.strictEqual( path, expected, "Resolves with correct path" );99 assert.checkSteps(100 [101 "join", "stat", "/path/to/a/foo"102 ],103 "Calls functions in correct order"104 );105 })();...
index.js
Source:index.js
1module.exports = function () {2 return {3 configureWebpack(config, isServer) {4 let rules = [];5 // Tree-sitter is only used for client-side code.6 // Don't try to load it on the server.7 if (isServer) {8 rules.push({9 test: /web-tree-sitter/,10 loader: "null-loader",11 });12 } else {13 // web-tree-sitter has a hard-coded path to tree-sitter.wasm,14 // (see https://github.com/tree-sitter/tree-sitter/issues/559)15 // which some browsers treat as absolute and others as relative.16 // This breaks everything. Rewrite it to always use an absolute path.17 rules.push({18 test: /tree-sitter\.js$/,19 loader: "string-replace-loader",20 options: {21 search: '"tree-sitter.wasm"',22 replace: '"/tree-sitter.wasm"',23 strict: true,24 },25 });26 }27 return {28 // web-tree-sitter tries to import "fs", which can be ignored.29 // https://github.com/tree-sitter/tree-sitter/issues/46630 node: {31 fs: "empty",32 },33 module: { rules },34 };35 },36 };...
webpack.config.js
Source:webpack.config.js
1/**2 * The doc doesn't really mention using webpack.config.js, but .storybook/main.js instead.3 *4 * Nevertheless, configuring the webpack.config.js seems to work fine.5 *6 * XXX Storybook uses Webpack 4, while our Next.js app uses Webpack 5.7 *8 * @param config9 * @param mode10 * @return {Promise<*>}11 * @see https://storybook.js.org/docs/react/configure/webpack12 * @see https://storybook.js.org/docs/react/configure/webpack#using-your-existing-config13 */14module.exports = async ({ config, mode }) => {15 /**16 * Fixes npm packages that depend on `fs` module, etc.17 *18 * E.g: "winston" would fail to load without this, because it relies on fs, which isn't available during browser build.19 *20 * @see https://github.com/storybookjs/storybook/issues/4082#issuecomment-49537089621 */22 config.node = {23 fs: 'empty',24 tls: 'empty',25 net: 'empty',26 module: 'empty',27 console: true,28 };29 return config;...
version.js
Source:version.js
1const getPackageVersion = require("get-pkg-version")2 , { readlinkSync } = require("fs")3 , which = require("which")4 , path = require("path")5 , fsutils = require("@project-furnace/fsutils")6 ;7module.exports = async () => {8 9 try {10 const version = await getPackageVersion("@project-furnace/furnace-cli");11 console.log(version);12 } catch (err) {13 const binPath = which.sync("furnace");14 const linkPath = readlinkSync(binPath);15 const resolvedPath = path.resolve(binPath, "..", linkPath)16 const baseDir = path.dirname(resolvedPath);17 const packageJson = path.join(baseDir, "package.json");18 if (fsutils.exists(packageJson)) {19 const package = JSON.parse(fsutils.readFile(packageJson));20 console.log(package.version);21 } else {22 console.log(`unable to find package.json at ${packageJson}`);23 }24 }...
server.js
Source:server.js
1var _Orator = require(__dirname+'/../../server/Headlight-NodeSDK.js').new(2 {3 Product:'Headlight-SDK-App-Sample',4 // The folder to serve static web files from for this app. By default, use the Stage folder.5 StaticContentFolder: __dirname+'/stage/',6 // Log streams are also different because Run logs can't write to the root FS which would be the folder in this case.7 "LogStreams":8 [9 {10 "level": "trace",11 "path": `${__dirname}/Run.log`12 },13 {14 "level": "trace",15 "streamtype": "prettystream"16 }17 ],18 }).orator();...
Using AI Code Generation
1const fs = require('fs');2const path = require('path');3const { remote } = require('webdriverio');4const opts = {5 capabilities: {6 },7};8const client = await remote(opts);9const app = await client.getAppStrings('en');10const appPath = app['appPath'];11const appDir = path.dirname(appPath);12const appPkg = path.join(appDir, 'Payload', 'my.app');13const appPkgInfo = await fs.which(appPkg);14console.log(appPkgInfo);15await client.deleteSession();16 at XCUITestDriver.start (/usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/lib/driver.js:491:11)17 at AppiumDriver.createSession (/usr/local/lib/node_modules/appium/lib/appium.js:359:35)18 at processTicksAndRejections (internal/process/task_queues.js:93:5)19 at async handler (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/lib/protocol/protocol.js:303:21)20 at async AppiumDriver.executeCommand (/usr/local/lib/node_modules/appium/lib/appium.js:523:7)21 at async handler (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/lib/protocol/protocol.js:303:21)22 at async ProtocolConverter.exec (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/lib/protocol/protocol.js:473:14)23 at async AppiumDriver.executeCommand (/usr/local/lib/node_modules/appium/lib/appium.js:523:7)24 at async handler (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/lib/protocol/protocol.js:303:21)25 at async ProtocolConverter.exec (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/lib/protocol/protocol.js:473:14)26 at async AppiumDriver.executeCommand (/usr/local/lib/node_modules/appium/lib/appium.js:523:7)27 at async handler (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/lib/protocol/protocol.js:303:21)
Using AI Code Generation
1var fs = require('fs');2var path = require('path');3var wd = require('wd');4var assert = require('assert');5var desired = {6 app: path.resolve(__dirname, 'UICatalog.app'),7};8var driver = wd.promiseChainRemote('localhost', 4723);9 .init(desired)10 .then(function() {11 .source()12 .then(function(source) {13 var re = /<XCUIElementTypeStaticText type="XCUIElementTypeStaticText" name="(.+?)" label="(.+?)" value="(.+?)" dom="(.+?)" enabled="(.+?)" visible="(.+?)" hint="(.+?)" x="(.+?)" y="(.+?)" width="(.+?)" height="(.+?)"/g;14 var str = source;15 var m;16 var elementNames = [];17 while ((m = re.exec(str)) !== null) {18 if (m.index === re.lastIndex) {19 re.lastIndex++;20 }21 console.log(m[2]);22 elementNames.push(m[2]);23 }
Using AI Code Generation
1const fs = require('fs');2const path = require('path');3const { exec } = require('child_process');4const { promisify } = require('util');5const execAsync = promisify(exec);6const { remote } = require('webdriverio');7const opts = {8 capabilities: {9 }10};11(async function main() {12 try {13 const driver = await remote(opts);14 const bundleId = await driver.execute('mobile: launchApp', { bundleId: 'com.apple.Preferences' });15 const { stdout } = await execAsync('xcrun simctl get_app_container booted com.apple.Preferences');16 const appContainer = stdout.trim();17 const filePath = path.resolve(appContainer, 'Library/Preferences/com.apple.Preferences.plist');18 const fileExists = await driver.execute('mobile: fsExists', { path: filePath });19 const fileContent = await driver.execute('mobile: fsReadFile', { path: filePath });20 console.log('fileContent', fileContent);21 await driver.execute('mobile: fsWriteFile', { path: filePath, data: 'Test' });22 await driver.execute('mobile: fsDeleteFile', { path: filePath });23 await driver.execute('mobile: fsDeleteDir', { path: filePath });24 await driver.execute('mobile: fsMakeDir', { path: filePath });25 await driver.execute('mobile: fsListDir', { path: filePath });26 await driver.execute('mobile: fsMoveDir', { origin: filePath, destination: filePath });27 await driver.execute('mobile: fsMoveFile', { origin: filePath, destination: filePath });28 await driver.execute('mobile: fsCopyDir', { origin: filePath, destination: filePath });29 await driver.execute('mobile: fsCopyFile', { origin: filePath, destination: filePath });30 await driver.execute('mobile: fsGetInfo', { path: filePath });31 await driver.execute('mobile:
Using AI Code Generation
1const fs = require('fs');2const path = require('path');3const app = path.resolve('/Users/saikrishna/Downloads/MyApp.app');4const appPath = path.resolve('/Users/saikrishna/Downloads/MyApp.app');5const appPath2 = path.resolve('/Users/saikrishna/Downloads/MyApp.app');6const appPath3 = path.resolve('/Users/saikrishna/Downloads/MyApp.app');7const appPath4 = path.resolve('/Users/saikrishna/Downloads/MyApp.app');8const appPath5 = path.resolve('/Users/saikrishna/Downloads/MyApp.app');9const appPath6 = path.resolve('/Users/saikrishna/Downloads/MyApp.app');10const appPath7 = path.resolve('/Users/saikrishna/Downloads/MyApp.app');11const appPath8 = path.resolve('/Users/saikrishna/Downloads/MyApp.app');12const appPath9 = path.resolve('/Users/saikrishna/Downloads/MyApp.app');13const appPath10 = path.resolve('/Users/saikrishna/Downloads/MyApp.app');14const appPath11 = path.resolve('/Users/saikrishna/Downloads/MyApp.app');15const appPath12 = path.resolve('/Users/saikrishna/Downloads/MyApp.app');16const appPath13 = path.resolve('/Users/saikrishna/Downloads/MyApp.app');17const appPath14 = path.resolve('/Users/saikrishna/Downloads/MyApp.app');18const appPath15 = path.resolve('/Users/saikrishna/Downloads/MyApp.app');19const appPath16 = path.resolve('/Users/saikrishna/Downloads/MyApp.app');20const appPath17 = path.resolve('/Users/saikrishna/Downloads/MyApp.app');21const appPath18 = path.resolve('/Users/saikrishna/Downloads/MyApp.app');22const appPath19 = path.resolve('/Users/saikrishna/Downloads/MyApp.app');23const appPath20 = path.resolve('/Users/saikrishna/Downloads/MyApp.app');24const appPath21 = path.resolve('/Users/saikrishna/Downloads/MyApp.app');25const appPath22 = path.resolve('/Users
Using AI Code Generation
1const fs = require('fs');2let file = fs.which('test.txt', function(err, path) {3 if (err) {4 console.log(err);5 }6 console.log(path);7});8const fs = require('fs');9let file = fs.which('test.txt', function(err, path) {10 if (err) {11 console.log(err);12 }13 console.log(path);14});15const fs = require('fs');16let file = fs.which('test.txt', function(err, path) {17 if (err) {18 console.log(err);19 }20 console.log(path);21});22const fs = require('fs');23let file = fs.which('test.txt', function(err, path) {24 if (err) {25 console.log(err);26 }27 console.log(path);28});29const fs = require('fs');30let file = fs.which('test.txt', function(err, path) {31 if (err) {32 console.log(err);33 }34 console.log(path);35});36const fs = require('fs');37let file = fs.which('test.txt', function(err, path) {38 if (err) {39 console.log(err);40 }41 console.log(path);42});43const fs = require('fs');44let file = fs.which('test.txt', function(err, path) {45 if (err) {46 console.log(err);47 }48 console.log(path);49});50const fs = require('fs');51let file = fs.which('test.txt', function(err, path) {52 if (err) {53 console.log(err);54 }55 console.log(path);56});
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!!