How to use driver.setOrientation method in Appium Xcuitest Driver

Best JavaScript code snippet using appium-xcuitest-driver

basic-e2e-specs.js

Source:basic-e2e-specs.js Github

copy

Full Screen

...75 });76 describe('screenshot', () => {77 after(async () => {78 try {79 await driver.setOrientation("PORTRAIT");80 } catch (ign) {}81 });82 it('should get an app screenshot', async () => {83 let screenshot = await driver.takeScreenshot();84 screenshot.should.exist;85 screenshot.should.be.a.string;86 });87 it('should get an app screenshot in landscape mode', async () => {88 let screenshot1 = (await driver.takeScreenshot());89 screenshot1.should.exist;90 try {91 await driver.setOrientation("LANDSCAPE");92 } catch (ign) {}93 // take a little pause while it orients, otherwise you get the screenshot94 // on an angle95 await B.delay(500);96 let screenshot2 = await driver.takeScreenshot();97 screenshot2.should.exist;98 screenshot2.should.not.eql(screenshot1);99 });100 });101 describe('logging', () => {102 describe('types', () => {103 it('should get the list of available logs', async () => {104 let expectedTypes = ['syslog', 'crashlog', 'performance'];105 (await driver.logTypes()).should.eql(expectedTypes);106 });107 });108 describe('retrieval', () => {109 it('should throw an error when an invalid type is given', async () => {110 await driver.log('something-random').should.eventually.be.rejected;111 });112 it('should get system logs', async () => {113 (await driver.log('syslog')).should.be.an.Array;114 });115 it('should get crash logs', async () => {116 (await driver.log('crashlog')).should.be.an.Array;117 });118 });119 });120 describe('orientation', () => {121 beforeEach(async () => {122 await driver.setOrientation('PORTRAIT');123 });124 afterEach(async () => {125 await driver.setOrientation('PORTRAIT');126 });127 it('should get the current orientation', async () => {128 let orientation = await driver.getOrientation();129 ['PORTRAIT', 'LANDSCAPE'].should.include(orientation);130 });131 it('should set the orientation', async function () {132 await driver.setOrientation('LANDSCAPE');133 (await driver.getOrientation()).should.eql('LANDSCAPE');134 });135 it('should be able to interact with an element in LANDSCAPE', async function () {136 await driver.setOrientation('LANDSCAPE');137 let el = await driver.elementByAccessibilityId('Buttons');138 await el.click();139 await driver.elementByAccessibilityId('Button').should.not.be.rejected;140 await driver.back();141 });142 });143 describe('window size', () => {144 it('should be able to get the current window size', async () => {145 let size = await driver.getWindowSize('current');146 size.width.should.be.a.number;147 size.height.should.be.a.number;148 });149 it('should not be able to get random window size', async () => {150 await driver.getWindowSize('something-random').should.be.rejectedWith(/Currently only getting current window size is supported/);...

Full Screen

Full Screen

general-tests.js

Source:general-tests.js Github

copy

Full Screen

...37 it('should get the orientation', async function () {38 (await driver.getOrientation()).should.equal('PORTRAIT');39 });40 it('should set the orientation to something valid', async function () {41 await driver.setOrientation('LANDSCAPE');42 (await driver.getOrientation()).should.equal('LANDSCAPE');43 });44 it('should not set the orientation to something invalid', async function () {45 await driver.setOrientation('INSIDEOUT')46 .should.eventually.be.rejectedWith(/Orientation must be/);47 });48 it('should get a screenshot', async function () {49 should.exist(await driver.takeScreenshot());50 });51 it('should set implicit wait timeout', async function () {52 await driver.setImplicitWaitTimeout(1000);53 });54 it('should not set invalid implicit wait timeout', async function () {55 await driver.setImplicitWaitTimeout('foo')56 .should.eventually.be.rejectedWith(/ms/);57 });58 // skip these until basedriver supports these timeouts59 it.skip('should set async script timeout', async function () {...

Full Screen

Full Screen

application.js

Source:application.js Github

copy

Full Screen

...33 });34 it(`Application Events`, async () => {35 let oriantation = await driver.findElementByText("Portrait", "contains");36 chai.assert.isTrue(await oriantation.isDisplayed(), "Portrait is not visible");37 await driver.setOrientation("LANDSCAPE");38 oriantation = await driver.findElementByText("Landscape", "contains");39 chai.assert.isTrue(await oriantation.isDisplayed(), "LANDSCAPE is not visible");40 await driver.setOrientation("PORTRAIT");41 oriantation = await driver.findElementByText("Portrait", "contains");42 chai.assert.isTrue(await oriantation.isDisplayed(), "Portrait is not visible");43 await driver.backgroundApp(2);44 const suspendSuspendEvent = await driver.findElementByText("The appication was suspended!", "contains");45 chai.assert.isTrue(await suspendSuspendEvent.isDisplayed(), "suspendSuspendEvent is not thrown"); 46 const suspendResumeEvent = await driver.findElementByText("The appication was resumed", "contains");47 chai.assert.isTrue(await suspendResumeEvent.isDisplayed(), "suspendResumeEvent is not thrown"); 48 });49 it(`Check Platform`, async () => {50 const platform = driver.isAndroid ? "Android" : "iOS";51 const batteryIndicator = await driver.findElementByText(`${platform} Applicaiton`, "contains");52 chai.assert.isTrue(await batteryIndicator.isDisplayed(), "Not correct platform!");53 });54});

