Best JavaScript code snippet using appium-xcuitest-driver
cli-release.js
Source:cli-release.js
...75 const cli = new CLI();76 const branchNameStub = sinon.stub(cli, 'getCurrentBranchName');77 branchNameStub.returns(Promise.reject(new Error(errorMessage)));78 globalStubs.push(branchNameStub);79 startLogCapture();80 return cli.argv(['publish-release'])81 .then(() => {82 endLogCapture();83 globalLogs[0].indexOf(errorMessage);84 globalExitCode.should.equal(1);85 });86 });87 it('should handle git branch name inquire error', function() {88 const errorMessage = 'Inject Inquirer Error.';89 const CLI = proxyquire('../src/node/cli/index.js', {90 'inquirer': {91 prompt: () => {92 return Promise.reject(new Error(errorMessage));93 },94 },95 });96 const cli = new CLI();97 const branchNameStub = sinon.stub(cli, 'getCurrentBranchName');98 branchNameStub.returns(Promise.resolve('random-branch-1234567890'));99 globalStubs.push(branchNameStub);100 startLogCapture();101 return cli.argv(['publish-release'])102 .then(() => {103 endLogCapture();104 globalLogs[0].indexOf(errorMessage);105 globalExitCode.should.equal(1);106 });107 });108 it('should hanlde user rejection on non-master branch', function() {109 const CLI = proxyquire('../src/node/cli/index.js', {110 'inquirer': {111 prompt: () => {112 return Promise.resolve({113 publish: false,114 });115 },116 },117 });118 const cli = new CLI();119 const branchNameStub = sinon.stub(cli, 'getCurrentBranchName');120 branchNameStub.returns(Promise.resolve('random-branch-1234567890'));121 globalStubs.push(branchNameStub);122 startLogCapture();123 return cli.argv(['publish-release'])124 .then(() => {125 endLogCapture();126 globalExitCode.should.equal(1);127 globalLogs.length.should.equal(0);128 });129 });130 it('shouldn\'t ask user a Q if on master branch', function() {131 let askedInquirer = false;132 const CLI = proxyquire('../src/node/cli/index.js', {133 'inquirer': {134 prompt: () => {135 askedInquirer = true;136 return Promise.resolve({137 publish: true,138 });139 },140 },141 });142 const cli = new CLI();143 const branchNameStub = sinon.stub(cli, 'getCurrentBranchName');144 branchNameStub.returns(Promise.resolve('master'));145 globalStubs.push(branchNameStub);146 return cli.confirmExpectedGitBranch()147 .then(() => {148 askedInquirer.should.equal(false);149 });150 });151 it('should handle user allowing release on non-master branch', function() {152 const CLI = proxyquire('../src/node/cli/index.js', {153 'inquirer': {154 prompt: () => {155 return Promise.resolve({156 publish: true,157 });158 },159 },160 });161 const cli = new CLI();162 const branchNameStub = sinon.stub(cli, 'getCurrentBranchName');163 branchNameStub.returns(Promise.resolve('random-branch-1234567890'));164 globalStubs.push(branchNameStub);165 return cli.confirmExpectedGitBranch();166 });167 it('should have good defaults and handle error for getting release details', function() {168 const errorMessage = 'Injected Inquirer Error.';169 const CLI = proxyquire('../src/node/cli/index.js', {170 'inquirer': {171 prompt: (questions) => {172 questions.forEach((question) => {173 switch(question.name) {174 case 'version':175 question.default.should.equal('patch');176 break;177 case 'tag':178 question.default.should.equal('stable');179 break;180 default:181 return Promise.reject('Unexpected question in test suite.');182 }183 });184 return Promise.reject(new Error(errorMessage));185 },186 },187 });188 const cli = new CLI();189 const branchNameStub = sinon.stub(cli, 'confirmExpectedGitBranch');190 branchNameStub.returns(Promise.resolve());191 globalStubs.push(branchNameStub);192 startLogCapture();193 return cli.argv(['publish-release'])194 .then(() => {195 endLogCapture();196 globalExitCode.should.equal(1);197 globalLogs[0].indexOf(errorMessage).should.not.equal(-1);198 });199 });200 it('should be able to get the current package.json file', function() {201 process.chdir(testOutput);202 const packageDetails = {203 scripts: {204 build: 'gulp build:prod',205 },206 };207 fse.writeJsonSync(path.join(testOutput, 'package.json'), packageDetails);208 const CLI = require('../src/node/cli/index.js');209 const cli = new CLI();210 return cli.getProjectPackage()211 .then((pkg) => {212 pkg.should.deep.equal(packageDetails);213 });214 });215 it('should print no tests warning if no scripts are defined', function() {216 process.chdir(testOutput);217 const packageDetails = {218 name: 'example-name',219 };220 fse.writeJsonSync(path.join(testOutput, 'package.json'), packageDetails);221 const CLI = require('../src/node/cli/index.js');222 const cli = new CLI();223 const branchNameStub = sinon.stub(cli, 'confirmExpectedGitBranch');224 branchNameStub.returns(Promise.resolve());225 globalStubs.push(branchNameStub);226 const getDetailsStub = sinon.stub(cli, 'getPublishDetails');227 getDetailsStub.returns(Promise.resolve());228 globalStubs.push(getDetailsStub);229 startLogCapture();230 return cli.runNPMScripts()231 .then(() => {232 endLogCapture();233 globalLogs[0].indexOf(strings['no-test-script']).should.not.equal(-1);234 });235 });236 it('should print no test warning if only other scripts are defined', function() {237 process.chdir(testOutput);238 const packageDetails = {239 name: 'example-name',240 scripts: {241 rando: 'echo "This shouldn\'t run"',242 example: 'echo "This shouldn\'t run either"',243 },244 };245 fse.writeJsonSync(path.join(testOutput, 'package.json'), packageDetails);246 const CLI = require('../src/node/cli/index.js');247 const cli = new CLI();248 const branchNameStub = sinon.stub(cli, 'confirmExpectedGitBranch');249 branchNameStub.returns(Promise.resolve());250 globalStubs.push(branchNameStub);251 const getDetailsStub = sinon.stub(cli, 'getPublishDetails');252 getDetailsStub.returns(Promise.resolve());253 globalStubs.push(getDetailsStub);254 startLogCapture();255 return cli.runNPMScripts()256 .then(() => {257 endLogCapture();258 globalLogs[0].indexOf(strings['no-test-script']).should.not.equal(-1);259 });260 });261 it('should run the build step if defined.', function() {262 process.chdir(testOutput);263 const buildFilename = 'build.txt';264 const packageDetails = {265 name: 'example-name',266 scripts: {267 rando: 'echo "This shouldn\'t run"',268 example: 'echo "This shouldn\'t run either"',269 build: `touch ${buildFilename}`,270 },271 };272 fse.writeJsonSync(path.join(testOutput, 'package.json'), packageDetails);273 const CLI = require('../src/node/cli/index.js');274 const cli = new CLI();275 const branchNameStub = sinon.stub(cli, 'confirmExpectedGitBranch');276 branchNameStub.returns(Promise.resolve());277 globalStubs.push(branchNameStub);278 const getDetailsStub = sinon.stub(cli, 'getPublishDetails');279 getDetailsStub.returns(Promise.resolve());280 globalStubs.push(getDetailsStub);281 startLogCapture();282 return cli.runNPMScripts()283 .then(() => {284 endLogCapture();285 globalLogs[0].indexOf(strings['no-test-script']).should.not.equal(-1);286 })287 .then(() => {288 // Check the npm script ran - will throw if the file doesn't exist.289 fs.accessSync(path.join(testOutput, buildFilename), fs.F_OK);290 });291 });292 it('should run the build and test steps if defined.', function() {293 process.chdir(testOutput);294 const buildFilename = 'build.txt';295 const testFilename = 'test.txt';296 const packageDetails = {297 name: 'example-name',298 scripts: {299 rando: 'echo "This shouldn\'t run"',300 example: 'echo "This shouldn\'t run either"',301 build: `touch ${buildFilename}`,302 test: `touch ${testFilename}`,303 },304 };305 fse.writeJsonSync(path.join(testOutput, 'package.json'), packageDetails);306 const CLI = require('../src/node/cli/index.js');307 const cli = new CLI();308 const branchNameStub = sinon.stub(cli, 'confirmExpectedGitBranch');309 branchNameStub.returns(Promise.resolve());310 globalStubs.push(branchNameStub);311 const getDetailsStub = sinon.stub(cli, 'getPublishDetails');312 getDetailsStub.returns(Promise.resolve());313 globalStubs.push(getDetailsStub);314 startLogCapture();315 return cli.runNPMScripts()316 .then(() => {317 endLogCapture();318 globalLogs.length.should.equal(0);319 })320 .then(() => {321 // Check the npm script ran - will throw if the file doesn't exist.322 fs.accessSync(path.join(testOutput, buildFilename), fs.F_OK);323 fs.accessSync(path.join(testOutput, testFilename), fs.F_OK);324 });325 });326 it('should have correct error and exit code when log in to NPM fails', function() {327 process.chdir(testOutput);328 const packageDetails = {329 name: 'example-name',330 scripts: {331 test: `echo "Log from test npm script."`,332 },333 };334 fse.writeJsonSync(path.join(testOutput, 'package.json'), packageDetails);335 const errorMessage = 'Injected NPM Login Error.';336 const CLI = require('../src/node/cli/index.js');337 const cli = new CLI();338 const branchNameStub = sinon.stub(cli, 'confirmExpectedGitBranch').callsFake(() => {339 return Promise.resolve();340 });341 globalStubs.push(branchNameStub);342 const publishDetailsStub = sinon.stub(cli, 'getPublishDetails').callsFake(() => {343 return Promise.resolve({version: 'patch',344 tag: 'stable'});345 });346 globalStubs.push(publishDetailsStub);347 const loginToNPMStub = sinon.stub(cli, 'loginToNPM').callsFake(() => {348 return Promise.reject(new Error(errorMessage));349 });350 globalStubs.push(loginToNPMStub);351 startLogCapture();352 return cli.argv(['publish-release'])353 .then(() => {354 endLogCapture();355 globalExitCode.should.equal(1);356 globalLogs[0].indexOf(errorMessage).should.not.equal(-1);357 });358 });359 it('should handle erroring Inquirer for publish confirmation', function() {360 process.chdir(testOutput);361 const packageDetails = {362 name: 'example-name',363 scripts: {364 test: `echo "Log from test npm script."`,365 },366 };367 fse.writeJsonSync(path.join(testOutput, 'package.json'), packageDetails);368 const errorMessage = 'Injected Inquirer Error.';369 const CLI = proxyquire('../src/node/cli/index.js', {370 'inquirer': {371 prompt: (questions) => {372 return Promise.reject(new Error(errorMessage));373 },374 },375 });376 const cli = new CLI();377 const branchNameStub = sinon.stub(cli, 'confirmExpectedGitBranch').callsFake(() => {378 return Promise.resolve();379 });380 globalStubs.push(branchNameStub);381 const publishDetailsStub = sinon.stub(cli, 'getPublishDetails').callsFake(() => {382 return Promise.resolve({version: 'patch',383 tag: 'stable'});384 });385 globalStubs.push(publishDetailsStub);386 const loginToNPMStub = sinon.stub(cli, 'loginToNPM').callsFake(() => {387 return Promise.resolve();388 });389 globalStubs.push(loginToNPMStub);390 startLogCapture();391 return cli.argv(['publish-release'])392 .then(() => {393 endLogCapture();394 globalExitCode.should.equal(1);395 globalLogs[0].indexOf(errorMessage).should.not.equal(-1);396 });397 });398 it('should not publish if response at publish confirmation is false', function() {399 process.chdir(testOutput);400 const packageDetails = {401 name: 'example-name',402 scripts: {403 test: `echo "Log from test npm script."`,404 },405 };406 fse.writeJsonSync(path.join(testOutput, 'package.json'), packageDetails);407 const CLI = proxyquire('../src/node/cli/index.js', {408 'inquirer': {409 prompt: (questions) => {410 return Promise.resolve(false);411 },412 },413 });414 const cli = new CLI();415 const branchNameStub = sinon.stub(cli, 'confirmExpectedGitBranch').callsFake(() => {416 return Promise.resolve();417 });418 globalStubs.push(branchNameStub);419 const publishDetailsStub = sinon.stub(cli, 'getPublishDetails').callsFake(() => {420 return Promise.resolve({version: 'patch',421 tag: 'stable'});422 });423 globalStubs.push(publishDetailsStub);424 const loginToNPMStub = sinon.stub(cli, 'loginToNPM').callsFake(() => {425 return Promise.resolve();426 });427 globalStubs.push(loginToNPMStub);428 startLogCapture();429 return cli.argv(['publish-release'])430 .then(() => {431 endLogCapture();432 globalExitCode.should.equal(1);433 globalLogs.length.should.equal(0);434 });435 });436 it('should bump the version correctly', function() {437 process.chdir(testOutput);438 const packageDetails = {439 name: 'example-name',440 version: '0.0.0',441 scripts: {442 test: `echo "Log from test npm script."`,443 },444 };445 fse.writeJsonSync(path.join(testOutput, 'package.json'), packageDetails);446 const CLI = require('../src/node/cli/index.js');447 const cli = new CLI();448 return cli.updatePackageVersion('patch')449 .then((newVersion) => {450 newVersion.should.equal('v0.0.1');451 const pkgDetails = fse.readJsonSync(path.join(testOutput, 'package.json'));452 pkgDetails.version.should.equal('0.0.1');453 return cli.updatePackageVersion('minor');454 })455 .then((newVersion) => {456 newVersion.should.equal('v0.1.0');457 const pkgDetails = fse.readJsonSync(path.join(testOutput, 'package.json'));458 pkgDetails.version.should.equal('0.1.0');459 return cli.updatePackageVersion('major');460 })461 .then((newVersion) => {462 newVersion.should.equal('v1.0.0');463 const pkgDetails = fse.readJsonSync(path.join(testOutput, 'package.json'));464 pkgDetails.version.should.equal('1.0.0');465 });466 });467 it('should handle failing npm version update', function() {468 process.chdir(testOutput);469 const packageDetails = {470 name: 'example-name',471 scripts: {472 test: `echo "Log from test npm script."`,473 },474 };475 fse.writeJsonSync(path.join(testOutput, 'package.json'), packageDetails);476 const errorMessage = 'Inject npm version update error.';477 const CLI = require('../src/node/cli/index.js');478 const cli = new CLI();479 const branchNameStub = sinon.stub(cli, 'confirmExpectedGitBranch').callsFake(() => {480 return Promise.resolve();481 });482 globalStubs.push(branchNameStub);483 const publishDetailsStub = sinon.stub(cli, 'getPublishDetails').callsFake(() => {484 return Promise.resolve({version: 'patch',485 tag: 'stable'});486 });487 globalStubs.push(publishDetailsStub);488 const loginToNPMStub = sinon.stub(cli, 'loginToNPM').callsFake(() => {489 return Promise.resolve();490 });491 globalStubs.push(loginToNPMStub);492 const confirmPublishStub = sinon.stub(cli, 'confirmNewPackageVersion').callsFake(() => {493 return Promise.resolve();494 });495 globalStubs.push(confirmPublishStub);496 const updateVersionStub = sinon.stub(cli, 'updatePackageVersion').callsFake(() => {497 return Promise.reject(new Error(errorMessage));498 });499 globalStubs.push(updateVersionStub);500 startLogCapture();501 return cli.argv(['publish-release'])502 .then(() => {503 endLogCapture();504 globalExitCode.should.equal(1);505 globalLogs[0].indexOf(errorMessage).should.not.equal(-1);506 });507 });508 it('should handle failing npm publish', function() {509 process.chdir(testOutput);510 const packageDetails = {511 name: 'example-name',512 scripts: {513 test: `echo "Log from test npm script."`,514 },515 };516 fse.writeJsonSync(path.join(testOutput, 'package.json'), packageDetails);517 const errorMessage = 'Inject npm publish error.';518 const CLI = require('../src/node/cli/index.js');519 const cli = new CLI();520 const branchNameStub = sinon.stub(cli, 'confirmExpectedGitBranch').callsFake(() => {521 return Promise.resolve();522 });523 globalStubs.push(branchNameStub);524 const publishDetailsStub = sinon.stub(cli, 'getPublishDetails').callsFake(() => {525 return Promise.resolve({version: 'patch',526 tag: 'stable'});527 });528 globalStubs.push(publishDetailsStub);529 const loginToNPMStub = sinon.stub(cli, 'loginToNPM').callsFake(() => {530 return Promise.resolve();531 });532 globalStubs.push(loginToNPMStub);533 const confirmPublishStub = sinon.stub(cli, 'confirmNewPackageVersion').callsFake(() => {534 return Promise.resolve();535 });536 globalStubs.push(confirmPublishStub);537 const updateVersionStub = sinon.stub(cli, 'updatePackageVersion').callsFake(() => {538 return Promise.resolve('v1.0.0');539 });540 globalStubs.push(updateVersionStub);541 const publishToNPMStub = sinon.stub(cli, 'publishToNPM').callsFake(() => {542 return Promise.reject(new Error(errorMessage));543 });544 globalStubs.push(publishToNPMStub);545 startLogCapture();546 return cli.argv(['publish-release'])547 .then(() => {548 endLogCapture();549 globalExitCode.should.equal(1);550 globalLogs[0].indexOf(errorMessage).should.not.equal(-1);551 });552 });553 it('should handle failing git tag push', function() {554 process.chdir(testOutput);555 const packageDetails = {556 name: 'example-name',557 scripts: {558 test: `echo "Log from test npm script."`,559 },560 };561 fse.writeJsonSync(path.join(testOutput, 'package.json'), packageDetails);562 const errorMessage = 'Injected Git Tag Push Error.';563 const CLI = require('../src/node/cli/index.js');564 const cli = new CLI();565 const branchNameStub = sinon.stub(cli, 'confirmExpectedGitBranch').callsFake(() => {566 return Promise.resolve();567 });568 globalStubs.push(branchNameStub);569 const publishDetailsStub = sinon.stub(cli, 'getPublishDetails').callsFake(() => {570 return Promise.resolve({version: 'patch',571 tag: 'stable'});572 });573 globalStubs.push(publishDetailsStub);574 const loginToNPMStub = sinon.stub(cli, 'loginToNPM').callsFake(() => {575 return Promise.resolve();576 });577 globalStubs.push(loginToNPMStub);578 const confirmPublishStub = sinon.stub(cli, 'confirmNewPackageVersion').callsFake(() => {579 return Promise.resolve();580 });581 globalStubs.push(confirmPublishStub);582 const updateVersionStub = sinon.stub(cli, 'updatePackageVersion').callsFake(() => {583 return Promise.resolve('v1.0.0');584 });585 globalStubs.push(updateVersionStub);586 const publishToNPMStub = sinon.stub(cli, 'publishToNPM').callsFake(() => {587 return Promise.resolve();588 });589 globalStubs.push(publishToNPMStub);590 const gitTagPushStub = sinon.stub(cli, 'pushGithubTag').callsFake(() => {591 return Promise.reject(new Error(errorMessage));592 });593 globalStubs.push(gitTagPushStub);594 startLogCapture();595 return cli.argv(['publish-release'])596 .then(() => {597 endLogCapture();598 globalExitCode.should.equal(1);599 globalLogs[0].indexOf(errorMessage).should.not.equal(-1);600 });601 });602 it('should handle failing doc publish', function() {603 process.chdir(testOutput);604 const packageDetails = {605 name: 'example-name',606 scripts: {607 test: `echo "Log from test npm script."`,608 },609 };610 fse.writeJsonSync(path.join(testOutput, 'package.json'), packageDetails);611 const errorMessage = 'Injected Git Tag Push Error.';612 const CLI = require('../src/node/cli/index.js');613 const cli = new CLI();614 const branchNameStub = sinon.stub(cli, 'confirmExpectedGitBranch').callsFake(() => {615 return Promise.resolve();616 });617 globalStubs.push(branchNameStub);618 const publishDetailsStub = sinon.stub(cli, 'getPublishDetails').callsFake(() => {619 return Promise.resolve({version: 'patch',620 tag: 'stable'});621 });622 globalStubs.push(publishDetailsStub);623 const loginToNPMStub = sinon.stub(cli, 'loginToNPM').callsFake(() => {624 return Promise.resolve();625 });626 globalStubs.push(loginToNPMStub);627 const confirmPublishStub = sinon.stub(cli, 'confirmNewPackageVersion').callsFake(() => {628 return Promise.resolve();629 });630 globalStubs.push(confirmPublishStub);631 const updateVersionStub = sinon.stub(cli, 'updatePackageVersion').callsFake(() => {632 return Promise.resolve('v1.0.0');633 });634 globalStubs.push(updateVersionStub);635 const publishToNPMStub = sinon.stub(cli, 'publishToNPM').callsFake(() => {636 return Promise.resolve();637 });638 globalStubs.push(publishToNPMStub);639 const gitTagPushStub = sinon.stub(cli, 'pushGithubTag').callsFake(() => {640 return Promise.resolve();641 });642 globalStubs.push(gitTagPushStub);643 const publishDocsStub = sinon.stub(cli, 'publishDocs').callsFake(() => {644 return Promise.reject(new Error(errorMessage));645 });646 globalStubs.push(publishDocsStub);647 startLogCapture();648 return cli.argv(['publish-release'])649 .then(() => {650 endLogCapture();651 globalExitCode.should.equal(1);652 // Assume that publish-docs tests will cover logging. For sake of this653 // injected error - log nothing.654 });655 });656 it('should handle successful publish', function() {657 process.chdir(testOutput);658 const packageDetails = {659 name: 'example-name',660 scripts: {661 test: `echo "Log from test npm script."`,662 },663 };664 fse.writeJsonSync(path.join(testOutput, 'package.json'), packageDetails);665 const CLI = require('../src/node/cli/index.js');666 const cli = new CLI();667 const branchNameStub = sinon.stub(cli, 'confirmExpectedGitBranch').callsFake(() => {668 return Promise.resolve();669 });670 globalStubs.push(branchNameStub);671 const publishDetailsStub = sinon.stub(cli, 'getPublishDetails').callsFake(() => {672 return Promise.resolve({version: 'patch',673 tag: 'stable'});674 });675 globalStubs.push(publishDetailsStub);676 const loginToNPMStub = sinon.stub(cli, 'loginToNPM').callsFake(() => {677 return Promise.resolve();678 });679 globalStubs.push(loginToNPMStub);680 const confirmPublishStub = sinon.stub(cli, 'confirmNewPackageVersion').callsFake(() => {681 return Promise.resolve();682 });683 globalStubs.push(confirmPublishStub);684 const updateVersionStub = sinon.stub(cli, 'updatePackageVersion').callsFake(() => {685 return Promise.resolve('v1.0.0');686 });687 globalStubs.push(updateVersionStub);688 const publishToNPMStub = sinon.stub(cli, 'publishToNPM').callsFake(() => {689 return Promise.resolve();690 });691 globalStubs.push(publishToNPMStub);692 const gitTagPushStub = sinon.stub(cli, 'pushGithubTag').callsFake(() => {693 return Promise.resolve();694 });695 globalStubs.push(gitTagPushStub);696 const publishDocsStub = sinon.stub(cli, 'publishDocs').callsFake(() => {697 return Promise.resolve();698 });699 globalStubs.push(publishDocsStub);700 startLogCapture();701 return cli.argv(['publish-release'])702 .then(() => {703 endLogCapture();704 globalExitCode.should.equal(0);705 globalLogs.length.should.equal(0);706 });707 });...
cli-docs.js
Source:cli-docs.js
...163 });164 it('should fail publishing if gh-pages exists', function() {165 process.chdir(testOutput);166 fse.ensureDirSync(path.join(testOutput, 'gh-pages'));167 startLogCapture();168 return new CLI().argv(['publish-docs'])169 .then(() => {170 endLogCapture();171 globalExitCode.should.equal(1);172 globalLogs[0].indexOf('The directory \'gh-pages\' already exists.')173 .should.not.equal(-1);174 });175 });176 it('should handle failing github pages checkout', function() {177 process.chdir(testOutput);178 const errMsg = 'Injected error from Mocha';179 const cli = new CLI();180 const checkoutStub = sinon.stub(cli, 'checkoutGithubPages');181 checkoutStub.returns(Promise.reject(errMsg));182 globalStubs.push(checkoutStub);183 startLogCapture();184 return cli.argv(['publish-docs'])185 .then(() => {186 endLogCapture();187 globalLogs[0].indexOf(errMsg);188 globalExitCode.should.equal(1);189 });190 });191 it('should handle failing clean up gh-pages directory', function() {192 process.chdir(testOutput);193 const errMsg = 'Injected error from Mocha';194 const cli = new CLI();195 const checkoutStub = sinon.stub(cli, 'checkoutGithubPages');196 checkoutStub.returns(Promise.resolve());197 const cleanupGHPages = sinon.stub(cli, 'cleanupGithubPages');198 cleanupGHPages.returns(Promise.reject(errMsg));199 globalStubs.push(checkoutStub);200 globalStubs.push(cleanupGHPages);201 startLogCapture();202 return cli.argv(['publish-docs'])203 .then(() => {204 endLogCapture();205 globalLogs[0].indexOf(errMsg);206 globalExitCode.should.equal(1);207 });208 });209 it('should handle failing git push', function() {210 process.chdir(testOutput);211 const errMsg = 'Injected error from Mocha';212 fse.ensureDirSync(path.join(testOutput, 'docs'));213 const cli = new CLI();214 const checkoutStub = sinon.stub(cli, 'checkoutGithubPages');215 checkoutStub.returns(Promise.resolve());216 const cleanupGHPages = sinon.stub(cli, 'cleanupGithubPages').callsFake(() => {217 fse.ensureDirSync(path.join(testOutput, 'gh-pages'));218 return Promise.resolve();219 });220 const pushChangesStub = sinon.stub(cli, 'pushChangesToGithub');221 pushChangesStub.returns(Promise.reject(errMsg));222 globalStubs.push(checkoutStub);223 globalStubs.push(cleanupGHPages);224 globalStubs.push(pushChangesStub);225 startLogCapture();226 return cli.argv(['publish-docs'])227 .then(() => {228 endLogCapture();229 globalLogs[0].indexOf(errMsg);230 globalExitCode.should.equal(1);231 let dirDeleted = false;232 try {233 fs.accessSync(path.join(testOutput, 'gh-pages'), fs.F_OK);234 } catch (err) {235 dirDeleted = true;236 }237 dirDeleted.should.equal(true);238 });239 });240 it('should delete gh-pages if all successful', function() {241 process.chdir(testOutput);242 fse.ensureDirSync(path.join(testOutput, 'docs'));243 const cli = new CLI();244 const checkoutStub = sinon.stub(cli, 'checkoutGithubPages');245 checkoutStub.returns(Promise.resolve());246 const cleanupGHPages = sinon.stub(cli, 'cleanupGithubPages').callsFake(() => {247 fse.ensureDirSync(path.join(testOutput, 'gh-pages'));248 return Promise.resolve();249 });250 const pushChangesStub = sinon.stub(cli, 'pushChangesToGithub');251 pushChangesStub.returns(Promise.resolve());252 globalStubs.push(checkoutStub);253 globalStubs.push(cleanupGHPages);254 globalStubs.push(pushChangesStub);255 startLogCapture();256 return cli.argv(['publish-docs'])257 .then(() => {258 endLogCapture();259 globalExitCode.should.equal(0);260 let dirDeleted = false;261 try {262 fs.accessSync(path.join(testOutput, 'gh-pages'), fs.F_OK);263 } catch (err) {264 dirDeleted = true;265 }266 dirDeleted.should.equal(true);267 });268 });269});
driver-specs.js
Source:driver-specs.js
1import sinon from 'sinon';2import * as iosDriver from 'appium-ios-driver';3import { JWProxy } from 'appium-base-driver';4import XCUITestDriver from '../..';5import xcode from 'appium-xcode';6import _ from 'lodash';7import chai from 'chai';8import * as utils from '../../lib/utils';9import { MOCHA_LONG_TIMEOUT } from './helpers';10chai.should();11const expect = chai.expect;12const caps = {13 platformName: 'iOS',14 deviceName: 'iPhone 6',15 app: '/foo.app',16 platformVersion: '10.0',17};18describe('driver commands', function () {19 describe('status', function () {20 let driver;21 let jwproxyCommandSpy;22 beforeEach(function () {23 driver = new XCUITestDriver();24 // fake the proxy to WDA25 const jwproxy = new JWProxy();26 jwproxyCommandSpy = sinon.stub(jwproxy, 'command').callsFake(async function () { // eslint-disable-line require-await27 return {some: 'thing'};28 });29 driver.wda = {30 jwproxy,31 };32 });33 afterEach(function () {34 jwproxyCommandSpy.reset();35 });36 it('should not have wda status by default', async function () {37 const status = await driver.getStatus();38 jwproxyCommandSpy.calledOnce.should.be.false;39 expect(status.wda).to.be.undefined;40 });41 it('should return wda status if cached', async function () {42 driver.cachedWdaStatus = {};43 const status = await driver.getStatus();44 jwproxyCommandSpy.called.should.be.false;45 status.wda.should.exist;46 });47 });48 describe('createSession', function () {49 let driver;50 let sandbox;51 beforeEach(function () {52 driver = new XCUITestDriver();53 sandbox = sinon.createSandbox();54 sandbox.stub(driver, 'determineDevice').callsFake(async function () { // eslint-disable-line require-await55 return {56 device: {57 shutdown: _.noop,58 isRunning () {59 return true;60 },61 stat () {62 return {state: 'Booted'};63 },64 clearCaches: _.noop,65 getWebInspectorSocket () {66 return '/path/to/uds.socket';67 },68 },69 udid: null,70 realDevice: null71 };72 });73 sandbox.stub(driver, 'configureApp').callsFake(_.noop);74 sandbox.stub(driver, 'startLogCapture').callsFake(_.noop);75 sandbox.stub(driver, 'startSim').callsFake(_.noop);76 sandbox.stub(driver, 'startWdaSession').callsFake(_.noop);77 sandbox.stub(driver, 'startWda').callsFake(_.noop);78 sandbox.stub(driver, 'setReduceMotion').callsFake(_.noop);79 sandbox.stub(driver, 'installAUT').callsFake(_.noop);80 sandbox.stub(driver, 'connectToRemoteDebugger').callsFake(_.noop);81 sandbox.stub(iosDriver.settings, 'setLocale').callsFake(_.noop);82 sandbox.stub(iosDriver.settings, 'setPreferences').callsFake(_.noop);83 sandbox.stub(xcode, 'getMaxIOSSDK').callsFake(async () => '10.0'); // eslint-disable-line require-await84 sandbox.stub(utils, 'checkAppPresent').callsFake(_.noop);85 sandbox.stub(iosDriver.appUtils, 'extractBundleId').callsFake(_.noop);86 });87 afterEach(function () {88 sandbox.restore();89 });90 it('should include server capabilities', async function () {91 this.timeout(MOCHA_LONG_TIMEOUT);92 const resCaps = await driver.createSession(caps);93 resCaps[1].javascriptEnabled.should.be.true;94 });95 it('should call startLogCapture', async function () {96 const c = { ... caps };97 Object.assign(c, {skipLogCapture: false});98 this.timeout(MOCHA_LONG_TIMEOUT);99 const resCaps = await driver.createSession(c);100 resCaps[1].javascriptEnabled.should.be.true;101 driver.startLogCapture.called.should.be.true;102 });103 it('should not call startLogCapture', async function () {104 const c = { ... caps };105 Object.assign(c, {skipLogCapture: true});106 this.timeout(MOCHA_LONG_TIMEOUT);107 const resCaps = await driver.createSession(c);108 resCaps[1].javascriptEnabled.should.be.true;109 driver.startLogCapture.called.should.be.false;110 });111 });112});113describe('installOtherApps', function () {114 let driver = new XCUITestDriver();115 let sandbox;116 beforeEach(function () {117 sandbox = sinon.createSandbox();118 });119 afterEach(function () {120 sandbox.restore();121 });122 it('should skip install other apps on real devices', async function () {123 sandbox.stub(driver, 'isRealDevice');124 sandbox.stub(driver.helpers, 'parseCapsArray');125 driver.isRealDevice.returns(true);126 await driver.installOtherApps('/path/to/iosApp.app');127 driver.isRealDevice.calledOnce.should.be.true;128 driver.helpers.parseCapsArray.notCalled.should.be.true;129 });130 it('should install multiple apps from otherApps as string on simulators', async function () {131 const SimulatorManagementModule = require('../../lib/simulator-management');132 sandbox.stub(SimulatorManagementModule, 'installToSimulator');133 sandbox.stub(driver, 'isRealDevice');134 driver.isRealDevice.returns(false);135 driver.opts.noReset = false;136 driver.opts.device = 'some-device';137 driver.lifecycleData = {createSim: false};138 await driver.installOtherApps('/path/to/iosApp.app');139 driver.isRealDevice.calledOnce.should.be.true;140 SimulatorManagementModule.installToSimulator.calledOnce.should.be.true;141 SimulatorManagementModule.installToSimulator.calledWith(142 'some-device',143 '/path/to/iosApp.app',144 undefined, {noReset: false, newSimulator: false}145 ).should.be.true;146 });147 it('should install multiple apps from otherApps as JSON array on simulators', async function () {148 const SimulatorManagementModule = require('../../lib/simulator-management');149 sandbox.stub(SimulatorManagementModule, 'installToSimulator');150 sandbox.stub(driver, 'isRealDevice');151 driver.isRealDevice.returns(false);152 driver.opts.noReset = false;153 driver.opts.device = 'some-device';154 driver.lifecycleData = {createSim: false};155 await driver.installOtherApps('["/path/to/iosApp1.app","/path/to/iosApp2.app"]');156 driver.isRealDevice.calledOnce.should.be.true;157 SimulatorManagementModule.installToSimulator.calledWith(158 'some-device',159 '/path/to/iosApp1.app',160 undefined, {noReset: false, newSimulator: false}161 ).should.be.true;162 SimulatorManagementModule.installToSimulator.calledWith(163 'some-device',164 '/path/to/iosApp2.app',165 undefined, {noReset: false, newSimulator: false}166 ).should.be.true;167 });...
cli.js
Source:cli.js
...57 const cliPath = binValues['web-push-testing-service'];58 fs.accessSync(path.join(__dirname, '..', cliPath), fs.F_OK);59 });60 it('should show help text', function() {61 startLogCapture();62 const inputs = ['-h', '--help'];63 inputs.forEach((input) => {64 new CLI().argv([input]);65 });66 globalExitCode.should.equal(0);67 });68 it('should show version number', function() {69 startLogCapture();70 const inputs = ['-v', '--version'];71 inputs.forEach((input) => {72 new CLI().argv([input]);73 });74 globalExitCode.should.equal(0);75 const version = require('../package.json').version;76 globalLogs.length.should.equal(inputs.length);77 globalLogs.forEach((log) => {78 log.should.equal(version);79 });80 });81 const createFullFlowTest = function(additionalArgs) {82 return function() {83 this.timeout(10 * 60 * 1000);...
log.js
Source:log.js
1import _ from 'lodash';2import { DEFAULT_WS_PATHNAME_PREFIX } from 'appium-base-driver';3import { iosCommands } from 'appium-ios-driver';4import { IOSCrashLog } from '../device-log/ios-crash-log';5import { IOSSimulatorLog } from '../device-log/ios-simulator-log';6import { IOSDeviceLog } from '../device-log/ios-device-log';7import log from '../logger';8import WebSocket from 'ws';9import SafariConsoleLog from '../device-log/safari-console-log';10import SafariNetworkLog from '../device-log/safari-network-log';11let extensions = {};12const WEBSOCKET_ENDPOINT = (sessionId) => `${DEFAULT_WS_PATHNAME_PREFIX}/session/${sessionId}/appium/device/syslog`;13Object.assign(extensions, iosCommands.logging);14extensions.supportedLogTypes.safariConsole = {15 description: 'Safari Console Logs - data written to the JS console in Safari',16 getter: async (self) => await self.extractLogs('safariConsole', self.logs),17};18extensions.supportedLogTypes.safariNetwork = {19 description: 'Safari Network Logs - information about network operations undertaken by Safari',20 getter: async (self) => await self.extractLogs('safariNetwork', self.logs),21};22extensions.startLogCapture = async function startLogCapture () {23 this.logs = this.logs || {};24 if (!_.isUndefined(this.logs.syslog) && this.logs.syslog.isCapturing) {25 log.warn('Trying to start iOS log capture but it has already started!');26 return true;27 }28 if (_.isUndefined(this.logs.syslog)) {29 this.logs.crashlog = new IOSCrashLog({30 sim: this.opts.device,31 udid: this.isRealDevice() ? this.opts.udid : undefined,32 });33 if (this.isRealDevice()) {34 this.logs.syslog = new IOSDeviceLog({35 udid: this.opts.udid,36 showLogs: this.opts.showIOSLog,37 });38 } else {39 this.logs.syslog = new IOSSimulatorLog({40 sim: this.opts.device,41 showLogs: this.opts.showIOSLog,42 xcodeVersion: this.xcodeVersion,43 });44 }45 this.logs.safariConsole = new SafariConsoleLog(!!this.opts.showSafariConsoleLog);46 this.logs.safariNetwork = new SafariNetworkLog(!!this.opts.showSafariNetworkLog);47 }48 try {49 await this.logs.syslog.startCapture();50 } catch (err) {51 log.warn(`Continuing without capturing device logs: ${err.message}`);52 return false;53 }54 await this.logs.crashlog.startCapture();55 await this.logs.safariConsole.startCapture();56 await this.logs.safariNetwork.startCapture();57 return true;58};59/**60 * Starts iOS system logs broadcast websocket on the same host and port61 * where Appium server is running at `/ws/session/:sessionId:/appium/syslog` endpoint. The method62 * will return immediately if the web socket is already listening.63 *64 * Each connected webcoket listener will receive syslog lines65 * as soon as they are visible to Appium.66 */67extensions.mobileStartLogsBroadcast = async function mobileStartLogsBroadcast () {68 const pathname = WEBSOCKET_ENDPOINT(this.sessionId);69 if (!_.isEmpty(await this.server.getWebSocketHandlers(pathname))) {70 log.debug(`The system logs broadcasting web socket server is already listening at ${pathname}`);71 return;72 }73 log.info(`Assigning system logs broadcasting web socket server to ${pathname}`);74 // https://github.com/websockets/ws/blob/master/doc/ws.md75 const wss = new WebSocket.Server({76 noServer: true,77 });78 wss.on('connection', (ws, req) => {79 if (req) {80 const remoteIp = _.isEmpty(req.headers['x-forwarded-for'])81 ? req.connection.remoteAddress82 : req.headers['x-forwarded-for'];83 log.debug(`Established a new system logs listener web socket connection from ${remoteIp}`);84 } else {85 log.debug('Established a new system logs listener web socket connection');86 }87 if (_.isEmpty(this._syslogWebsocketListener)) {88 this._syslogWebsocketListener = (logRecord) => {89 if (ws && ws.readyState === WebSocket.OPEN) {90 ws.send(logRecord.message);91 }92 };93 }94 this.logs.syslog.on('output', this._syslogWebsocketListener);95 ws.on('close', (code, reason) => {96 if (!_.isEmpty(this._syslogWebsocketListener)) {97 this.logs.syslog.removeListener('output', this._syslogWebsocketListener);98 this._syslogWebsocketListener = null;99 }100 let closeMsg = 'System logs listener web socket is closed.';101 if (!_.isEmpty(code)) {102 closeMsg += ` Code: ${code}.`;103 }104 if (!_.isEmpty(reason)) {105 closeMsg += ` Reason: ${reason}.`;106 }107 log.debug(closeMsg);108 });109 });110 await this.server.addWebSocketHandler(pathname, wss);111};112/**113 * Stops the previously started syslog broadcasting wesocket server.114 * This method will return immediately if no server is running.115 */116extensions.mobileStopLogsBroadcast = async function mobileStopLogsBroadcast () {117 const pathname = WEBSOCKET_ENDPOINT(this.sessionId);118 if (_.isEmpty(await this.server.getWebSocketHandlers(pathname))) {119 return;120 }121 log.debug('Stopping the system logs broadcasting web socket server');122 await this.server.removeWebSocketHandler(pathname);123};...
cli-tests.js
Source:cli-tests.js
...80 const cliPath = binValues['npm-publish-scripts'];81 fs.accessSync(path.join(__dirname, '..', cliPath), fs.F_OK);82 });83 it('should show help text and exit with bad code', function() {84 startLogCapture();85 return new CLI().argv([])86 .then(() => {87 endLogCapture();88 globalExitCode.should.equal(1);89 });90 });91 it('should show help text', function() {92 startLogCapture();93 const inputs = ['-h', '--help'];94 const promises = inputs.map((input) => {95 new CLI().argv([input])96 .then(() => {97 globalExitCode.should.equal(0);98 });99 });100 return Promise.all(promises)101 .then(() => {102 endLogCapture();103 const helpText = fs.readFileSync(104 path.join(__dirname, '..', 'src', 'node', 'cli', 'cli-help.txt'), 'utf8');105 globalLogs.forEach((log) => {106 log.indexOf(helpText).should.not.equal(-1);107 });108 });109 });110 it('should show version number', function() {111 startLogCapture();112 const inputs = ['-v', '--version'];113 const promises = inputs.map((input) => {114 return new CLI().argv([input])115 .then(() => {116 globalExitCode.should.equal(0);117 });118 });119 return Promise.all(promises)120 .then(() => {121 endLogCapture();122 const version = require('../package.json').version;123 globalLogs.length.should.equal(inputs.length);124 globalLogs.forEach((log) => {125 log.indexOf(version).should.not.equal(-1);126 });127 });128 });129 it('should handle random commands', function() {130 startLogCapture();131 const invalidCommand = 'random-command-1234567890';132 return new CLI().argv([invalidCommand])133 .then(() => {134 endLogCapture();135 globalExitCode.should.equal(1);136 (globalLogs[0].indexOf(`Invlaid command given '${invalidCommand}'`))137 .should.not.equal(-1);138 });139 });...
logging.js
Source:logging.js
1import _ from 'lodash';2import IOSLog from '../device-log/ios-log';3import IOSCrashLog from '../device-log/ios-crash-log';4import logger from '../logger';5const GET_SERVER_LOGS_FEATURE = 'get_server_logs';6let commands = {}, helpers = {}, extensions = {};7extensions.extractLogs = async function extractLogs (logType, logsContainer = {}) {8 // make sure that we have logs at all9 // otherwise it's not been initialized10 if (_.isEmpty(logsContainer)) {11 throw new Error('No logs currently available. Is the device/simulator started?');12 }13 // If logs captured successfully send response with data, else send error14 const logObject = logsContainer[logType];15 const logs = logObject ? await logObject.getLogs() : null;16 if (logs) {17 return logs;18 }19 throw new Error(`No logs of type '${logType}' found.`);20};21extensions.supportedLogTypes = {22 syslog: {23 description: 'System Logs - Device logs for iOS applications on real devices and simulators',24 getter: async (self) => await self.extractLogs('syslog', self.logs),25 },26 crashlog: {27 description: 'Crash Logs - Crash reports for iOS applications on real devices and simulators',28 getter: async (self) => await self.extractLogs('crashlog', self.logs),29 },30 performance: {31 description: 'Performance Logs - Debug Timelines on real devices and simulators',32 getter: async (self) => await self.extractLogs('performance', self.logs),33 },34 server: {35 description: 'Appium server logs',36 getter: (self) => {37 self.ensureFeatureEnabled(GET_SERVER_LOGS_FEATURE);38 return logger.unwrap().record39 .map(function (x) {40 return {41 // npmlog does not keep timestamps in the history42 timestamp: Date.now(),43 level: 'ALL',44 message: _.isEmpty(x.prefix) ? x.message : `[${x.prefix}] ${x.message}`,45 };46 });47 },48 },49};50helpers.startLogCapture = async function startLogCapture (sim) {51 if (!_.isEmpty(this.logs)) {52 logger.warn("Trying to start iOS log capture but it's already started!");53 return;54 }55 this.logs.crashlog = new IOSCrashLog();56 this.logs.syslog = new IOSLog({57 sim,58 udid: this.opts.udid,59 showLogs: this.opts.showIOSLog,60 realDeviceLogger: this.opts.realDeviceLogger,61 xcodeVersion: this.xcodeVersion,62 });63 try {64 await this.logs.syslog.startCapture();65 } catch (err) {66 logger.warn('Could not capture logs from device. Continuing without capturing logs.');67 return;68 }69 await this.logs.crashlog.startCapture();70};71Object.assign(extensions, commands, helpers);72export { commands, helpers };...
log-specs.js
Source:log-specs.js
1import chai from 'chai';2import chaiAsPromised from 'chai-as-promised';3import _ from 'lodash';4import sinon from 'sinon';5import * as Logs from '../../lib/device-log/ios-log';6import * as CrashLogs from '../../lib/device-log/ios-crash-log';7import log from '../../lib/commands/log';8chai.should();9chai.use(chaiAsPromised);10describe('XCUITestDriver - startLogCapture', function () {11 let startCaptureSpy, crashLogStub, iosLogStub;12 before(function () {13 const spy = {14 startCapture: _.noop,15 };16 startCaptureSpy = sinon.spy(spy, 'startCapture');17 crashLogStub = sinon.stub(CrashLogs, 'IOSCrashLog').callsFake(function () {18 this.startCapture = _.noop;19 });20 iosLogStub = sinon.stub(Logs, 'IOSLog').callsFake(function () {21 this.startCapture = spy.startCapture;22 });23 });24 after(function () {25 startCaptureSpy.restore();26 crashLogStub.restore();27 iosLogStub.restore();28 });29 // establish that the basic things work as we imagine30 it('should not spawn more than one instance of idevicesyslog', async function () {31 const fakeInstance = {32 logs: undefined,33 opts: {},34 isRealDevice: _.noop,35 };36 startCaptureSpy.callCount.should.equal(0);37 await log.startLogCapture.call(fakeInstance);38 startCaptureSpy.callCount.should.equal(1);39 fakeInstance.logs.syslog.isCapturing = true;40 await log.startLogCapture.call(fakeInstance);41 startCaptureSpy.callCount.should.equal(1);42 });...
Using AI Code Generation
1const { startLogCapture } = require('appium-xcuitest-driver/lib/commands/log');2await startLogCapture('syslog');3const { stopLogCapture } = require('appium-xcuitest-driver/lib/commands/log');4await stopLogCapture('syslog');5const { getLogTypes } = require('appium-xcuitest-driver/lib/commands/log');6await getLogTypes();7const { getLog } = require('appium-xcuitest-driver/lib/commands/log');8await getLog('syslog');9const { getEventTimings } = require('appium-xcuitest-driver/lib/commands/performance');10await getEventTimings();11const { getPerformanceDataTypes } = require('appium-xcuitest-driver/lib/commands/performance');12await getPerformanceDataTypes();13const { getPerformanceData } = require('appium-xcuitest-driver/lib/commands/performance');14await getPerformanceData('com.apple.springboard', 'cpuinfo', 1000);15const { getNamedPages } = require('appium-xcuitest-driver/lib/commands/context');16await getNamedPages();17const { getNamedPageSource } = require('appium-xcuitest-driver/lib/commands/context');18await getNamedPageSource('pageName');19const { getNamedPageSource } = require('appium-xcuitest-driver/lib/commands/context');20await getNamedPageSource('pageName');21const { getContexts } = require('appium-xcuitest-driver/lib/commands/context');22await getContexts();
Using AI Code Generation
1var startLogCapture = require('appium-xcuitest-driver').startLogCapture;2startLogCapture('syslog');3var stopLogCapture = require('appium-xcuitest-driver').stopLogCapture;4stopLogCapture();5var getLog = require('appium-xcuitest-driver').getLog;6getLog('syslog');7var driver = new iosDriver();8driver.startLogCapture('syslog');9driver.stopLogCapture();10driver.getLog('syslog');11driver.getLog('syslog');12driver.getLog('syslog');13driver.getLog('syslog');14driver.getLog('syslog');15driver.getLog('syslog');16driver.getLog('syslog');17driver.getLog('syslog');18driver.getLog('syslog');19driver.getLog('syslog');
Using AI Code Generation
1var wd = require('wd');2var assert = require('assert');3var path = require('path');4var desiredCaps = {5 app: path.resolve(__dirname, 'UICatalog.app.zip')6};7var driver = wd.promiseChainRemote('localhost', 4723);8driver.init(desiredCaps)9 .then(() => driver.startLogCapture())10 .then(() => driver.sleep(5000))11 .then(() => driver.stopLogCapture())12 .then((logs) => {13 console.log(logs);14 })15 .catch((err) => console.log(err))16 .finally(() => driver.quit());
Using AI Code Generation
1const { startLogCapture } = require('appium-xcuitest-driver');2startLogCapture().then((logs) => {3 console.log(logs);4});5{6 "dependencies": {7 }8}9[{10}]11stopLogCapture()12const { stopLogCapture } = require('appium-xcuitest-driver');13stopLogCapture().then(() => {14 console.log('Log capture stopped');15});16{17 "dependencies": {18 }19}20getLogTypes()21const { getLogTypes } = require('appium-xcuitest-driver');22getLogTypes().then((types) => {23 console.log(types);24});25{26 "dependencies": {27 }28}29getLogs()30const { getLogs } = require('appium-xcuitest-driver');31getLogs('syslog').then((logs) => {32 console.log(logs);33});34{35 "dependencies": {36 }37}
Using AI Code Generation
1const { startLogCapture } = require('appium-xcuitest-driver');2const opts = {3};4let driver = new iosDriver();5await driver.createSession(opts);6const { getLog } = require('appium-xcuitest-driver');7const opts = {8};9let driver = new iosDriver();10await driver.createSession(opts);11const { getLogTypes } = require('appium-xcuitest-driver');12const opts = {13};14let driver = new iosDriver();15await driver.createSession(opts);16const { startPerformanceRecord } = require('appium-xcuitest-driver');17const opts = {18};19let driver = new iosDriver();20await driver.createSession(opts);
Using AI Code Generation
1var driver = require('appium-xcuitest-driver');2driver.startLogCapture();3driver.logEvent('info', 'Test log message');4driver.stopLogCapture();5commands.startLogCapture = async function () {6 if (this.isSimulator()) {7 return;8 }9 await this.startRealDeviceLogCapture();10};11commands.stopLogCapture = async function () {12 if (this.isSimulator()) {13 return;14 }15 await this.stopRealDeviceLogCapture();16};17commands.logEvent = async function (level, message) {18 if (this.isSimulator()) {19 return;20 }21 await this.realDeviceLogEvent(level, message);22};23commands.startRealDeviceLogCapture = async function () {24 if (this._realDeviceLogger) {25 return;26 }27 this._realDeviceLogger = new RealDeviceLogger({udid: this.opts.udid});28 this._realDeviceLogger.startCapture();29};30commands.stopRealDeviceLogCapture = async function () {31 if (!this._realDeviceLogger) {32 return;33 }34 this._realDeviceLogger.stopCapture();35 this._realDeviceLogger = null;36};37commands.realDeviceLogEvent = async function (level, message) {38 if (!this._realDeviceLogger) {39 return;40 }41 this._realDeviceLogger.logEvent(level, message);42};43class RealDeviceLogger {44 constructor (opts = {}) {45 const {udid} = opts;46 this.udid = udid;47 this.proc = null;48 this.onOutput = this.onOutput.bind(this);49 this.onExit = this.onExit.bind(this);50 this.logs = [];51 }52 startCapture () {53 this.proc = spawn('idevicesyslog', ['-u', this.udid]);54 this.proc.stdout.on('data', this.onOutput);55 this.proc.stderr.on('data', this.onOutput);56 this.proc.on('exit', this.onExit);57 }58 stopCapture () {59 if (!this.proc) {60 return;61 }62 this.proc.stdout.removeListener('data', this.onOutput);63 this.proc.stderr.removeListener('data', this.onOutput);
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!!