How to use driver.setOrientation method in Appium

Best JavaScript code snippet using appium

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

1var webdriver = require('selenium-webdriver'),2 until = webdriver.until;3var driver = new webdriver.Builder()4 .forBrowser('firefox')5 .build();6driver.findElement(By.name('q')).sendKeys('webdriver');7driver.findElement(By.name('btnG')).click();8driver.wait(until.titleIs('webdriver - Google Search'), 1000);9driver.setOrientation('LANDSCAPE');10driver.quit();

Full Screen

Using AI Code Generation

copy

Full Screen

1driver.setOrientation("LANDSCAPE");2driver.setOrientation("PORTRAIT");3driver.getOrientation();4driver.hideKeyboard();5driver.isKeyboardShown();6driver.getDeviceTime();7driver.getGeoLocation();8driver.setGeoLocation(12.34, 56.78, 90.12);9driver.getNetworkConnection();10driver.setNetworkConnection(1);11driver.startActivity("com.example", "com.example.Activity");12driver.currentActivity();13driver.appStrings();14driver.lock(5);15driver.unlock();16driver.isLocked();17driver.rotate("LANDSCAPE");18driver.backgroundApp(5);19driver.openNotifications();20driver.touchId(true);21driver.toggleTouchIdEnrollment(true);

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var assert = require('assert');3var desiredCaps = {4};5driver.init(desiredCaps).then(function(){6 driver.setOrientation("LANDSCAPE");7 driver.sleep(5000);8 driver.setOrientation("PORTRAIT");9 driver.sleep(5000);10 driver.quit();11});

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('selenium-webdriver');2 build();3driver.setOrientation('LANDSCAPE');4driver.quit();5var webdriver = require('selenium-webdriver');6 build();7driver.getOrientation().then(function(orientation) {8 console.log(orientation);9});10driver.quit();

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2driver.init({3}, function() {4 driver.setOrientation('LANDSCAPE', function() {5 });6});7var wd = require('wd');8driver.init({9}, function() {10 driver.getOrientation(function(err, orientation) {11 });12});13var wd = require('wd');14driver.init({15}, function() {16 driver.getNetworkConnection(function(err, network) {17 });18});19var wd = require('wd');20driver.init({

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('selenium-webdriver'),2 until = webdriver.until;3var driver = new webdriver.Builder()4 .forBrowser('chrome')5 .build();6driver.setOrientation("LANDSCAPE");7driver.sleep(5000);8driver.setOrientation("PORTRAIT");9driver.sleep(5000);10driver.quit();

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Appium automation tests on LambdaTest cloud grid

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

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful