Best JavaScript code snippet using appium-android-driver
basic-e2e-specs.js
Source:basic-e2e-specs.js
...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/);...
general-tests.js
Source:general-tests.js
...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 () {...
application.js
Source:application.js
...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});
orientation-e2e-specs.js
Source:orientation-e2e-specs.js
...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 });...
dialog.test.js
Source:dialog.test.js
...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 })...
sample.test.js
Source:sample.test.js
...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 });...
orientation-specs.js
Source:orientation-specs.js
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 });...
Using AI Code Generation
1var webdriverio = require('webdriverio');2var options = {3 desiredCapabilities: {4 }5};6var client = webdriverio.remote(options);7 .init()8 .setOrientation('LANDSCAPE')9 .end();
Using AI Code Generation
1var webdriver = require('selenium-webdriver');2var _ = require('lodash');3var driver = new webdriver.Builder()4 .withCapabilities({5 })6 .build();7driver.setOrientation('LANDSCAPE');8driver.quit();9var webdriver = require('selenium-webdriver');10var _ = require('lodash');11var driver = new webdriver.Builder()12 .withCapabilities({13 })14 .build();15driver.getOrientation(function(err, orientation){16 console.log(orientation);17});18driver.quit();19var webdriver = require('selenium-webdriver');20var _ = require('lodash');21var driver = new webdriver.Builder()22 .withCapabilities({23 })24 .build();25driver.isLocked(function(err, locked){26 console.log(locked);27});28driver.quit();29var webdriver = require('selenium-webdriver');30var _ = require('lodash');31var driver = new webdriver.Builder()32 .withCapabilities({
Using AI Code Generation
1driver.setOrientation("LANDSCAPE");2driver.getOrientation();3driver.rotate("LANDSCAPE");4driver.isLocked();5driver.lock();6driver.unlock();7driver.isAppInstalled("com.example.app");8driver.installApp("path/to/app.apk");9driver.removeApp("com.example.app");10driver.launchApp();11driver.closeApp();12driver.resetApp();13driver.backgroundApp(5);14driver.startActivity("com.example.app", ".ExampleActivity");15driver.currentActivity();16driver.currentPackage();17driver.pushFile("/data/local/tmp/remote.txt", "Hello World!");18driver.pullFile("/data/local/tmp/remote.txt");
Using AI Code Generation
1var wd = require("wd");2var assert = require("assert");3var desired = {4};5var driver = wd.remote("localhost", 4723);6driver.init(desired, function() {7 driver.setOrientation("LANDSCAPE", function(err) {8 driver.setOrientation("PORTRAIT", function(err) {9 driver.quit();10 });11 });12});13desired_caps = {14 caps: {15 },16 appium_lib: {17 }18}19 @driver = Appium::Driver.new(desired_caps).start_driver20from appium import webdriver21desired_caps = {}
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!