How to use driver.getCurrentPackage method in Appium Android Driver

Best JavaScript code snippet using appium-android-driver

commonConditions.js

Source: commonConditions.js Github

copy

Full Screen

...46 }47 if (profile.accountClosed) {48 await patchAccountStatus(personId, false)49 }50 const appBundleId = await driver.getCurrentPackage() /​/​ Esto saca el valor de appbundleId51 const { deviceId, magicLinkBaseUrl } = World52 const actionToken = await browser.call(async() => await linkAccountToken(email, deviceId, appBundleId))53 await browser.url(`${magicLinkBaseUrl}/​link-account?token=${actionToken}`)54})55Given('get login token with user email {string}', { timeout: 130000 }, async email => {56 const persons = await getPersonByEmail(email)57 const person = await find(persons, { type: 'CUSTOMER' })58 const { id: personId, maritalStatus, profile } = person59 World.personId = personId60 World.email = email61 await unlockAllRestrictions(personId)62 await setKeycloakUserState(personId, true)63 await logOutAllSessions(personId) /​/​uncomment this block and run with VPN to unlock user from keylock64 /​/​browser.call(() => unlinkAllDevices(personId))65 if (driver.isAndroid === true) {66 const appBundleId = await driver.getCurrentPackage() /​/​ Esto saca el valor de appbundleId67 const { deviceId, magicLinkBaseUrl } = World68 const actionToken = await linkAccountToken(email, deviceId, appBundleId)69 World.actionToken = actionToken70 await browser.url(`${magicLinkBaseUrl}/​link-account?token=${actionToken}`)71 } else {72 const appBundleId = 'ar.com.bdsol.bds.squads.multicolor' /​/​ Esto saca el valor de appbundleId73 const { deviceId, magicLinkBaseUrl } = World74 const actionToken = await linkAccountToken(email, deviceId, appBundleId)75 World.actionToken = actionToken76 /​/​driver.execute('mobile: launchApp', {bundleId: 'com.apple.mobilesafari'});77 await driver.execute('mobile: launchApp', { bundleId: 'com.google.chrome.ios' })78 const newTab = await $('~New Tab')79 const nuevoTab = await $('~Crear nueva pestaña.')80 const backButton = await $('/​/​*[@name="Volver" or @name="Back"]')81 const urlButton2 = await $('/​/​*[@name="Busca o escribe una URL" or @name="Search or type URL"]')82 for (let i = 0; i < 2; i++) {83 try {84 if (await newTab.isDisplayed()) {85 await newTab.click()86 break;87 } else if (await nuevoTab.isDisplayed()){88 await nuevoTab.click()89 break;90 } else if (await backButton.isEnabled()){91 await backButton.click()92 } else if (await urlButton2.isDisplayed()){93 break;94 } else {95 await browser.pause(2000) 96 }97 } catch(error){98 console.log('No se pudo ejecutar el magiclink en chrome')99 }100 } 101 const urlButton = await $('/​/​*[@name="Busca o escribe una URL" or @name="Search or type URL"]')102 const address = await $('~Address')103 104 for (let i = 0; i < 2; i++) {105 try {106 if (await urlButton.isDisplayed() || await urlButton.isEnabled()) {107 await urlButton.click() 108 await urlButton.setValue(`${magicLinkBaseUrl}/​link-account?token=${actionToken}\uE007`) 109 break;110 } else if (await address.isDisplayed()){111 await address.click() 112 await address.setValue(`${magicLinkBaseUrl}/​link-account?token=${actionToken}\uE007`) 113 break;114 }115 } catch(error){116 throw new Error(117 ' No se pudo ejecutar el magiclink en chrome'118 );119 }120 } 121 const openBds = await $('~Abrir Banco del Sol')122 await openBds.click()123 const openSelector =124 "type == 'XCUIElementTypeButton' && name CONTAINS 'Abrir' || type == 'XCUIElementTypeButton' && name CONTAINS 'Open'"125 const openButton = await $(`-ios predicate string:${openSelector}`)126 if (await openButton.isDisplayed()) {127 await openButton.click()128 }129 }130})131Given('user {string} already has {int} devices linked', async (email, amountOfDevices) => {132 const persons = await browser.call(async() =>await getPersonByEmail(email))133 const person = await find(persons, { type: 'CUSTOMER' })134 const appBundleId = await driver.getCurrentPackage() 135 for (let i = 0; i < amountOfDevices; i++) {136 await browser.call(async() => await logOutAllSessions(person.id))137 await browser.call(async() => await linkAccount(email, uuid(), '192837', `modelo ${i}`, `nombre ${i}`, appBundleId))138 }139})140Given('there is no user registered with DNI {string}', async dni => {141 const persons = await browser.call(async() => await getPersonByDni(dni))142 if (persons.length > 0) {143 persons.forEach(async person => await browser.call(async() => await deletePersonById(person.id)))144 }145})146Given('there is no user registered with mail {string}', async mail => {147 const persons = await browser.call(async() => await getPersonByEmail(mail))148 if (persons.length > 0) {...

Full Screen

Full Screen

driver-e2e-specs.js

Source: driver-e2e-specs.js Github

copy

Full Screen

...31 driver = null;32 });33 it('should start android session focusing on default pkg and act', async function () {34 driver = await initSession(APIDEMOS_CAPS);35 await driver.getCurrentPackage().should.eventually.equal(APIDEMOS_PACKAGE);36 await driver.getCurrentActivity().should.eventually.equal(APIDEMOS_MAIN_ACTIVITY);37 });38 it('should start android session focusing on custom pkg and act', async function () {39 const caps = amendCapabilities(APIDEMOS_CAPS, {40 'appium:appPackage': APIDEMOS_PACKAGE,41 'appium:appActivity': APIDEMOS_SPLIT_TOUCH_ACTIVITY,42 });43 driver = await initSession(caps);44 await driver.getCurrentPackage().should.eventually.equal(APIDEMOS_PACKAGE);45 await driver.getCurrentActivity().should.eventually.equal(APIDEMOS_SPLIT_TOUCH_ACTIVITY);46 });47 it('should error out for not apk extension', async function () {48 const caps = amendCapabilities(APIDEMOS_CAPS, {49 'appium:app': 'foo',50 'appium:appPackage': APIDEMOS_PACKAGE,51 'appium:appActivity': APIDEMOS_SPLIT_TOUCH_ACTIVITY,52 });53 await initSession(caps).should.eventually.be.rejectedWith(/​does not exist or is not accessible/​);54 });55 it('should error out for invalid app path', async function () {56 const caps = amendCapabilities(APIDEMOS_CAPS, {57 'appium:app': 'foo.apk',58 'appium:appPackage': APIDEMOS_PACKAGE,59 'appium:appActivity': APIDEMOS_SPLIT_TOUCH_ACTIVITY,60 });61 await initSession(caps).should.eventually.be.rejectedWith(/​does not exist or is not accessible/​);62 });63 });64 describe('custom adb port', function () {65 let adbPort = 5042;66 let driver;67 beforeEach(async function () {68 await killAndPrepareServer(DEFAULT_ADB_PORT, adbPort);69 });70 afterEach(async function () {71 if (driver) {72 await deleteSession();73 }74 driver = null;75 await killAndPrepareServer(adbPort, DEFAULT_ADB_PORT);76 });77 it('should start android session with a custom adb port', async function () {78 const caps = amendCapabilities(APIDEMOS_CAPS, {79 'appium:adbPort': adbPort,80 'appium:allowOfflineDevices': true,81 });82 driver = await initSession(caps, adbPort);83 await driver.getCurrentPackage().should.eventually.equal(APIDEMOS_PACKAGE);84 await driver.getCurrentActivity().should.eventually.equal(APIDEMOS_MAIN_ACTIVITY);85 });86 });87});88describe('close', function () {89 it('should close application', async function () {90 const driver = await initSession(APIDEMOS_CAPS);91 await driver.closeApp();92 APIDEMOS_PACKAGE.should.not.equal(await driver.getCurrentPackage());93 });...

Full Screen

Full Screen

general-e2e-specs.js

Source: general-e2e-specs.js Github

copy

Full Screen

...13 await deleteSession();14 });15 describe('startActivity', function () {16 it('should launch a new package and activity', async function () {17 let appPackage = await driver.getCurrentPackage();18 let appActivity = await driver.getCurrentActivity();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

camera-screen.js

Source: camera-screen.js Github

copy

Full Screen

...12 if ( this.isIos() ) {13 await this.click("Take Picture");14 await this.click("Use Photo");15 } else {16 let packageName = await this.driver.getCurrentPackage();17 if ( packageName === "com.sec.android.app.camera") {18 /​/​ yuck there isn't an accesssbility label or even button because the UI is in OpenGL19 /​/​ this is fragile and will break but for now its OK.20 await this.driver.touchAction([{action: 'tap', x: 1797, y: 545 }]);21 /​/​await this.driver.debug();22 await this.waitForRaw( `android=new UiSelector().resourceId("com.sec.android.app.camera:id/​okay")`, "waiting for photo to be taken" )23 await this.clickRaw( `android=new UiSelector().resourceId("com.sec.android.app.camera:id/​okay")`);24 } else {25 await this.clickRaw(`android=new UiSelector().resourceId("com.android.camera:id/​shutter_button")`); 26 await this.clickRaw(`android=new UiSelector().resourceId("com.android.camera:id/​btn_done")`);27 }28 }29 }30}...

Full Screen

Full Screen

button_spec.js

Source: button_spec.js Github

copy

Full Screen

1var wdio = require("webdriverio");2var assert = require("assert");3async function getElementById(id, driver) {4 const appPackage = await driver.getCurrentPackage();5 const textviewSelector =6 'new UiSelector().resourceId("' + appPackage + ":id/​" + id + '")';7 return $("android=" + textviewSelector);8}9describe("Hello button", () => {10 it("should change the text to 'Hello World!'", async () => {11 const paragraph = await getElementById("txtResult", driver);12 let actualText = await paragraph.getText();13 let expectedText = "Hello World!";14 assert.notStrictEqual(15 actualText,16 expectedText,17 "Text should be something else before the button is clicked"18 ); /​/​ compare expected value and actula value...

Full Screen

Full Screen

test.js

Source: test.js Github

copy

Full Screen

1var wdio = require("webdriverio");2var assert = require("assert");3async function getElementById(id, driver) {4 const appPackage = await driver.getCurrentPackage();5 const textviewSelector =6 'new UiSelector().resourceId("' + appPackage + ":id/​" + id + '")';7 return $("android=" + textviewSelector);8}9describe("first_test", () => {10 it("TC_01_Sign In To The Account", async () => {11 const paragraph = await getElementById("txtResult", driver);12 let actualText = await paragraph.getText();13 let expectedText = "Hello World!";14 assert.notStrictEqual(15 actualText,16 expectedText,17 "Text should be something else before the button is clicked"18 ); /​/​ compare expected value and actula value...

Full Screen

Full Screen

android-create-session.test.js

Source: android-create-session.test.js Github

copy

Full Screen

...16/​/​ });17/​/​18/​/​ /​/​ Check that we're running the ApiDemos app by checking package and activity19/​/​ const activity = await driver.getCurrentActivity();20/​/​ const pkg = await driver.getCurrentPackage();21/​/​ assert.equal(`${pkg}${activity}`, 'io.appium.android.apis.ApiDemos');22/​/​23/​/​ /​/​ Quit the session24/​/​ await driver.quit();25/​/​ });...

Full Screen

Full Screen

getCurrentPackage.js

Source: getCurrentPackage.js Github

copy

Full Screen

...15 * let package = mob.getCurrentPackage(); /​/​ Gets current Android package.16*/​17module.exports = async function() {18 await this.helpers.assertContext(this.helpers.contextList.android);19 return await this.driver.getCurrentPackage();...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var assert = require('assert');3var desiredCaps = {4};5var driver = wd.remote("localhost", 4723);6driver.init(desiredCaps, function() {7 driver.getCurrentPackage(function(err, currentPackage){8 console.log("Current Package: " + currentPackage);9 });10});11driver.quit();

Full Screen

Using AI Code Generation

copy

Full Screen

1driver.getCurrentPackage().then(function (currentPackage) {2 console.log("Current package: " + currentPackage);3});4driver.getCurrentActivity().then(function (currentActivity) {5 console.log("Current activity: " + currentActivity);6});7driver.getDeviceTime().then(function (deviceTime) {8 console.log("Device time: " + deviceTime);9});10driver.getDeviceTime().then(function (deviceTime) {11 console.log("Device time: " + deviceTime);12});13driver.getDeviceTime().then(function (deviceTime) {14 console.log("Device time: " + deviceTime);15});16driver.getDeviceTime().then(function (deviceTime) {17 console.log("Device time: " + deviceTime);18});19driver.getDeviceTime().then(function (deviceTime) {20 console.log("Device time: " + deviceTime);21});22driver.getDeviceTime().then(function (deviceTime) {23 console.log("Device time: " + deviceTime);24});25driver.getDeviceTime().then(function (deviceTime) {26 console.log("Device time: " + deviceTime);27});28driver.getDeviceTime().then(function (deviceTime) {29 console.log("Device time: " + deviceTime);30});31driver.getDeviceTime().then(function (deviceTime) {32 console.log("Device time: " + deviceTime);33});

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('selenium-webdriver');2var driver = new webdriver.Builder().forBrowser('chrome').build();3driver.getCurrentPackage().then(function(currentPackage) {4 console.log("Current Package: " + currentPackage);5});6driver.quit();7Recommended Posts: How to use driver.getOrientation() in Appium8How to use driver.getGeoLocation() in Appium9How to use driver.lock() in Appium10How to use driver.unlock() in Appium11How to use driver.isLocked() in Appium12How to use driver.hideKeyboard() in Appium13How to use driver.getNetworkConnection() in Appium14How to use driver.setNetworkConnection() in Appium

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd'),2 _ = require('underscore'),3 assert = require('assert');4var desired = {5};6var driver = wd.remote("localhost", 4723);7driver.init(desired, function() {8 driver.getCurrentPackage(function(err, pkg) {9 if (err) throw err;10 console.log("Current Package: " + pkg);11 });12 driver.quit();13});14var wd = require('wd'),15 _ = require('underscore'),16 assert = require('assert');17var desired = {18};19var driver = wd.remote("localhost", 4723);20driver.init(desired, function() {21 driver.getCurrentActivity(function(err, act) {22 if (err) throw err;23 console.log("Current Activity: " + act);24 });25 driver.quit();26});27var wd = require('wd'),28 _ = require('underscore'),29 assert = require('assert');30var desired = {

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

How To Use Appium Inspector For Mobile Apps

Let’s put it short: Appium Desktop = Appium Server + Inspector. When Appium Server runs automation test scripts, Appium Inspector can identify the UI elements of every application under test. The core structure of an Appium Inspector is to ensure that you discover every visible app element when you develop your test scripts. Before you kickstart your journey with Appium Inspector, you need to understand the details of it.

August &#8217;21 Updates: Live With iOS 14.5, Latest Browsers, New Certifications, &#038; More!

Hey Folks! Welcome back to the latest edition of LambdaTest’s product updates. Since programmer’s day is just around the corner, our incredible team of developers came up with several new features and enhancements to add some zing to your workflow. We at LambdaTest are continuously upgrading the features on our platform to make lives easy for the QA community. We are releasing new functionality almost every week.

Difference Between Web vs Hybrid vs Native Apps

Native apps are developed specifically for one platform. Hence they are fast and deliver superior performance. They can be downloaded from various app stores and are not accessible through browsers.

Top 12 Mobile App Testing Tools For 2022: A Beginner&#8217;s List

This article is a part of our Content Hub. For more in-depth resources, check out our content hub on Mobile App Testing Tutorial.

11 Best Automated UI Testing Tools In 2022

The web development industry is growing, and many Best Automated UI Testing Tools are available to test your web-based project to ensure it is bug-free and easily accessible for every user. These tools help you test your web project and make it fully compatible with user-end requirements and needs.

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