How to use driver.startActivity method in Appium Android Driver

Best JavaScript code snippet using appium-android-driver

touch-e2e-specs.js

Source:touch-e2e-specs.js Github

copy

Full Screen

...20 after(async function () {21 await deleteSession();22 });23 async function startListActivity () {24 await driver.startActivity({25 appActivity: '.view.List5',26 appPackage: 'io.appium.android.apis',27 });28 }29 async function startFingerPaintActivity () {30 await driver.startActivity({31 appActivity: '.graphics.FingerPaint',32 appPackage: 'io.appium.android.apis',33 });34 }35 async function startSplitTouchActivity () {36 await driver.startActivity({37 appActivity: '.view.SplitTouchView',38 appPackage: 'io.appium.android.apis',39 });40 }41 async function startDragAndDropActivity () {42 await driver.startActivity({43 appActivity: '.view.DragAndDropDemo',44 appPackage: 'io.appium.android.apis',45 });46 }47 async function startTextSwitcherActivity () {48 await driver.startActivity({49 appActivity: '.view.TextSwitcher1',50 appPackage: 'io.appium.android.apis',51 });52 }53 async function getScrollData () {54 const els = await driver.elementsByClassName('android.widget.TextView');55 // the last element is the title of the view, and often the56 // second-to-last is actually off the screen57 const startEl = els[els.length - 3];58 const {x: startX, y: startY} = await startEl.getLocation();59 const endEl = _.first(els);60 const {x: endX, y: endY} = await endEl.getLocation();61 return {startX, startY, endX, endY, startEl, endEl};62 }...

Full Screen

Full Screen

keyboard-e2e-specs.js

Source:keyboard-e2e-specs.js Github

copy

Full Screen

...140 const opts = {141 appPackage: defaultAsciiCaps.appPackage,142 appActivity: defaultAsciiCaps.appActivity,143 };144 await driver.startActivity(opts);145 try {146 const okBtn = await driver.elementById('android:id/button1');147 console.log('\n\nFound alert. Trying to dismiss'); // eslint-disable-line148 await okBtn.click();149 await ensureUnlocked(driver);150 await driver.startActivity(opts);151 } catch (ign) {}152 });153 after(async function () {154 await deleteSession();155 });156 beforeEach(async function () {157 await ensureUnlocked(driver);158 });159 describe('editing a text field', function () {160 let els;161 beforeEach(async function () {162 const opts = {163 appPackage: defaultAsciiCaps.appPackage,164 appActivity: defaultAsciiCaps.appActivity,165 };166 await driver.startActivity(opts);167 els = await retryInterval(10, 1000, async function () {168 const els = await driver.elementsByClassName(EDITTEXT_CLASS);169 els.should.have.length.at.least(1);170 return els;171 });172 });173 for (let test of tests) {174 describe(test.label, function () {175 it('should work with setValue', async function () {176 await runTextEditTest(driver, test.text);177 });178 it('should work with keys', async function () {179 await runTextEditTest(driver, test.text, true);180 });181 });182 }183 it('should be able to clear a password field', async function () {184 // this test is flakey185 this.retries(4);186 // there is currently no way to directly assert anything about the contents187 // of a password field, since there is no way to access the contents188 const password = 'super-duper password';189 let passwordTextField = els[1];190 let passwordOutput = await driver.elementById('io.appium.android.apis:id/edit1Text');191 await passwordTextField.sendKeys(password);192 await waitForText(passwordOutput, password);193 await passwordTextField.clear();194 await waitForText(passwordOutput, '');195 });196 it('should be able to type in length-limited field', async function () {197 let charactersToType = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';198 if (!process.env.TESTOBJECT_E2E_TESTS) {199 let adb = new ADB();200 let apiLevel = parseInt(await adb.getApiLevel(), 10);201 if (apiLevel < 24 || (process.env.CI && apiLevel < 28)) {202 // below Android 7.0 (API level 24) typing too many characters in a203 // length-limited field will either throw a NullPointerException or204 // crash the app205 // also can be flakey in CI for SDK < 28206 return this.skip();207 }208 }209 let el = els[3];210 await el.setImmediateValue(charactersToType);211 // expect first 11 characters (limit of the field) to be in the field212 let text = await el.text();213 text.should.eql('0123456789a');214 });215 });216 describe('sending a key event', function () {217 before(async function () {218 await driver.startActivity({appPackage: PACKAGE, appActivity: KEYEVENT_ACTIVITY});219 await B.delay(500);220 });221 it('should be able to send combination keyevents', async function () {222 await runCombinationKeyEventTest(driver);223 });224 it('should be able to send keyevents', async function () {225 await runKeyEventTest(driver);226 });227 });228 });229 describe('unicode', function () {230 let adb;231 if (!process.env.TESTOBJECT_E2E_TESTS) {232 adb = new ADB();233 }234 let initialIME;235 let driver;236 before(async function () {237 // save the initial ime so we can make sure it is restored238 if (adb) {239 initialIME = await adb.defaultIME();240 initialIME.should.not.eql('io.appium.settings/.UnicodeIME');241 }242 driver = await initSession(defaultUnicodeCaps);243 });244 after(async function () {245 await deleteSession();246 // make sure the IME has been restored247 if (adb) {248 let ime = await adb.defaultIME();249 ime.should.eql(initialIME);250 ime.should.not.eql('io.appium.settings/.UnicodeIME');251 }252 });253 beforeEach(async function () {254 await ensureUnlocked(driver);255 });256 describe('editing a text field', function () {257 beforeEach(async function () {258 await driver.startActivity({259 appPackage: defaultUnicodeCaps.appPackage,260 appActivity: defaultUnicodeCaps.appActivity,261 });262 });263 for (let testSet of [tests, unicodeTests, languageTests]) {264 for (let test of testSet) {265 describe(test.label, function () {266 it('should work with setValue', async function () {267 await runTextEditTest(driver, test.text);268 });269 it('should work with keys', async function () {270 await runTextEditTest(driver, test.text, true);271 });272 });273 }274 }275 });276 describe('sending a key event', function () {277 before(async function () {278 await driver.startActivity({appPackage: PACKAGE, appActivity: KEYEVENT_ACTIVITY});279 });280 it('should be able to send combination keyevents', async function () {281 await runCombinationKeyEventTest(driver);282 });283 it('should be able to send keyevents', async function () {284 await runKeyEventTest(driver);285 });286 });287 });...

Full Screen

Full Screen

by-uiautomator-e2e-specs.js

Source:by-uiautomator-e2e-specs.js Github

copy

Full Screen

...99 let selector = 'new UiSelector().className("not.a.class"); new UiSelector().className("android.widget.TextView")';100 await driver.elementByAndroidUIAutomator(selector).should.eventually.exist;101 });102 it('should scroll to, and return elements using UiScrollable', async function () {103 await driver.startActivity({appPackage: 'io.appium.android.apis', appActivity: '.view.List1'});104 let selector = 'new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().text("Beer Cheese").instance(0))';105 let el = await driver.elementByAndroidUIAutomator(selector);106 await el.text().should.eventually.equal('Beer Cheese');107 });108 it('should allow chaining UiScrollable methods', async function () {109 await driver.startActivity({appPackage: 'io.appium.android.apis', appActivity: '.view.List1'});110 let selector = 'new UiScrollable(new UiSelector().scrollable(true).instance(0)).setMaxSearchSwipes(11).scrollIntoView(new UiSelector().text("Beer Cheese").instance(0))';111 let el = await driver.elementByAndroidUIAutomator(selector);112 await el.text().should.eventually.equal('Beer Cheese');113 });114 it('should allow UiScrollable scrollIntoView', async function () {115 await driver.startActivity({appPackage: 'io.appium.android.apis', appActivity: '.view.List1'});116 let selector = 'new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().text("Beer Cheese").instance(0));';117 let el = await driver.elementByAndroidUIAutomator(selector);118 await el.text().should.eventually.equal('Beer Cheese');119 });120 it('should allow UiScrollable with unicode string', async function () {121 await driver.startActivity({appPackage: 'io.appium.android.apis', appActivity: '.text.Unicode'});122 let selector = 'new UiSelector().text("عربي").instance(0);';123 let el = await driver.elementByAndroidUIAutomator(selector);124 await el.text().should.eventually.equal('عربي');125 });...