Full Screen

Full Screen

orientation-e2e-specs.js

Source:orientation-e2e-specs.js Github

copy

Full Screen

...8describe('apidemo - orientation -', function () {9 let driver;10 describe('initial -', function () {11 afterEach(async function () {12 await driver.setOrientation('PORTRAIT');13 await deleteSession();14 });15 it('should have portrait orientation if requested', async function () {16 driver = await initSession(Object.assign({}, APIDEMOS_CAPS, {17 appActivity: '.view.TextFields',18 orientation: 'PORTRAIT',19 }));20 await driver.getOrientation().should.eventually.eql('PORTRAIT');21 });22 it('should have landscape orientation if requested', async function () {23 driver = await initSession(Object.assign({}, APIDEMOS_CAPS, {24 appActivity: '.view.TextFields',25 orientation: 'LANDSCAPE',26 }));27 await driver.getOrientation().should.eventually.eql('LANDSCAPE');28 });29 it('should have portrait orientation if nothing requested', async function () {30 driver = await initSession(Object.assign({}, APIDEMOS_CAPS, {31 appActivity: '.view.TextFields',32 }));33 await driver.getOrientation().should.eventually.eql('PORTRAIT');34 });35 });36 describe('setting -', function () {37 before(async function () {38 driver = await initSession(Object.assign({}, APIDEMOS_CAPS, {39 appActivity: '.view.TextFields'40 }));41 });42 after(async function () {43 await deleteSession();44 });45 it('should rotate screen to landscape', async function () {46 await driver.setOrientation('PORTRAIT');47 await B.delay(3000);48 await driver.setOrientation('LANDSCAPE');49 await B.delay(3000);50 await driver.getOrientation().should.eventually.become('LANDSCAPE');51 });52 it('should rotate screen to landscape', async function () {53 await driver.setOrientation('LANDSCAPE');54 await B.delay(3000);55 await driver.setOrientation('PORTRAIT');56 await B.delay(3000);57 await driver.getOrientation().should.eventually.become('PORTRAIT');58 });59 it('should not error when trying to rotate to portrait again', async function () {60 await driver.setOrientation('PORTRAIT');61 await B.delay(3000);62 await driver.setOrientation('PORTRAIT');63 await B.delay(3000);64 await driver.getOrientation().should.eventually.become('PORTRAIT');65 });66 });...

Full Screen

Full Screen

dialog.test.js

Source:dialog.test.js Github

copy

Full Screen

...16 dialog.dialogOkBtn.click()17 })18 it.only('Verify that the app adjusts when orientation is switched', () => {19 console.log(driver.getOrientation())20 driver.setOrientation('LANDSCAPE')21 driver.pause(3000)22 driver.saveScreenshot('./screenshots/landscape.png')23 dialog.appbtn.click();24 driver.setOrientation('PORTRAIT')25 driver.back()26 driver.saveScreenshot('./screenshots/portrait.png')27 })28 it.only('Verify thee repeat alarm options has attribute checked set to true when selected', () => {29 dialog.appbtn.click()30 dialog.alertDialogBtn.click()31 })...

