How to use driver.getScreenshot method in Appium Xcuitest Driver

Best JavaScript code snippet using appium-xcuitest-driver

actions-specs.js

Source:actions-specs.js Github

copy

Full Screen

...423 });424 it('should be able to take screenshot via exec-out (API level > 20)', async function () {425 driver.adb.getApiLevel.returns(24);426 driver.getScreenshotDataWithAdbExecOut.withArgs(driver.adb).returns(image);427 await driver.getScreenshot().should.become('YXBwaXVt');428 driver.getScreenshotDataWithAdbExecOut.calledOnce.should.be.true;429 driver.getScreenshotDataWithAdbShell.notCalled.should.be.true;430 image.getBuffer.calledWith(jimp.MIME_PNG).should.be.true;431 });432 it('should be able to take screenshot via adb shell (API level <= 20)', async function () {433 driver.adb.getApiLevel.returns(20);434 driver.getScreenshotDataWithAdbShell.withArgs(driver.adb, driver.opts).returns(image);435 await driver.getScreenshot().should.become('YXBwaXVt');436 driver.getScreenshotDataWithAdbShell.calledOnce.should.be.true;437 driver.getScreenshotDataWithAdbExecOut.notCalled.should.be.true;438 image.getBuffer.calledWith(jimp.MIME_PNG).should.be.true;439 });440 it('should tries to take screenshot via adb shell if exec-out failed (API level > 20)', async function () {441 driver.adb.getApiLevel.returns(24);442 driver.getScreenshotDataWithAdbExecOut.throws();443 driver.getScreenshotDataWithAdbShell.withArgs(driver.adb, driver.opts).returns(image);444 await driver.getScreenshot().should.become('YXBwaXVt');445 driver.getScreenshotDataWithAdbShell.calledOnce.should.be.true;446 driver.getScreenshotDataWithAdbShell.calledOnce.should.be.true;447 });448 it('should throw error if adb shell failed', async function () {449 driver.adb.getApiLevel.returns(20);450 driver.getScreenshotDataWithAdbShell.throws();451 await driver.getScreenshot().should.be.rejectedWith('Cannot get screenshot');452 });453 it('should rotate image if API level < 23', async function () {454 driver.adb.getApiLevel.returns(22);455 driver.getScreenshotDataWithAdbExecOut.withArgs(driver.adb).returns(image);456 await driver.getScreenshot();457 driver.adb.getScreenOrientation.calledOnce.should.be.true;458 image.rotate.calledOnce.should.be.true;459 });460 it('should not rotate image if API level >= 23', async function () {461 driver.adb.getApiLevel.returns(23);462 driver.getScreenshotDataWithAdbExecOut.withArgs(driver.adb).returns(image);463 await driver.getScreenshot();464 driver.adb.getScreenOrientation.notCalled.should.be.true;465 image.rotate.notCalled.should.be.true;466 });467 it('should not throws error if rotate image failed', async function () {468 image.rotate.resetBehavior();469 image.rotate.throws();470 driver.adb.getApiLevel.returns(22);471 driver.getScreenshotDataWithAdbExecOut.withArgs(driver.adb).returns(image);472 await driver.getScreenshot().should.be.fulfilled;473 image.rotate.threw().should.be.true;474 });475 });...

Full Screen

Full Screen

baiduTest.spec.js

Source:baiduTest.spec.js Github

copy

Full Screen

