How to use driver.getOrientation method in Appium

Best JavaScript code snippet using appium

Run Appium automation tests on LambdaTest cloud grid

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

orientation-e2e-specs.js

Source: orientation-e2e-specs.js Github

copy
1import chai from 'chai';
2import chaiAsPromised from 'chai-as-promised';
3import B from 'bluebird';
4import { APIDEMOS_CAPS } from '../desired';
5import { initDriver } from '../helpers/session';
6
7
8chai.should();
9chai.use(chaiAsPromised);
10
11describe('apidemo - orientation -', function () {
12  let driver;
13
14  describe('initial -', function () {
15    afterEach(async function () {
16      await driver.setOrientation('PORTRAIT');
17      await driver.quit();
18    });
19    it('should have portrait orientation if requested', async function () {
20      driver = await initDriver(Object.assign({}, APIDEMOS_CAPS, {
21        appActivity: '.view.TextFields',
22        orientation: 'PORTRAIT',
23      }));
24      await driver.getOrientation().should.eventually.eql('PORTRAIT');
25    });
26    it('should have landscape orientation if requested', async function () {
27      driver = await initDriver(Object.assign({}, APIDEMOS_CAPS, {
28        appActivity: '.view.TextFields',
29        orientation: 'LANDSCAPE',
30      }));
31      await driver.getOrientation().should.eventually.eql('LANDSCAPE');
32    });
33    it('should have portrait orientation if nothing requested', async function () {
34      driver = await initDriver(Object.assign({}, APIDEMOS_CAPS, {
35        appActivity: '.view.TextFields',
36      }));
37      await driver.getOrientation().should.eventually.eql('PORTRAIT');
38    });
39  });
40  describe('setting -', function () {
41    before(async function () {
42      driver = await initDriver(Object.assign({}, APIDEMOS_CAPS, {
43        appActivity: '.view.TextFields'
44      }));
45    });
46    after(async function () {
47      await driver.quit();
48    });
49    it('should rotate screen to landscape', async function () {
50      await driver.setOrientation('PORTRAIT');
51      await B.delay(3000);
52      await driver.setOrientation('LANDSCAPE');
53      await B.delay(3000);
54      await driver.getOrientation().should.eventually.become('LANDSCAPE');
55    });
56    it('should rotate screen to landscape', async function () {
57      await driver.setOrientation('LANDSCAPE');
58      await B.delay(3000);
59      await driver.setOrientation('PORTRAIT');
60      await B.delay(3000);
61      await driver.getOrientation().should.eventually.become('PORTRAIT');
62    });
63    it('should not error when trying to rotate to portrait again', async function () {
64      await driver.setOrientation('PORTRAIT');
65      await B.delay(3000);
66      await driver.setOrientation('PORTRAIT');
67      await B.delay(3000);
68      await driver.getOrientation().should.eventually.become('PORTRAIT');
69    });
70  });
71});
72
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run JavaScript Tests on LambdaTest Cloud Grid

Execute automation tests with Appium on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)