Best JavaScript code snippet using appium-xcuitest-driver
index.js
Source:index.js
1const express = require('express');2const bodyParser = require('body-parser')3const cors = require('cors')4const serverlessExpress = require('aws-serverless-express');5const awsServerlessExpressMiddleware = require('aws-serverless-express/middleware')6const AmazonQLDBDriverNodejs = require("amazon-qldb-driver-nodejs");7const AWS = require("aws-sdk");8AWS.config.update({region:'us-east-1'});9const qldb = new AWS.QLDB({apiVersion: '2019-01-02'});10const ionjs = require("ion-js");11const utils = require("./utils");12const qldbDriver = new AmazonQLDBDriverNodejs.PooledQldbDriver("DealLedger", {region: "us-east-1"});13const app = express();14const router = express.Router();15router.use(cors())16router.use(bodyParser.json())17router.use(bodyParser.urlencoded({ extended: true }))18router.use(awsServerlessExpressMiddleware.eventContext())19app.use('/api/', router);20const server = serverlessExpress.createServer(app);21exports.handler = (event, context) => {22 console.log("inside lambda handler",JSON.stringify(event,null,2));23 serverlessExpress.proxy(server, event, context);24}25router.get('/health',async (req,res)=>{26 27 res.json({status:'UP'});28})29router.get('/get-block',async (req,res)=>{30 let r = await qldb.getBlock({31 BlockAddress: { /* required */32 IonText: '{strandId:"BfvSL5DYUKE3spPDrWewCC",sequenceNo:4}'33 },34 Name: 'DealLedger', /* required */35 DigestTipAddress: {36 IonText: '{strandId:"BfvSL5DYUKE3spPDrWewCC",sequenceNo:135}'37 }38 }).promise();39 res.json(r);40})41router.get('/ledger/:tablename',async (req,res)=>{42 let tablename = req.params.tablename;43 const writer = ionjs.makeTextWriter();44 const qldbSession = await qldbDriver.getSession();45 let r = await (await qldbSession.executeStatement(`Select * from _ql_committed_${tablename} as v`)).getResultList();46 47 let json =[];48 r.forEach(reader=>{49 reader.next();50 let obj = utils.recursivePathLookup(reader,[]);51 obj.blockAddress.sequenceNo = parseInt( obj.blockAddress.sequenceNo.join(''));52 json.push({data: obj.data, blockAddress: obj.blockAddress,metadata:obj.metadata});53 })54 55 res.json(json);56})57router.get('/history/:tablename/:id',async (req,res)=>{58 let tablename = req.params.tablename;59 let id = req.params.id;60 const writer = ionjs.makeTextWriter();61 const qldbSession = await qldbDriver.getSession();62 let r = await (await qldbSession.executeStatement(`Select * from history(${tablename}) as h where h.metadata.id='${id}'`)).getResultList();63 64 let json =[];65 r.forEach(reader=>{66 reader.next();67 let obj = utils.recursivePathLookup(reader,[]);68 obj.blockAddress.sequenceNo = parseInt( obj.blockAddress.sequenceNo.join(''));69 json.push({data: obj.data, blockAddress: obj.blockAddress,metadata:obj.metadata});70 })71 72 res.json(json);73})74router.post('/verification',async (req,res)=>{75 let body = req.body;76 77 let revision = await qldb.getRevision({78 BlockAddress: { /* required */79 IonText: JSON.stringify(body.blockAddress)80 },81 DocumentId: body.metadata.id, /* required */82 Name: 'DealLedger', /* required */83 DigestTipAddress: {84 IonText: body.digest.DigestTipAddress.IonText85 }86 }).promise()87 88 res.json(revision);89})90router.get('/digest',async (req,res)=>{91 92 let r = await qldb.getDigest({Name:'DealLedger'}).promise();93 res.json(r);94})95router.put('/update-status',async (req,res)=>{96 let body = req.body;97 const qldbSession = await qldbDriver.getSession();98 99 const dealIdQldbWriter = AmazonQLDBDriverNodejs.createQldbWriter();100 utils.writeValueAsIon(body.dealId, dealIdQldbWriter);101 const statusQldbWriter = AmazonQLDBDriverNodejs.createQldbWriter();102 utils.writeValueAsIon(body.status, statusQldbWriter);103 const statement = "UPDATE Deal as v set v.status=? where v.dealId=?";104 let r = await (await qldbSession.executeStatement(statement,[statusQldbWriter,dealIdQldbWriter])).getResultList();105 106 res.json({success:true});...
driverProvider.js
Source:driverProvider.js
...49 if (driverIndex >= 0) {50 this.drivers_.splice(driverIndex, 1);51 }52 var deferred = q.defer();53 if (driver.getSession() === undefined) {54 deferred.resolve();55 }56 else {57 driver.getSession()58 .then(function (session_) {59 if (session_) {60 driver.quit().then(function () {61 deferred.resolve();62 });63 }64 else {65 deferred.resolve();66 }67 })68 .catch(function (err) {69 deferred.resolve();70 });71 }...
wd-bridge.js
Source:wd-bridge.js
...30 wdDriver.swEl = function (el) {31 // converting from selenium-webdriver to wd32 return new seleniumWebdriver.WebElement(driver, {ELEMENT: el.value});33 };34 driver.getSession().then(function (session) {35 wdDriver.attach(session.getId());36 deferred.resolve(wdDriver);37 });38 return deferred.promise;39 },40 initFromProtractor: function (config) {41 var protractor = externalLib;42 /* global browser */43 var url;44 if (config.sauceUser && config.sauceKey) {45 url = UrlLib.parse(config.seleniumAddress ||46 'http://ondemand.saucelabs.com:80/wd/hub');47 url.auth = config.sauceUser + ':' + config.sauceKey;48 } else {49 url = UrlLib.parse(config.seleniumAddress);50 }51 var wdBrowser = global.wdBrowser = wd.promiseChainRemote(url);52 wdBrowser.wdEl = function (el) {53 // converting from selenium-webdriver to wd54 return wdBrowser.chain()55 .then(function () {56 return el.toWireValue().then(function (wireValue) {57 return wdBrowser.newElement(wireValue.ELEMENT);58 });59 });60 };61 wdBrowser.swEl = function (el) {62 // converting from selenium-webdriver to wd63 return new protractor.WebElement(browser, {ELEMENT: el.value});64 };65 browser.driver.getSession().then(function (session) {66 wdBrowser.attach(session.getId());67 });68 }69 };...
test.js
Source:test.js
1const AmazonQLDBDriverNodejs = require("amazon-qldb-driver-nodejs");2const AWS = require("aws-sdk");3AWS.config.update({region:'us-east-1'});4const qldb = new AWS.QLDB({apiVersion: '2019-01-02'});5const ionjs = require("ion-js");6const utils = require("./utils");7const qldbDriver = new AmazonQLDBDriverNodejs.PooledQldbDriver("DealLedger", {region: "us-east-1"});8var main = async function(){9 console.log("calling main ");10 11 const qldbSession = await qldbDriver.getSession();12 for (const table of await qldbSession.getTableNames()) {13 console.log(table);14 }15 let r = await (await qldbSession.executeStatement("Select * from _ql_committed_Deal as v")).getResultList();16 17 //console.log(r);18 let json = [];19 r.forEach(reader=>{20 // let writer = ionjs.makeTextWriter();21 // //console.log(reader);22 // writer.writeValues(reader);23 // let s = ionjs.decodeUtf8(writer.getBytes());24 // //s = s.substring(1);25 // json.push(s)26 // reader.next();27 // reader.stepIn();28 // reader.next();29 // reader.next();30 // reader.next();31 // console.log(reader.fieldName());32 // console.log(ionjs.decodeUtf8(reader.byteValue()));33 reader.next();34 let obj = utils.recursivePathLookup(reader,[]);35 json.push({data: obj.data, blockAddress: obj.blockAddress});36 //json.push(utils.getFieldValue(reader,["data"]));37 //console.log(utils.getFieldValue(reader,["data"]));38 })39 //let records = ionjs.decodeUtf8(writer.getBytes());40 console.log(json);41 //qldbWriter = AmazonQLDBDriverNodejs.createQldbWriter();42}43var main2 = async function(){44 console.log("calling main2 ");45 46 const qldbSession = await qldbDriver.getSession();47 for (const table of await qldbSession.getTableNames()) {48 console.log(table);49 }50 const qldbWriter = AmazonQLDBDriverNodejs.createQldbWriter();51 const dealId = "108570";52 utils.writeValueAsIon(dealId, qldbWriter);53 const statement = "UPDATE Deal as v set v.status='dmv-rejected' where v.dealId=?"54 let r = await (await qldbSession.executeStatement(statement,[qldbWriter])).getResultList();55 56 const writer = ionjs.makeTextWriter();57 r.forEach(reader=>{58 writer.writeValues(reader);59 60 })61 console.log(ionjs.decodeUtf8(writer.getBytes()));62}...
session-specs.js
Source:session-specs.js
...38 javascript_enabled: true,39 app: 'NOTLOL.app',40 };41 driver.deviceCaps = undefined;42 let res = await driver.getSession();43 proxySpy.calledOnce.should.be.true;44 res.should.eql({45 sillyCap: true,46 app: 'LOL.app',47 platformName: 'iOS',48 javascript_enabled: true,49 udid: 'cecinestpasuneudid',50 statBarHeight: 20,51 viewportRect: {x: 1, y: 2, height: 3, width: 4},52 pixelRatio: 3,53 });54 });55 it('should merge caps with WDA response without screen info', async function () {56 driver.caps = {57 platformName: 'iOS',58 javascript_enabled: true,59 app: 'NOTLOL.app',60 };61 driver.deviceCaps = undefined;62 driver.opts.includeDeviceCapsToSessionInfo = false;63 let res = await driver.getSession();64 proxySpy.calledOnce.should.be.false;65 res.should.eql({66 sillyCap: true,67 app: 'LOL.app',68 platformName: 'iOS',69 javascript_enabled: true,70 udid: 'cecinestpasuneudid'71 });72 });73 });...
driver.js
Source:driver.js
...28 "/session/:sessionId/webauthn/authenticator/:authenticatorId/uv"29 );30 }31 static async addVirtualAuthenticator(driver) {32 const sessionId = (await driver.getSession()).id_;33 const addVirtualAuthCommand = new Command(34 Driver.commands.ADDVIRTUALAUTHENTICATOR35 );36 addVirtualAuthCommand.setParameter("sessionId", sessionId);37 addVirtualAuthCommand.setParameter("protocol", "ctap2");38 addVirtualAuthCommand.setParameter("transport", "internal");39 addVirtualAuthCommand.setParameter("hasResidentKey", true);40 addVirtualAuthCommand.setParameter("isUserConsenting", true);41 addVirtualAuthCommand.setParameter("isUserVerified", true);42 addVirtualAuthCommand.setParameter("hasUserVerification", true);43 const authenticatorId = await driver44 .getExecutor()45 .execute(addVirtualAuthCommand);46 return { driver, authenticatorId };47 }48 static async setUserVerified(driver, authenticatorId, isUserVerified) {49 const sessionId = (await driver.getSession()).id_;50 const setUserVerified = new Command(Driver.commands.SETUSERVERIFIED);51 setUserVerified.setParameters({52 sessionId,53 authenticatorId,54 isUserVerified,55 });56 await driver.getExecutor().execute(setUserVerified);57 }...
SeleniumDriver.js
Source:SeleniumDriver.js
1var webdriver = require('selenium-webdriver'),2 when = require('when');3function SeleniumDriver(host, port, capabilities) {4 var currentDriver;5 process.on("uncaughtException", function (err) {6 console.log('[SeleniumDriver]: unhandled exception');7 if (err && err.stack) console.log(err.stack);8 });9 webdriver.promise.controlFlow().on('uncaughtException', function(err) {10 console.log('[SeleniumDriver]: controlflow, unhandled exception');11 if (err && err.stack) console.log(err.stack);12 });13 return {14 capture: function(busterServerUrl) {15 currentDriver = new webdriver.Builder().16 usingServer('http://' + host + ':' + port + '/wd/hub').17 withCapabilities(capabilities).18 build();19 console.log('[SeleniumDriver] Asking the grid server to connect a node with %s to %s',20 capabilities.browserName, busterServerUrl);21 return this.navigate(busterServerUrl);22 },23 getCapabilities: function() {24 return capabilities;25 },26 navigate: function(url) {27 return currentDriver.get(url);28 },29 isAvailable: function() {30 return !!currentDriver;31 },32 getSession: function() {33 return currentDriver.getSession();34 },35 quit: function() {36 return currentDriver.quit();37 }38 }39}...
webdriver-existing-chrome-start.js
Source:webdriver-existing-chrome-start.js
...15 .build();16 try {17 //-- baidu begin--18 await driver.get('http://www.baidu.com');19 await driver.getSession().then( s => {20 console.log("url:" + s.getId());21 });22 23 //console.log("session:" + driver.getSession());24 25 //-- baidu end-- 26 }27 finally {28 //await driver.quit();29 }...
Using AI Code Generation
1var webdriver = require('selenium-webdriver');2var driver = new webdriver.Builder()3 .withCapabilities({4 })5 .build();6driver.getSession().then(function(sessionId) {7 console.log(sessionId);8 driver.quit();9});10Session {11 Capabilities {12 'webdriver.remote.sessionid': 'e6b8d9e1-6b50-4d5e-8a0b-1e6c1f7d2f66' } }13[{"id":"e6b8d9e1-6b50-4d5e-8a0b-1e6c1f7d2f66","capabilities":{"acceptSslCerts":true,"browserName
Using AI Code Generation
1const wdio = require("webdriverio");2const assert = require("assert");3const opts = {4 capabilities: {5 }6};7async function main() {8 const client = await wdio.remote(opts);9 const session = await client.getSession();10 console.log(session);11 await client.deleteSession();12}13main();14const wdio = require("webdriverio");15const assert = require("assert");16const opts = {17 capabilities: {18 }19};20async function main() {21 const client = await wdio.remote(opts);22 const session = await client.getSession();23 console.log(session);24 await client.deleteSession();25}26main();27const wdio = require("webdriverio");28const assert = require("assert");29const opts = {30 capabilities: {
Using AI Code Generation
1const webdriverio = require('webdriverio');2const options = {3 desiredCapabilities: {4 }5};6const client = webdriverio.remote(options);7 .init()8 .getSession()9 .then(function(sessionId) {10 console.log(sessionId);11 })12 .end();13const webdriverio = require('webdriverio');14const options = {15 desiredCapabilities: {16 }17};18const client = webdriverio.remote(options);19 .init()20 .getSession()21 .then(function(sessionId) {22 console.log(sessionId);23 })24 .end();25const webdriverio = require('webdriverio');26const options = {27 desiredCapabilities: {28 }29};30const client = webdriverio.remote(options);31 .init()32 .getSession()
Using AI Code Generation
1var webdriverio = require('webdriverio');2var options = {3 desiredCapabilities: {4 }5};6 .remote(options)7 .init()8 .then(function (client) {9 return client.getSession().then(function (session) {10 console.log(session);11 return client.end();12 });13 })14 .catch(function (err) {15 console.log(err);16 process.exit(1);17 });18from appium import webdriver19from selenium.webdriver.support.ui import WebDriverWait20desired_caps = {}21print(driver.session_id)22driver.quit()23caps = {}24driver = Appium::Driver.new({caps: caps, appium_lib: {port: 4723}})25import io.appium.java_client.AppiumDriver;26import io.appium.java_client.remote.MobileCapabilityType;27import org.openqa.selenium.remote.DesiredCapabilities;28import java.net.MalformedURLException;29import java.net.URL;30public class Test {31 public static void main(String[] args) throws MalformedURLException {32 DesiredCapabilities capabilities = new DesiredCapabilities();33 capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "iOS");34 capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "11.4");35 capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone 8");36 capabilities.setCapability(MobileCapabilityType.APP, "path/to/my.app");
Using AI Code Generation
1const {remote} = require('webdriverio');2const opts = {3 capabilities: {4 }5};6(async function () {7 let client = await remote(opts);8 let session = await client.getSession();9 console.log(session);10 await client.deleteSession();11})();12const {remote} = require('webdriverio');13const opts = {14 capabilities: {15 }16};17(async function () {18 let client = await remote(opts);19 let session = await client.getSession();20 console.log(session);21 await client.deleteSession();22})();23const {remote} = require('webdriverio');24const opts = {25 capabilities: {26 }27};28(async function () {29 let client = await remote(opts);30 let session = await client.getSession();31 console.log(session);32 await client.deleteSession();33})();
Using AI Code Generation
1var webdriver = require('selenium-webdriver');2var driver = new webdriver.Builder()3 .withCapabilities({4 })5 .build();6driver.getSession().then(function(session) {7 console.log(session.getId());8 console.log(session.getCapabilities());9 driver.quit();10});
Using AI Code Generation
1var webdriver = require('selenium-webdriver');2var driver = new webdriver.Builder()3 .withCapabilities({4 })5 .build();6driver.getSession().then(function(sessionId) {7 console.log(sessionId);8});9{ id: '4a0b4c4d-4e5f-6a7b-8c9d-0e1f2a3b4c5d',10 { platform: 'MAC',11 warnings: {},12 { platformName: 'iOS',13 appiumVersion: '1.7.2' },14 appiumVersion: '1.7.2' } }
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!!