...137 let filepath = self.screenshotPath + '/' + self.caseName + '_' + self.stepId;138 let driver = self.driver;139 try{140 // catch error when get alert msg141 await driver.getScreenshot(filepath + '.png');142 let url = await driver.url();143 let html = await driver.source();144 html = '<!--url: '+url+' -->\n' + html;145 fs.writeFileSync(filepath + '.html', html);146 let cookies = await driver.cookies();147 fs.writeFileSync(filepath + '.cookie', JSON.stringify(cookies));148 }149 catch(e){}150 }151 });152 after(function(){153 return this.driver.close();154 });155 });...

Full Screen

Full Screen

screenshots-specs.js

Source:screenshots-specs.js Github

copy

Full Screen

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

Full Screen

Full Screen

test.url.js

Source:test.url.js Github

copy

Full Screen

...112 if(doScreenshot && !/^(closeWindow):/.test(title)){113 var filepath = screenshotPath + '/' + caseName.replace(/[^\/]+$/, function(all){114 return all.replace(/\s*[:\.\:\-\s]\s*/g, '_');115 }) + '_' + (stepId++) + '.png';116 return _this.driver.getScreenshot(filepath).catch(function(){});117 }118 });119 after(function(){120 return this.driver.close();121 });122 });123 });124}125function getRootPath(){126 var rootPath = path.resolve(__dirname);127 while(rootPath){128 if(fs.existsSync(rootPath + '/config.json')){129 break;130 }...

Full Screen

Full Screen

jwebdriver-mobile.js

Source:jwebdriver-mobile.js Github

copy

Full Screen

...81 afterEach(async function(){82 let self = this;83 let filepath = self.screenshotPath + '/' + self.caseName + '_' + self.stepId;84 let driver = self.driver;85 await driver.getScreenshot(filepath + '.png');86 let json = await driver.source();87 fs.writeFileSync(filepath + '.json', json);88 });89 after(function(){90 return this.driver.close();91 });92 });93 });94}95function getRootPath(){96 let rootPath = path.resolve(__dirname);97 while(rootPath){98 if(fs.existsSync(rootPath + '/config.json')){99 break;...

Full Screen

Full Screen

actions-e2e-specs.js

Source:actions-e2e-specs.js Github

copy

Full Screen

...49 });50 });51 describe('getScreenshot', function () {52 it('should return valid base64-encoded screenshot', async function () {53 const base64screenshot = await driver.getScreenshot();54 const imageMagic = Buffer.from(base64screenshot, 'base64').toString('hex', 0, PNG_MAGIC_LENGTH);55 imageMagic.should.be.equal(PNG_MAGIC);56 });57 });...

Full Screen

Full Screen

screenshot-specs.js

Source:screenshot-specs.js Github

copy

Full Screen