Full Screen

Full Screen

general-e2e-specs.js

Source:general-e2e-specs.js Github

copy

Full Screen

...19 appPackage.should.equal('io.appium.android.apis');20 appActivity.should.equal('.ApiDemos');21 let startAppPackage = 'io.appium.android.apis';22 let startAppActivity = '.view.SplitTouchView';23 await driver.startActivity({appPackage: startAppPackage, appActivity: startAppActivity});24 let newAppPackage = await driver.getCurrentPackage();25 let newAppActivity = await driver.getCurrentActivity();26 newAppPackage.should.equal(startAppPackage);27 newAppActivity.should.equal(startAppActivity);28 });29 it('should be able to launch activity with custom intent parameter category', async function () {30 let startAppPackage = 'io.appium.android.apis';31 let startAppActivity = 'io.appium.android.apis.app.HelloWorld';32 let startIntentCategory = 'appium.android.intent.category.SAMPLE_CODE';33 await driver.startActivity({appPackage: startAppPackage, appActivity: startAppActivity, intentCategory: startIntentCategory});34 let appActivity = await driver.getCurrentActivity();35 appActivity.should.include('HelloWorld');36 });37 it('should be able to launch activity with dontStopAppOnReset = true', async function () {38 let startAppPackage = 'io.appium.android.apis';39 let startAppActivity = '.os.MorseCode';40 await driver.startActivity({appPackage: startAppPackage, appActivity: startAppActivity});41 let appPackage = await driver.getCurrentPackage();42 let appActivity = await driver.getCurrentActivity();43 appPackage.should.equal(startAppPackage);44 appActivity.should.equal(startAppActivity);45 });46 it('should be able to launch activity with dontStopAppOnReset = false', async function () {47 let startAppPackage = 'io.appium.android.apis';48 let startAppActivity = '.os.MorseCode';49 await driver.startActivity({appPackage: startAppPackage, appActivity: startAppActivity});50 let appPackage = await driver.getCurrentPackage();51 let appActivity = await driver.getCurrentActivity();52 appPackage.should.equal(startAppPackage);53 appActivity.should.equal(startAppActivity);54 });55 });...

