Best JavaScript code snippet using appium
basic-specs.js
Source:basic-specs.js
...238 caps.intentCategory = "appium.android.intent.category.SAMPLE_CODE";239 setup(this, caps)240 .then(function (d) { driver = d; });241 it('should launch activity with intent category', function (done) {242 driver.getCurrentActivity()243 .should.eventually.include("HelloWorld")244 .nodeify(done);245 });246 });247 });248 describe('appium android', function () {249 this.timeout(env.MOCHA_INIT_TIMEOUT);250 var session;251 var title = getTitle(this);252 if (env.FAST_TESTS) {253 beforeEach(function (done) {254 androidReset('io.appium.android.apis', '.ApiDemos').nodeify(done);255 });256 }...
utils.js
Source:utils.js
...87 * @returns {boolean}88 */89function androidBrowserOpened() {90 try {91 driver.waitUntil(() => !driver.getCurrentActivity().includes('.MainActivity') && !driver.getCurrentActivity().includes('.GrantPermissionsActivity'));92 return true;93 } catch (e) {94 return false;95 }96}97/**98 * Verify that the browser is opened.99 * - iOS: For iOS we can check if Safari is running in the foreground100 * - Android: For Android we can check the current activity. If it holds a browser reference we know101 * for sure that the app is put on the background and that for example chrome is opened.102 *103 * @returns {boolean}104 */105export function isBrowserOpened() {...
driver-e2e-specs.js
Source:driver-e2e-specs.js
...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 });...
general-e2e-specs.js
Source:general-e2e-specs.js
...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 });...
keystore-base.js
Source:keystore-base.js
1"use strict";2var setup = require("./setup-base")3 , env = require('../../helpers/env')4 , exec = require('child_process').exec5 , osType = require('os').type()6 , rimraf = require('rimraf');7module.exports = function () {8 var tmp = osType === 'Windows_NT' ? 'C:\\Windows\\Temp' : '/tmp';9 var keystorePath = tmp + '/appiumtest.keystore';10 var keyAlias = 'appiumtest';11 var desired = {12 app: "sample-code/apps/selendroid-test-app.apk",13 appPackage: 'io.selendroid.testapp',14 appActivity: '.HomeScreenActivity',15 useKeystore: true,16 keystorePath: keystorePath,17 keyAlias: keyAlias18 };19 this.timeout(env.MOCHA_INIT_TIMEOUT);20 before(function (done) {21 rimraf(keystorePath, function (err) {22 if (err) return done(err);23 var cmd = 'keytool -genkey -v -keystore ' + keystorePath + ' -alias ' + keyAlias + ' -storepass android -keypass android -keyalg RSA -validity 14000';24 var child = exec(cmd, done);25 // answer the questions that `keytool` asks26 child.stdin.write('Appium Testsuite\nAppium\nTest\nSan Francisco\nCalifornia\nUS\nyes\n');27 });28 });29 // custom keystore doesn't make sense when running on Sauce30 describe('brand-new custom keystore @skip-ci', function () {31 var driver;32 setup(this, desired).then(function (d) { driver = d; });33 it('should be able to launch an app with custom keystore', function (done) {34 driver35 .getCurrentActivity()36 .should.eventually.include(desired.appActivity)37 .nodeify(done);38 });39 });...
deeplink.js
Source:deeplink.js
1const expectChai = require('chai').expect;2describe('Deep Link', () => {3 it('should let me switch between app and browser', () => {4 const appPackage = driver.getCurrentPackage();5 const appActivity = driver.getCurrentActivity();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 });...
First.js
Source:First.js
...5//boolean value true / false6//driver.isLocked();7//Console log to print line8//To get Current Activity9console.log("Hello Ritzz", driver.getCurrentActivity());10//--To get Current Package11driver.getCurrentPackage();12//--To install Application into Device13driver.installApp(c://rit/flipkart.apk)14 //to check whether this app is installed or not package 15 driver.isAppInstalled(appId)16//to Terminate app17driver.terminateApp(appId)18//--To hide keyword 19driver.hideKeyboard()20//--To check keyboard is open or not true/false21driver.isKeyboardShown()22//--To open activity and start application23driver.startActivity(appPackage, appActivity, appWaitPackage, appWaitActivity, intentAction, intentCategory, intentFlags, optionalIntentArguments, dontStopAppOnReset)...
android-create-session.test.js
Source:android-create-session.test.js
...11 ...androidCaps,12 app: require('../helpers/apps').androidApiDemos13 });14 // Check that we're running the ApiDemos app by checking package and activity15 const activity = await driver.getCurrentActivity();16 const pkg = await driver.getCurrentPackage();17 assert.equal(`${pkg}${activity}`, 'io.appium.android.apis.ApiDemos');18 // Quit the session19 await driver.quit();20 });...
Using AI Code Generation
1var webdriver = require('selenium-webdriver');2}).build();3driver.getCurrentActivity().then(function(currentActivity){4 console.log(currentActivity);5});6driver.quit();
Using AI Code Generation
1var wd = require('wd');2var assert = require('assert');3var caps = {4};5driver.init(caps)6 .then(function () {7 return driver.getCurrentActivity();8 })9 .then(function (activity) {10 console.log("Current Activity: " + activity);11 })12 .catch(function (err) {13 console.log(err);14 })15 .fin(function () {16 driver.quit();17 });18var wd = require('wd');19var assert = require('assert');20var caps = {21};22driver.init(caps)23 .then(function () {24 return driver.startActivity({25 });26 })27 .then(function () {28 return driver.getCurrentActivity();29 })30 .then(function (activity) {31 console.log("Current Activity: " + activity);32 })33 .catch(function (err) {34 console.log(err);35 })36 .fin(function () {37 driver.quit();38 });39var wd = require('wd');40var assert = require('assert');41var caps = {42};
Using AI Code Generation
1var wd = require('wd');2var assert = require('assert');3var fs = require('fs');4var desired = require('./desired');5var browser = wd.remote("localhost", 4723);6browser.init(desired, function() {7 browser.elementByName('q', function(err, el) {8 browser.type(el, "Hello World", function() {9 browser.elementByName('btnG', function(err, el) {10 browser.clickElement(el, function() {11 browser.elementByTagName('h3', function(err, el) {12 browser.text(el, function(err, text) {13 console.log(text);14 browser.quit();15 });16 });17 });18 });19 });20 });21 });22});23module.exports = {24};25> [debug] Request received with params: {"desiredCapabilities":{"app":"/path/to/my.apk","appActivity":"MyActivity","appPackage":"com.example.my","appium-version":"1.0","deviceName":"Samsung Galaxy S4","platformName":"Android","platformVersion":"4.4"}}
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!!