How to use driver.getOrientation method in Appium

Best JavaScript code snippet using appium

js-oxygen.js

Source:js-oxygen.js Github

copy

Full Screen

1import Framework from './framework';2class JsOxygenFramework extends Framework {3 get language () {4 return 'js';5 }6 wrapWithBoilerplate (code) {7 let caps = JSON.stringify(this.caps);8 let url = JSON.stringify(`${this.scheme}://${this.host}:${this.port}${this.path}`);9 return `// Requires the Oxygen HQ client library10// (npm install oxygen-cli -g)11// Then paste this into a .js file and run with:12// oxygen <file>.js13mob.init(${caps}, ${url});14${code}15`;16 }17 codeFor_findAndAssign (strategy, locator, localVar, isArray) {18 // wdio has its own way of indicating the strategy in the locator string19 switch (strategy) {20 case 'xpath': break; // xpath does not need to be updated21 case 'accessibility id': locator = `~${locator}`; break;22 case 'id': locator = `id=${locator}`; break;23 case 'name': locator = `name=${locator}`; break;24 case 'class name': locator = `css=${locator}`; break;25 case '-android uiautomator': locator = `android=${locator}`; break;26 case '-android datamatcher': locator = `android=${locator}`; break;27 case '-ios predicate string': locator = `ios=${locator}`; break;28 case '-ios class chain': locator = `ios=${locator}`; break; // TODO: Handle IOS class chain properly. Not all libs support it. Or take it out29 default: throw new Error(`Can't handle strategy ${strategy}`);30 }31 if (isArray) {32 return `let ${localVar} = mob.findElements(${JSON.stringify(locator)});`;33 } else {34 return `let ${localVar} = mob.findElement(${JSON.stringify(locator)});`;35 }36 }37 codeFor_click (varName, varIndex) {38 return `mob.click(${this.getVarName(varName, varIndex)});`;39 }40 codeFor_clear (varName, varIndex) {41 return `mob.clear(${this.getVarName(varName, varIndex)});`;42 }43 codeFor_sendKeys (varName, varIndex, text) {44 return `mob.type(${this.getVarName(varName, varIndex)}, ${JSON.stringify(text)});`;45 }46 codeFor_back () {47 return `mob.back();`;48 }49 codeFor_tap (varNameIgnore, varIndexIgnore, x, y) {50 return `mob.tap(${x}, ${y});`;51 }52 codeFor_swipe (varNameIgnore, varIndexIgnore, x1, y1, x2, y2) {53 return `mob.swipeScreen(${x1}, ${y1}, ${x2}, ${y2});`;54 }55 codeFor_getCurrentActivity () {56 return `let activityName = mob.getCurrentActivity();`;57 }58 codeFor_getCurrentPackage () {59 return `let packageName = mob.getCurrentPackage();`;60 }61 codeFor_installAppOnDevice (varNameIgnore, varIndexIgnore, app) {62 return `mob.installApp('${app}');`;63 }64 codeFor_isAppInstalledOnDevice (varNameIgnore, varIndexIgnore, app) {65 return `let isAppInstalled = mob.isAppInstalled("${app}");`;66 }67 codeFor_launchApp () {68 return `mob.launchApp();`;69 }70 codeFor_backgroundApp (varNameIgnore, varIndexIgnore, timeout) {71 return `mob.driver().background(${timeout});`;72 }73 codeFor_closeApp () {74 return `mob.closeApp();`;75 }76 codeFor_resetApp () {77 return `mob.resetApp();`;78 }79 codeFor_removeAppFromDevice (varNameIgnore, varIndexIgnore, app) {80 return `mob.removeApp('${app}')`;81 }82 codeFor_getAppStrings (varNameIgnore, varIndexIgnore, language, stringFile) {83 return `let appStrings = mob.driver().getAppStrings(${language ? `${language}, ` : ''}${stringFile ? `"${stringFile}` : ''});`;84 }85 codeFor_getClipboard () {86 return `let clipboardText = mob.driver().getClipboard();`;87 }88 codeFor_setClipboard (varNameIgnore, varIndexIgnore, clipboardText) {89 return `mob.driver().setClipboard('${clipboardText}')`;90 }91 codeFor_pressKeycode (varNameIgnore, varIndexIgnore, keyCode, metaState, flags) {92 return `mob.driver().longPressKeyCode(${keyCode}, ${metaState}, ${flags});`;93 }94 codeFor_longPressKeycode (varNameIgnore, varIndexIgnore, keyCode, metaState, flags) {95 return `mob.driver().longPressKeyCode(${keyCode}, ${metaState}, ${flags});`;96 }97 codeFor_hideDeviceKeyboard () {98 return `mob.driver().hideKeyboard();`;99 }100 codeFor_isKeyboardShown () {101 return `//isKeyboardShown not supported`;102 }103 codeFor_pushFileToDevice (varNameIgnore, varIndexIgnore, pathToInstallTo, fileContentString) {104 return `mob.driver().pushFile('${pathToInstallTo}', '${fileContentString}');`;105 }106 codeFor_pullFile (varNameIgnore, varIndexIgnore, pathToPullFrom) {107 return `let data = mob.driver().pullFile('${pathToPullFrom}');`;108 }109 codeFor_pullFolder (varNameIgnore, varIndexIgnore, folderToPullFrom) {110 return `let data = mob.driver().pullFolder('${folderToPullFrom}');`;111 }112 codeFor_toggleAirplaneMode () {113 return `mob.driver().toggleAirplaneMode();`;114 }115 codeFor_toggleData () {116 return `mob.driver().toggleData();`;117 }118 codeFor_toggleWiFi () {119 return `mob.driver().toggleWiFi();`;120 }121 codeFor_toggleLocationServices () {122 return `mob.driver().toggleLocationServices();`;123 }124 codeFor_sendSMS () {125 return `// Not supported: sendSms;`;126 }127 codeFor_gsmCall () {128 return `// Not supported: gsmCall`;129 }130 codeFor_gsmSignal () {131 return `// Not supported: gsmSignal`;132 }133 codeFor_gsmVoice () {134 return `// Not supported: gsmVoice`;135 }136 codeFor_shake () {137 return `mob.shake();`;138 }139 codeFor_lock (varNameIgnore, varIndexIgnore, seconds) {140 return `mob.driver().lock(${seconds});`;141 }142 codeFor_unlock () {143 return `mob.driver().unlock();`;144 }145 codeFor_isLocked () {146 return `let isLocked = mob.driver().isLocked();`;147 }148 codeFor_rotateDevice (varNameIgnore, varIndexIgnore, x, y, radius, rotation, touchCount, duration) {149 return `mob.driver().rotateDevice(${x}, ${y}, ${radius}, ${rotation}, ${touchCount}, ${duration});`;150 }151 codeFor_getPerformanceData () {152 return `// Not supported: getPerformanceData`;153 }154 codeFor_getSupportedPerformanceDataTypes () {155 return `// Not supported: getSupportedPerformanceDataTypes`;156 }157 codeFor_performTouchId (varNameIgnore, varIndexIgnore, match) {158 return `mob.driver().touchId(${match});`;159 }160 codeFor_toggleTouchIdEnrollment (varNameIgnore, varIndexIgnore, enroll) {161 return `mob.driver().toggleEnrollTouchId(${enroll});`;162 }163 codeFor_openNotifications () {164 return `mob.driver().openNotifications();`;165 }166 codeFor_getDeviceTime () {167 return `let time = mob.getDeviceTime();`;168 }169 codeFor_fingerprint (varNameIgnore, varIndexIgnore, fingerprintId) {170 return `mob.driver().fingerPrint(${fingerprintId});`;171 }172 codeFor_sessionCapabilities () {173 return `let caps = mob.driver().capabilities;`;174 }175 codeFor_setPageLoadTimeout (varNameIgnore, varIndexIgnore, ms) {176 return `mob.driver().setTimeout({'pageLoad': ${ms}});`;177 }178 codeFor_setAsyncScriptTimeout (varNameIgnore, varIndexIgnore, ms) {179 return `mob.driver().setTimeout({'script': ${ms}});`;180 }181 codeFor_setImplicitWaitTimeout (varNameIgnore, varIndexIgnore, ms) {182 return `mob.driver().setTimeout({'implicit': ${ms}});`;183 }184 codeFor_setCommandTimeout () {185 return `// Not supported: setCommandTimeout`;186 }187 codeFor_getOrientation () {188 return `let orientation = mob.driver().getOrientation();`;189 }190 codeFor_setOrientation (varNameIgnore, varIndexIgnore, orientation) {191 return `mob.driver().setOrientation("${orientation}");`;192 }193 codeFor_getGeoLocation () {194 return `let location = mob.driver().getGeoLocation();`;195 }196 codeFor_setGeoLocation (varNameIgnore, varIndexIgnore, latitude, longitude, altitude) {197 return `mob.driver().setGeoLocation({latitude: ${latitude}, longitude: ${longitude}, altitude: ${altitude}});`;198 }199 codeFor_logTypes () {200 return `let logTypes = mob.driver().getLogTypes();`;201 }202 codeFor_log (varNameIgnore, varIndexIgnore, logType) {203 return `let logs = mob.driver().getLogs('${logType}');`;204 }205 codeFor_updateSettings (varNameIgnore, varIndexIgnore, settingsJson) {206 return `mob.driver().updateSettings(${settingsJson});`;207 }208 codeFor_settings () {209 return `let settings = mob.driver().getSettings();`;210 }211}212JsOxygenFramework.readableName = 'JS - Oxygen HQ';...

Full Screen

Full Screen

basic-e2e-specs.js

Source:basic-e2e-specs.js Github

copy

Full Screen

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

Full Screen

Full Screen

driver-e2e-specs.js

Source:driver-e2e-specs.js Github

copy

Full Screen

...55 let caps = _.defaults({56 orientation: initialOrientation57 }, UICATALOG_SIM_CAPS);58 await driver.init(caps);59 let orientation = await driver.getOrientation();60 orientation.should.eql(initialOrientation);61 }62 for (let orientation of ['LANDSCAPE', 'PORTRAIT']) {63 it(`should be able to start in a ${orientation} mode`, async function () {64 this.timeout(MOCHA_TIMEOUT);65 await runOrientationTest(orientation);66 });67 }68 });69 /* jshint ignore:end */70 describe('reset', () => {71 it.skip('default: creates sim and deletes it afterwards', async () => {72 let caps = UICATALOG_SIM_CAPS;73 await killAllSimulators();...

Full Screen

Full Screen

sensor.test.js

Source:sensor.test.js Github

copy

Full Screen

...50 51 await delay(2000);52 await driver.startActivity(app_package,app_package_activity_setting_home )53 // expect(await(await sensorPage.connected).isDisplayed()).equal(true);54 let orientation = await driver.getOrientation();55 expect(orientation).equal('PORTRAIT');56 await delay(2000);57 await driver.setOrientation("LANDSCAPE");58 let orientation_1 = await driver.getOrientation();59 expect(orientation_1).equal('LANDSCAPE');60 await delay(2000);61 await driver.setOrientation("PORTRAIT");62 let a_orientation = await driver.getOrientation();63 expect(a_orientation).equal('PORTRAIT');64 });65 // it('airplane mode', async () => {66 67 // await delay(2000);68 // await driver.openNotifications();69 // await delay(2000);70 // await driver.toggleAirplaneMode(); 71 // await delay(3000);72 // let status_airplane_on = await (await sensorPage.Airplane_).getText()73 // expect(status_airplane_on).equal('On')74 // console.log('turnedon airplane mode')75 // await driver.toggleAirplaneMode();76 // await delay(3000);...

Full Screen

Full Screen

dialog.test.js

Source:dialog.test.js Github

copy

Full Screen

...15 dialog.dialogOkBtn.click()16 })17 it('Verify that the app adjust when orientation is switched', () => {18 driver.setOrientation('LANDSCAPE')19 console.log(driver.getOrientation())20 driver.pause(1000) //ms21 driver.saveScreenshot('./screenshots/landscape.png')22 dialog.appBtn.click()23 driver.setOrientation('PORTRAIT')24 console.log(driver.getOrientation())25 driver.back()26 driver.saveScreenshot('./screenshots/portrait.png')27 })28 it('Verify Timeouts', () => {29 driver.setImplicitTimeout(1000)30 driver.setTimeouts(1000)31 driver.pause(1000)32 })33 it('Verify the repeat alarm options has attribute checked set to true when selected', () => {34 let isChecked, text;35 dialog.appBtn.click()36 dialog.alertDialogBtn.click()37 dialog.repeatAlarmBtn.click()38 console.log(dialog._weekdayCheckbox(0).getText())...

Full Screen

Full Screen

general-tests.js

Source:general-tests.js Github

copy

Full Screen

...34 source.should.contain('<MockNavBar id="nav"');35 });36 // TODO do we want to test driver.pageIndex? probably not37 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/);...

Full Screen

Full Screen

orientation-e2e-specs.js

Source:orientation-e2e-specs.js Github

copy

Full Screen

...16 driver = await initDriver(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 initDriver(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 initDriver(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 initDriver(Object.assign({}, APIDEMOS_CAPS, {39 appActivity: '.view.TextFields'40 }));41 });42 after(async function () {43 await driver.quit();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

sample.test.js

Source:sample.test.js Github

copy

Full Screen

...13 await dialog.passwordEntry("Actual Password");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

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.findElement(By.name('q')).sendKeys('webdriver');7driver.findElement(By.name('btnK')).click();8driver.wait(until.titleIs('webdriver - Google Search'), 1000);9driver.quit();10driver.getOrientation().then(function(orientation) {11 console.log(orientation);12});13driver.getOrientation().then(function(orientation) {14 console.log(orientation);15});16driver.setOrientation('LANDSCAPE').then(function() {17 driver.getOrientation().then(function(orientation) {18 console.log(orientation);19 });20});21driver.setOrientation('PORTRAIT').then(function() {22 driver.getOrientation().then(function(orientation) {23 console.log(orientation);24 });25});26driver.setOrientation('LANDSCAPE').then(function() {27 driver.getOrientation().then(function(orientation) {28 console.log(orientation);29 });30});31driver.setOrientation('PORTRAIT').then(function() {32 driver.getOrientation().then(function(orientation) {33 console.log(orientation);34 });35});36driver.quit();

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.findElement(By.name('q')).sendKeys('webdriver');7driver.findElement(By.name('btnK')).click();8driver.wait(until.titleIs('webdriver - Google Search'), 1000);9driver.quit();10driver.getOrientation().then(function(orientation) {11});12driver.setOrientation('LANDSCAPE').then(function() {13 console.log('orientation set to LANDSCAPE');14});15driver.setOrientation('PORTRAIT').then(function() {16 console.log('orientation set to PORTRAIT');17});18driver.setOrientation('LANDSCAPE').then(function() {19 console.log('orientation set to LANDSCAPE');20});21driver.setOrientation('PORTRAIT').then(function() {22 console.log('orientation set to PORTRAIT');23});24driver.getOrientation().then(function(orientation) {25});26driver.quit();27getOrientation()28setOrientation(orientation)

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.manage().window().maximize();7driver.manage().window().setSize(400, 600);8driver.getOrientation().then(function(orientation) {9 console.log(orientation);10});11driver.quit();

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('selenium-webdriver');2var driver = new webdriver.Builder().withCapabilities(webdriver.Capabilities.android()).build();3driver.getOrientation().then(function(orientation) {4 console.log(orientation);5});6var webdriver = require('selenium-webdriver');7var driver = new webdriver.Builder().withCapabilities(webdriver.Capabilities.android()).build();8driver.setOrientation('LANDSCAPE').then(function() {9 console.log('Orientation set to LANDSCAPE');10});11var webdriver = require('selenium-webdriver');12var driver = new webdriver.Builder().withCapabilities(webdriver.Capabilities.android()).build();13driver.getGeoLocation().then(function(geoLocation) {14 console.log(geoLocation);15});16var webdriver = require('selenium-webdriver');17var driver = new webdriver.Builder().withCapabilities(webdriver.Capabilities.android()).build();18driver.setGeoLocation({latitude: 37.422, longitude: -122.084}).then(function() {19 console.log('Geo location set to 37.422, -122.084');20});21var webdriver = require('selenium-webdriver');22var driver = new webdriver.Builder().withCapabilities(webdriver.Capabilities.android()).build();23driver.getNetworkConnection().then(function(networkConnection) {24 console.log(networkConnection);25});26var webdriver = require('selenium-webdriver');27var driver = new webdriver.Builder().withCapabilities(webdriver.Capabilities.android()).build();28driver.setNetworkConnection(6).then(function() {29 console.log('Network connection set to 6');30});31var webdriver = require('selenium-webdriver');32var driver = new webdriver.Builder().withCapabilities(webdriver.Capabilities.android()).build();33driver.setNetworkConnection(6).then(function() {34 console.log('Network connection set to 6');35});36var webdriver = require('selenium-webdriver');37var driver = new webdriver.Builder().withCapabilities(webdriver.Capabilities.android()).build();38driver.getNetworkConnection().then(function(networkConnection) {39 console.log(networkConnection);40});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require("wd");2var driver = wd.remote();3driver.init({browserName:'safari'}, function() {4 driver.getOrientation(function(err, orientation) {5 console.log("Orientation is: " + orientation);6 });7});8driver.quit();9driver.setOrientation(orientation, callback)10var wd = require("wd");11var driver = wd.remote();12driver.init({browserName:'safari'}, function() {13 driver.setOrientation('LANDSCAPE', function(err) {14 if (err) {15 console.log("Error setting orientation: " + err);16 } else {17 console.log("Orientation set successfully");18 }19 });20});21driver.quit();22driver.getGeoLocation(callback)23driver.setGeoLocation(latitude, longitude, altitude, callback)24driver.getNetworkConnection(callback)25driver.setNetworkConnection(type, callback)26driver.getPerformanceData(packageName, dataType, dataReadTimeout, callback)

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var assert = require('assert');3var desiredCaps = {4};5var driver = wd.promiseChainRemote('localhost', 4723);6 .init(desiredCaps)7 .getOrientation()8 .then(function(orientation) {9 console.log('orientation is: ' + orientation);10 })11 .fin(function() {12 return driver.quit();13 })14 .done();15driver.getOrientation()16driver.setOrientation()17driver.rotate()18driver.hideKeyboard()19driver.getGeoLocation()20driver.setGeoLocation()21driver.getNetworkConnection()22driver.setNetworkConnection()23driver.touchAction()24driver.touchActions()25driver.performMultiAction()26driver.performTouchId()27driver.toggleTouchIdEnrollment()28driver.toggleAirplaneMode()29driver.toggleData()30driver.toggleWiFi()31driver.toggleLocationServices()32driver.toggleBluetooth()33driver.toggleWifi()34driver.pushFile()35driver.pullFile()36driver.pullFolder()37driver.lock()38driver.unlock()39driver.isLocked()

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