Full Screen

Full Screen

android-native.spec.js

Source:android-native.spec.js Github

copy

Full Screen

1describe('Adndroid Native Feature tests', ()=>{2 it('Access an Activity directly', async () =>{3 await driver.startActivity('io.appium.android.apis','io.appium.android.apis.app.AlertDialogSamples');4 await driver.pause(3000);5 await expect($('//*[@text="App/Alert Dialogs"]')).toExist();6 });7 it('Working with dialogs boxes', async () =>{8 await driver.startActivity('io.appium.android.apis','io.appium.android.apis.app.AlertDialogSamples');9 await $('//*[@resource-id="io.appium.android.apis:id/two_buttons"]').click();10 //await driver.acceptAlert();11 // await driver.dismissAlert();12 console.log('TEXT ALERT-> ',await driver.getAlertText());13 await $('//*[@resource-id="android:id/button1"]').click();14 await expect($('//*[@resource-id="android:id/alertTitle"]')).not.toExist();15 });16 it('Working with vertical scroll', async () =>{17 await $('~App').click();18 await $('~Activity').click();19 //await $('android=new UiScrollable(new UiSelector().scrollable(true)).scrollToEnd(1,5)');20 await $('android=new UiScrollable(new UiSelector().scrollable(true)).scrollTextIntoView("Secure Surfaces")').click();21 // await $('~Secure Surfaces').click();22 await expect($('~Secure Dialog')).toExist();23 });24 it('Working with horizontal scroll', async () =>{25 await driver.startActivity('io.appium.android.apis','io.appium.android.apis.view.Gallery1');26 await $('android=new UiScrollable(new UiSelector().scrollable(true)).setAsHorizontalList().scrollForward()');27 await $('android=new UiScrollable(new UiSelector().scrollable(true)).setAsHorizontalList().scrollBackward()');28 await driver.pause(3000);29 });30 it.only('Scroll exercise', async () =>{31 await driver.startActivity('io.appium.android.apis','io.appium.android.apis.view.DateWidgets1');32 const date= await $('//*[@resource-id="io.appium.android.apis:id/dateDisplay"]');33 const currentDate = await date.getText();34 await $('~change the date').click();35 await $('android=new UiScrollable(new UiSelector().scrollable(true)).setAsHorizontalList().scrollForward()');36 await $('//*[@text="10"]').click();37 await $('//*[@resource-id="android:id/button1"]').click();38 await expect(date.getText()).not.toEqual(currentDate);39 await driver.pause(3000);40 });...

Full Screen

Full Screen

android_TestActivity.js

Source:android_TestActivity.js Github

copy

Full Screen

1const { NoDriverProxyCommandError } = require("appium/build/lib/appium");2const { driverConfig } = require("appium/build/lib/cli/args");3describe('Android Activity Test', ()=>{4 it('Alert and Access an activity directly ', async ()=> {5 await driver.startActivity("io.appium.android.apis","io.appium.android.apis.app.AlertDialogSamples")6 await driver.pause(3000);7 expect($('//*[@text="app.AlertDialogSamples"]')).toExist();8 await $('//*[@resource-id="io.appium.android.apis:id/two_buttons"]').click();9 driver.acceptAlert();10 //driver.dismiss();11 //driver.getAlertText();12 expect($('//*[@resource-id="android:id/button1"]')).not.toExist();13 14 15 16 17 });18 it('Vertical Scrolling ', async ()=> {19 await $('~App').click();20 await $('~Activity').click();21 //more stable if you use scrollTextintoView22 await $('android=new UiScrollable(new UiSelector().scrollable(true)).scrollTextIntoView("Secure Surfaces")');23 //If does not work use ScrollToEnd for the element present in the bottom of the page.24 //await $('android=new UiScrollable(new UiSelector().scrollable(true)).scrollToEnd(1,5)'); 25 //await $('~Secure Surfaces').click();26 await expect($('~Secure Dialog')).toExist();27 28 29 30 });31 it('Horizonatal Scrolling ', async ()=> {32 await driver.startActivity("io.appium.android.apis","io.appium.android.apis.view.Gallery1")33 await $('android=new UiScrollable(new UiSelector().scrollable(true)).setAsHorizontalList().scrollForward()'); 34 await driver.pause(3000);35});36it.only('Date Picker ', async ()=> {37 38 await $('~Views').click();39 await $('~Date Widgets').click();40 await $('~1. Dialog').click();41 const currentDate = await($('//android.widget.TextView[@resource-id="io.appium.android.apis:id/dateDisplay"]')).getText(); 42 await $('~change the date').click();43 await $('android=new UiScrollable(new UiSelector().scrollable(true)).setAsHorizontalList().scrollForward()'); 44 await $('//*[@text="10"]').click();45 await $('//*[@resource-id="android:id/button1"]').click();46 const updatedDate = await($('//android.widget.TextView[@resource-id="io.appium.android.apis:id/dateDisplay"]')).getText(); ...

Full Screen

Full Screen

android-native.js

Source:android-native.js Github

copy

Full Screen

1const { driverConfig } = require("appium/build/lib/cli/args")2describe('Android Native Feature Tests', () => {3 it('Access and Activity directly', async () => {4 //access activity5 await driver.startActivity("io.appium.android.apis", "io.appium.android.apis.app.AlertDialogSamples")6 //pause7 await driver.pause(3000);8 //assertion9 await expect($('//*[@text="App/Alert Dialogs"]')).toExist();10 })11 it('Working with Dialog Boxes', async () => {12 //access activity13 await driver.startActivity("io.appium.android.apis", "io.appium.android.apis.app.AlertDialogSamples")14 //click on first dialog15 await $('//*[@resource-id="io.appium.android.apis:id/two_buttons"]').click();16 //accept alert17 //await driver.acceptAlert();18 //dismiss alert19 //await driver.dismissAlert();20 //click on the OK button21 //await $('//*[@resource-id="android:id/button1"]').click();22 //assertion - alert box is no longer visible23 await expect($('//*[@resource-id="android:id/alertTitle"]')).not.toExist();24 })25 it('Vertical scrolling', async () => {26 await $('~App').click();27 await $('~Activity').click();28 //scroll to the end (not stable if element gets moved)29 await $('android=new UiScrollable(new UiSelector().scrollable(true)).scrollToEnd(1,5)');30 //scrollTextIntoView - more stable31 //await $('android=new UiScrollable(new UiSelector().scrollable(true)).scrollTextIntoView("Secure Surfaces")').click();32 //assertion33 await expect($('~Secure Dialog')).toExist();34 })35 it('Horizontal scrolling', async () => {36 await driver.startActivity(37 "io.appium.android.apis",38 "io.appium.android.apis.view.Gallery1"39 );40 //Horizontal scrolling - forward41 await $('android=new UiScrollable(new UiSelector().scrollable(true)).setAsHorizontalList().scrollForward()');42 43 //backward44 await $('android=new UiScrollable(new UiSelector().scrollable(true)).setAsHorizontalList().scrollBackward()');45 await driver.pause(3000);46 })...

Full Screen

Full Screen

deeplink.js

Source:deeplink.js Github

copy

Full Screen

...6 const chromePackage = "com.android.chrome";7 const chromeActivity = "com.google.android.apps.chrome.Main";8 const paypalUrl = "https://paypal.github.io/react-paypal-js/iframe.html?id=example-venmobutton--horizontal&viewMode=story";9 // Launch Chrome app, switch to its context, and load PayPal URL10 driver.startActivity(chromePackage, chromeActivity);11 driver.waitUntil(12 () => driver.getContexts().length > 113 )14 driver.switchContext('WEBVIEW_chrome');15 driver.url(paypalUrl);16 // Switch to iframe17 const frame = $('/html/body/div[3]/div/div/iframe[1]');18 frame.waitForExist({timeout: 5000, timeoutMsg: 'expected iframe to appear'});19 browser.switchToFrame(frame);20 // Click button within iframe21 const payPalButton = $('/html/body/div[1]/div/div[1]/div');22 payPalButton.click();23 24 var venmoText = $('android=new UiSelector().text("Venmo").className("android.widget.TextView")');25 // Perform the rest of your test in the native app26 driver.pause(3000);27 driver.startActivity(appPackage, appActivity);28 expectChai(driver.getCurrentActivity()).to.equal(appActivity);29 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('webdriverio');2var options = {3 desiredCapabilities: {4 }5};6 .remote(options)7 .init()8 .then(function () {9 return this.startActivity({10 });11 })12 .then(function () {13 return this.quit();14 })15 .catch(function (err) {16 console.log(err);17 });

Full Screen

Using AI Code Generation

copy

Full Screen

1driver.startActivity("com.android.calculator2","com.android.calculator2.Calculator");2System.out.println(driver.currentActivity());3System.out.println(driver.currentPackage());4System.out.println(driver.isLocked());5driver.lockDevice();6driver.unlockDevice();7driver.hideKeyboard();8System.out.println(driver.isKeyboardShown());9driver.pressKeyCode(3);10driver.longPressKeyCode(3);11driver.pushFile("/storage/emulated/0/Download/test.txt", "Hello World");12System.out.println(driver.pullFile("/storage/emulated/0/Download/test.txt"));13System.out.println(driver.pullFolder("/storage/emulated/0/Download/"));14driver.toggleAirplaneMode();15driver.toggleData();16driver.toggleWiFi();17driver.toggleLocationServices();18driver.openNotifications();19System.out.println(driver.getDeviceTime());20driver.installApp("C:\\Users\\Sagar\\Desktop\\Appium\\ApiDemos-debug.apk");21driver.removeApp("io.appium.android.apis");22System.out.println(driver.isAppInstalled("io

Full Screen

Using AI Code Generation

copy

Full Screen

1const wd = require("wd");2const driver = wd.promiseChainRemote({3});4driver.init({5})6 .then(() => {7 return driver.startActivity({8 });9 })10 .then(() => {11 return driver.source();12 })13 .then((source) => {14 console.log(source);15 })16 .catch((err) => {17 console.log(err);18 });

Full Screen

Using AI Code Generation

copy

Full Screen

1var desiredCaps = {2};3var driver = wd.promiseChainRemote("localhost", 4723);4driver.init(desiredCaps).then(function() {5 return driver.startActivity("com.example.myapp", "com.example.myapp.SecondActivity");6}).then(function() {7});8DesiredCapabilities capabilities = new DesiredCapabilities();9capabilities.setCapability("app", "com.example.myapp");10capabilities.setCapability("platformName", "Android");11capabilities.setCapability("platformVersion", "4.4.2");12capabilities.setCapability("deviceName", "Android Emulator");13capabilities.setCapability("appPackage", "com.example.myapp");14capabilities.setCapability("appActivity", "com.example.myapp.MainActivity");

Full Screen

Using AI Code Generation

copy

Full Screen

1driver.startActivity({appPackage: 'com.abc.xyz', appActivity: 'com.abc.xyz.MainActivity'});2driver.startActivity('com.abc.xyz', 'com.abc.xyz.MainActivity');3driver.startActivity('com.abc.xyz', 'com.abc.xyz.MainActivity', 'intent arguments');4driver.startActivity('com.abc.xyz', 'com.abc.xyz.MainActivity', 'intent arguments', 'intent flags');5driver.startActivity('com.abc.xyz', 'com.abc.xyz.MainActivity', 'intent arguments', 'intent flags', 'optional intent uri');6driver.startActivity('com.abc.xyz', 'com.abc.xyz.MainActivity', 'intent arguments', 'intent flags', 'optional intent uri', 'optional intent data');7driver.startActivity('com.abc.xyz', 'com.abc.xyz.MainActivity', 'intent arguments', 'intent flags', 'optional intent uri', 'optional intent data', 'optional intent category');8driver.startActivity('com.abc.xyz', 'com.abc.xyz.MainActivity', 'intent arguments', 'intent flags', 'optional intent uri', 'optional intent data', 'optional intent category', 'optional intent mime type');9driver.startActivity('com.abc.xyz', 'com.abc.xyz.MainActivity', 'intent arguments', 'intent flags', 'optional intent uri', 'optional intent data', 'optional intent category', 'optional intent mime type', 'optional intent package');10driver.startActivity('com.abc.xyz', 'com.abc.xyz.MainActivity', 'intent arguments', 'intent flags', 'optional intent uri', 'optional intent data', 'optional intent category', 'optional intent mime type', 'optional intent package', 'optional activity options');11driver.startActivity('com.abc.xyz', 'com.abc.xyz.MainActivity', 'intent arguments', 'intent flags', 'optional intent uri', 'optional intent data', 'optional intent category', 'optional intent mime type', 'optional intent package', 'optional activity options', 'optional wait package');12driver.startActivity('com.abc.xyz', 'com.abc.xyz.MainActivity', 'intent arguments', 'intent flags', 'optional intent uri', 'optional intent data', 'optional intent category', 'optional intent mime type', 'optional intent package', 'optional activity options', 'optional wait package', 'optional wait activity');13driver.startActivity('com.abc.xyz', 'com.abc.xyz.MainActivity', 'intent arguments', 'intent flags', 'optional intent uri', 'optional

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);6driver.init(desiredCaps).then(function () {7 return driver.startActivity({8 });9}).then(function () {10 return driver.elementById('com.sec.android.app.camera:id/shutter_button').click();11}).then(function () {12 console.log('Test Passed');13}).fin(function () {14 return driver.quit();15}).done();

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 Android Driver 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