Full Screen

Full Screen

sample.test.js

Source:sample.test.js Github

copy

Full Screen

...14 await dialog.okBtnClick();15 });16 it('Verify that the app adjust when orientation is switched', async () => {17 console.log("############################## ORIENTATION : ################################# ", await driver.getOrientation());18 await driver.setOrientation("LANDSCAPE");19 await driver.saveScreenshot('./test-execution_report/mobile-ui/screenshot/landscape.png');20 await driver.setOrientation("PORTRAIT");21 await driver.saveScreenshot("./test-execution_report/mobile-ui/screenshot/portrait.png");22 });...

Full Screen

Full Screen

orientation-specs.js

Source:orientation-specs.js Github

copy

Full Screen

1"use strict";2var setup = require("../../common/setup-base")3 , env = require('../../../helpers/env')4 , desired = require("./desired")5 , reset = require("./reset");6describe("apidemos - orientation", function () {7 var driver;8 setup(this, desired).then(function (d) { driver = d; });9 if (env.FAST_TESTS) {10 beforeEach(function () {11 return reset(driver);12 });13 }14 it('should rotate screen to landscape', function (done) {15 driver16 .setOrientation("PORTRAIT")17 .sleep(3000)18 .setOrientation("LANDSCAPE")19 .sleep(3000)20 .getOrientation().should.become("LANDSCAPE")21 .nodeify(done);22 });23 it('should rotate screen to portrait', function (done) {24 driver25 .setOrientation("LANDSCAPE")26 .sleep(3000)27 .setOrientation("PORTRAIT")28 .sleep(3000)29 .getOrientation().should.become("PORTRAIT")30 .nodeify(done);31 });32 it('Should not error when trying to rotate to portrait again', function (done) {33 driver34 .setOrientation("PORTRAIT")35 .sleep(3000)36 .setOrientation("PORTRAIT")37 .sleep(3000)38 .getOrientation().should.become("PORTRAIT")39 .nodeify(done);40 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const wd = require('wd');2const assert = require('assert');3const PORT = 4723;4const config = {5};6async function main() {7 let driver = await wd.promiseChainRemote('localhost', PORT);8 await driver.init(config);9 await driver.sleep(3000);10 await driver.setOrientation('PORTRAIT');11 let orientation = await driver.getOrientation();12 assert.equal(orientation, "PORTRAIT");13 await driver.quit();14}15main();16const wd = require('wd');17const assert = require('assert');18const PORT = 4723;19const config = {20};21async function main() {22 let driver = await wd.promiseChainRemote('localhost', PORT);23 await driver.init(config);24 await driver.sleep(3000);25 await driver.setOrientation('PORTRAIT');26 let orientation = await driver.getOrientation();27 assert.equal(orientation, "PORTRAIT");28 await driver.quit();29}30main();

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var assert = require('assert');3var caps = {4};5var driver = wd.promiseChainRemote('localhost', 4723);6 .init(caps)7 .setOrientation('LANDSCAPE')8 .then(function() {9 return driver.takeScreenshot();10 })11 .then(function(img) {12 require('fs').writeFile('landscape.png', img, 'base64', function(err) {13 console.log(err);14 });15 })16 .setOrientation('PORTRAIT')17 .then(function() {18 return driver.takeScreenshot();19 })20 .then(function(img) {21 require('fs').writeFile('portrait.png', img, 'base64', function(err) {22 console.log(err);23 });24 })25 .quit();

Full Screen

Using AI Code Generation

copy

Full Screen

1const wd = require('wd');2const chai = require('chai');3const chaiAsPromised = require('chai-as-promised');4chai.use(chaiAsPromised);5const expect = chai.expect;6const caps = {7};8const driver = wd.promiseChainRemote('localhost', 4723);9driver.init(caps)10 .then(() => driver.setOrientation('LANDSCAPE'))11 .then(() => driver.setOrientation('PORTRAIT'))12 .then(() => driver.quit())13 .catch((err) => console.log(err));

Full Screen

Using AI Code Generation

copy

Full Screen

1const wdio = require('webdriverio');2const driver = wdio.remote({3 desiredCapabilities: {4 }5});6driver.init();7driver.setOrientation('LANDSCAPE');8driver.end();9* Appium version (or git revision) that exhibits the issue: 1.6.410* Last Appium version that did not exhibit the issue (if applicable):11* Node.js version (unless using Appium.app|exe): v7.10.0

Full Screen

Using AI Code Generation

copy

Full Screen

1const wd = require('wd');2const {host, port, user, key} = require('./credentials');3const driver = wd.promiseChainRemote(host, port, user, key);4 .init({5 })6 .then(() => driver.setOrientation('LANDSCAPE'))7 .then(() => driver.setOrientation('PORTRAIT'))8 .then(() => driver.quit());

Full Screen

Using AI Code Generation

copy

Full Screen

1const webdriver = require('selenium-webdriver');2const { Eyes, Target, VisualGridRunner, ClassicRunner, BatchInfo, ConsoleLogHandler, StitchMode, Configuration, DeviceName, ScreenOrientation, BatchInfo, DeviceName, ScreenOrientation } = require('@applitools/eyes-selenium');3let driver;4async function main() {5 const eyes = new Eyes(new ClassicRunner());6 const batchInfo = new BatchInfo('Demo Batch');7 const configuration = new Configuration();8 configuration.setApiKey(process.env.APPLITOOLS_API_KEY);9 configuration.setBatch(batchInfo);10 configuration.setAppName('Demo App');11 configuration.setTestName('Demo Test');12 configuration.setMatchLevel('Strict');13 configuration.setForceFullPageScreenshot(true);14 configuration.setStitchMode(StitchMode.CSS);15 configuration.addBrowser(800, 600, BrowserType.CHROME);16 configuration.addBrowser(700, 500, BrowserType.FIREFOX);17 configuration.addBrowser(1600, 1200, BrowserType.EDGE_CHROMIUM);18 configuration.addBrowser(1024, 768, BrowserType.IE_11);19 configuration.addBrowser(800, 600, BrowserType.SAFARI);20 configuration.addDeviceEmulation(DeviceName.iPhone_X, ScreenOrientation.PORTRAIT);21 eyes.setConfiguration(configuration);22 eyes.setLogHandler(new ConsoleLogHandler(true));23 try {24 driver = await new webdriver.Builder()25 .forBrowser('chrome')26 .build();27 await eyes.open(driver);28 await eyes.check('Main Page', Target.window());29 await eyes.close();30 } finally {31 await driver.quit();32 await eyes.abortIfNotClosed();33 }34}35main();36const webdriver = require('selenium-webdriver');37const { Eyes, Target, VisualGridRunner, ClassicRunner, BatchInfo, ConsoleLogHandler, StitchMode, Configuration, DeviceName, ScreenOrientation, BatchInfo, DeviceName, ScreenOrientation } = require('@applitools/eyes-selenium');38let driver;39async function main() {40 const eyes = new Eyes(new ClassicRunner());41 const batchInfo = new BatchInfo('Demo Batch');42 const configuration = new Configuration();43 configuration.setApiKey(process.env.APPLITOOLS_API_KEY);44 configuration.setBatch(batchInfo);45 configuration.setAppName('

Full Screen

Using AI Code Generation

copy

Full Screen

1const wdio = require("webdriverio");2const assert = require("assert");3const opts = {4 capabilities: {5 }6};7async function main() {8 const client = await wdio.remote(opts);9 await client.setOrientation("LANDSCAPE");10 await client.deleteSession();11}12main();

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