...4describe('testapp - screenshots', function () {5 describe('default', function () {6 const driver = setup(this, desired).driver;7 it('should get an app screenshot', async function () {8 (await driver.getScreenshot()).should.exist;9 });10 // TODO: fails in ci env, investigate11 it('should get an app screenshot in landscape mode @skip-ci', async function () {12 let screenshot1 = (await driver.getScreenshot());13 screenshot1.should.exist;14 try {15 await driver.setOrientation('LANDSCAPE');16 } catch (e) {17 // A useless error does often exist here, let's ignore it18 }19 let screenshot2 = await driver.getScreenshot();20 screenshot2.should.exist;21 screenshot2.should.not.eql(screenshot1);22 // cooldown23 await B.delay(3000);24 });25 });26 describe('setting screenshotWaitTimeout', function () {27 const driver = setup(this, desired).driver;28 it('should get an app screenshot', async function () {29 (await driver.getScreenshot()).should.exist;30 });31 });...

Full Screen

Full Screen

viewport-screenshot-specs.js

Source:viewport-screenshot-specs.js Github

copy

Full Screen

...15 sinon.stub(driver, 'getWindowSize').returns({width: 320, height: 568});16 sinon.stub(driver, 'getDevicePixelRatio').returns(2);17 sinon.stub(driver, 'getStatusBarHeight').returns(0);18 sinon.stub(driver, 'getScreenshot').returns(await getImage('screenshot.b64'));19 let screenshot = await driver.getScreenshot();20 expect(screenshot).to.be.not.empty;21 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const path = require('path');2const { remote } = require('webdriverio');3(async () => {4 const browser = await remote({5 capabilities: {6 }7 })8 const screenshot = await browser.takeScreenshot()9 console.log(screenshot)10 await browser.deleteSession()11})().catch(async (e) => console.error(e))12{13 "scripts": {14 },15 "dependencies": {16 }17}

Full Screen

Using AI Code Generation

copy

Full Screen

1const test = require('selenium-webdriver/testing');2const webdriver = require('selenium-webdriver');3const {Builder, By, until} = require('selenium-webdriver');4const {Options} = require('selenium-webdriver/chrome');5const {Eyes, Target, ConsoleLogHandler, BatchInfo} = require('@applitools/eyes.selenium');6const {getDriver, getEyes} = require('./driver');7const appName = 'Test App';8const batchName = 'Test Batch';9const batch = new BatchInfo(batchName);10test.describe('Test App', function () {11 let driver, eyes;12 test.beforeEach(async function () {13 driver = await getDriver();14 eyes = await getEyes();15 eyes.setBatch(batch);16 });17 test.it('Test 1', async function () {18 await eyes.open(driver, appName, 'Test 1', {width: 800, height: 600});19 await eyes.check('Login Page', Target.window());20 await eyes.close();21 });22 test.afterEach(async function () {23 await eyes.abortIfNotClosed();24 await driver.quit();25 });26});27const {Eyes, Target, ConsoleLogHandler, BatchInfo} = require('@applitools/eyes.selenium');28const {Builder, By, until} = require('selenium-webdriver');29const {Options} = require('selenium-webdriver/chrome');30const appName = 'Test App';31const batchName = 'Test Batch';32const batch = new BatchInfo(batchName);33const getDriver = async () => {34 const options = new Options();35 const driver = await new Builder()36 .forBrowser('chrome')37 .setChromeOptions(options)38 .build();39 return driver;40};41const getEyes = async () => {42 const eyes = new Eyes();43 eyes.setLogHandler(new ConsoleLogHandler(true));44 eyes.setApiKey(process.env.APPLITOOLS_API_KEY);45 return eyes;46};47module.exports = {getDriver, getEyes};

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('selenium-webdriver');2 build();3driver.getScreenshot().then(function(data) {4 require('fs').writeFile('out.png', data, 'base64', function(err) {5 console.log(err);6 });7});8driver.quit();

Full Screen

Using AI Code Generation

copy

Full Screen

1const {Builder, By, until} = require('selenium-webdriver');2const test = require('selenium-webdriver/testing');3const assert = require('assert');4const fs = require('fs');5test.describe('Appium XCUITest Driver', function() {6 let driver;7 test.before(function *() {8 driver = yield new Builder()9 .forBrowser('safari')10 .build();11 });12 test.it('should take screenshot', function *() {13 const screenshot = yield driver.getScreenshot();14 fs.writeFileSync('screenshot.png', new Buffer(screenshot, 'base64'));15 });16 test.after(() => driver.quit());17});18Create your feature branch (git checkout -b my-new-feature)19Commit your changes (git commit -am 'Add some feature')20Push to the branch (git push origin my-new-feature)

Full Screen

Using AI Code Generation

copy

Full Screen

1const wdio = require('webdriverio');2const options = {3 desiredCapabilities: {4 }5};6const client = wdio.remote(options);7client.init().then(() => {8 return client.getScreenshot();9}).then((res) => {10 console.log(res);11 const fs = require('fs');12 const stream = fs.createWriteStream("./test.png");13 stream.write(new Buffer(res, 'base64'));14 stream.end();15}).catch((err) => {16 console.log(err);17});18client.end();19const wdio = require('webdriverio');20const options = {21 desiredCapabilities: {22 }23};24const client = wdio.remote(options);25client.init().then(() => {26 return client.getScreenshot();27}).then((res) => {28 console.log(res);29 const fs = require('fs');30 const stream = fs.createWriteStream("./test.png");31 stream.write(new Buffer(res, 'base64'));32 stream.end();33}).catch((err) => {34 console.log(err);35});36client.end();

Full Screen

Using AI Code Generation

copy

Full Screen

1const wd = require('wd');2const { execSync } = require('child_process');3const username = process.env.SAUCE_USERNAME;4const accessKey = process.env.SAUCE_ACCESS_KEY;5const driver = wd.promiseChainRemote('ondemand.saucelabs.com', 443, username, accessKey);6(async function example() {7 try {8 await driver.init({9 'sauce:options': {10 },11 });12 await driver.sleep(5000);13 const screenshot = await driver.getScreenshot();14 execSync(`echo ${screenshot} | base64 -d > screenshot.png`);15 } catch (err) {16 console.log(err);17 } finally {18 await driver.quit();19 }20})();

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var path = require('path');3var fs = require('fs');4var assert = require('assert');5var desired = {6}7var driver = wd.promiseChainRemote('

Full Screen

Using AI Code Generation

copy

Full Screen

1const wd = require('wd');2const { exec } = require('child_process');3const app = '/path/to/your.app';4async function main() {5 await driver.init({6 });7 await driver.sleep(3000);8 await driver.getScreenshot('screenshot.png');9 await driver.quit();10}11main();12const wd = require('wd');13const { exec } = require('child_process');14const app = '/path/to/your.app';15async function main() {16 await driver.init({17 });18 await driver.sleep(3000);19 const base64Screenshot = await driver.saveScreenshot();20 await driver.quit();21}22main();23const wd = require('wd');24const fs = require('fs');25const { exec } = require('child_process');26const app = '/path/to/your.app';27async function main() {28 await driver.init({29 });30 await driver.sleep(3000);

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 Xcuitest Driver automation tests on LambdaTest cloud grid

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

Sign up Free
_

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful