How to use verifyFind method in Appium Xcuitest Driver

Best JavaScript code snippet using appium-xcuitest-driver

browser_findbar_marks.js

Source:browser_findbar_marks.js Github

copy

Full Screen

...98 let findbar = await gBrowser.getFindBar();99 let closedPromise = BrowserTestUtils.waitForEvent(findbar, "findbarclose");100 await EventUtils.synthesizeKey("KEY_Escape");101 await closedPromise;102 await verifyFind(browser, "", true, []);103 }104 endFn();105 gBrowser.removeTab(tab);106});107// This test verifies what happens when scroll marks are visible and the window is resized.108add_task(async function test_found_resize() {109 let window2 = await BrowserTestUtils.openNewBrowserWindow({});110 let tab = await BrowserTestUtils.openNewForegroundTab(111 window2.gBrowser,112 TEST_PAGE_URI113 );114 let browser = tab.linkedBrowser;115 let endFn = initForBrowser(browser);116 await promiseFindFinished(window2.gBrowser, "tex", true);117 let values = await getMarks(browser, true);118 let resizePromise = BrowserTestUtils.waitForContentEvent(119 browser,120 "resize",121 true122 );123 window2.resizeTo(outerWidth - 100, outerHeight - 80);124 await resizePromise;125 // Some number of extra scrollbar adjustment and painting events can occur126 // when resizing the window, so don't use an exact match for the count.127 let resizedValues = await getMarks(browser, true);128 SimpleTest.isfuzzy(resizedValues[0], values[0], 2, "first value");129 SimpleTest.ok(resizedValues[1] - 50 > values[1], "second value");130 SimpleTest.ok(resizedValues[2] - 50 > values[2], "third value");131 endFn();132 await BrowserTestUtils.closeWindow(window2);133});134// Returns the scroll marks that should have been assigned135// to the scrollbar after a find. As a side effect, also136// verifies that the marks have been updated since the last137// call to getMarks. If increase is true, then the marks should138// have been updated, and if increase is false, the marks should139// not have been updated.140async function getMarks(browser, increase) {141 let results = await SpecialPowers.spawn(browser, [], () => {142 let marks = content.lastMarks;143 content.lastMarks = null;144 return {145 marks: marks || [],146 count: content.eventsCount,147 };148 });149 // The marks are updated whenever the scrollbar is updated and150 // this could happen several times as either a find for multiple151 // characters occurs. This check allows for mutliple updates to occur.152 if (increase) {153 Assert.ok(results.count > gUpdateCount, "expected events count");154 } else {155 Assert.equal(results.count, gUpdateCount, "expected events count");156 }157 gUpdateCount = results.count;158 return results.marks;159}160async function doAndVerifyFind(browser, text, increase, expectedMarks) {161 await promiseFindFinished(browser.getTabBrowser(), text, true);162 return verifyFind(browser, text, increase, expectedMarks);163}164async function verifyFind(browser, text, increase, expectedMarks) {165 let foundMarks = await getMarks(browser, increase);166 is(foundMarks.length, expectedMarks.length, "marks count with text " + text);167 for (let t = 0; t < foundMarks.length; t++) {168 SimpleTest.isfuzzy(169 foundMarks[t],170 expectedMarks[t],171 5,172 "mark " + t + " with text " + text173 );174 }175 Assert.deepEqual(foundMarks, expectedMarks, "basic find with text " + text);...

Full Screen

Full Screen

find-specs.js

Source:find-specs.js Github

copy

Full Screen

...20 });21 proxySpy.reset();22 }23 it('should convert class names from UIA to XCUI', async function () {24 await verifyFind('class name', 'UIAButton', 'XCUIElementTypeButton');25 await verifyFind('class name', 'UIAMapView', 'XCUIElementTypeMap');26 await verifyFind('class name', 'UIAScrollView', 'XCUIElementTypeScrollView');27 await verifyFind('class name', 'UIACollectionView', 'XCUIElementTypeCollectionView');28 await verifyFind('class name', 'UIATextView', 'XCUIElementTypeTextView');29 await verifyFind('class name', 'UIAWebView', 'XCUIElementTypeWebView');30 });31 it('should convert xpaths from UIA to XCUI', async function () {32 await verifyFind('xpath', '//UIAButton', '//XCUIElementTypeButton');33 await verifyFind('xpath',34 '//UIAButton/UIATextField',35 '//XCUIElementTypeButton/XCUIElementTypeTextField');36 await verifyFind('xpath',37 'UIAButton//UIATextField',38 'XCUIElementTypeButton//XCUIElementTypeTextField');39 await verifyFind('xpath',40 '//UIAButton[@name="foo"]',41 '//XCUIElementTypeButton[@name="foo"]');42 await verifyFind('xpath',43 '//UIAButton/Weird',44 '//XCUIElementTypeButton/Weird');45 await verifyFind('xpath',46 '//UIAMapView/UIAScrollView',47 '//XCUIElementTypeMap/XCUIElementTypeScrollView');48 await verifyFind('xpath',49 '//UIAMapView/UIAScrollView[@name="UIADummyData"]',50 '//XCUIElementTypeMap/XCUIElementTypeScrollView[@name="UIADummyData"]');51 await verifyFind('xpath',52 '//XCUIElementTypeMap[@name="UIADummyData"]',53 '//XCUIElementTypeMap[@name="UIADummyData"]');54 });55 it('should reject request for first visible child with no context', async function () {56 await driver.findNativeElementOrElements(57 'xpath', '/*[@firstVisible="true"]', false)58 .should.eventually.be.rejectedWith(/without a context element/);59 });60 it('should reject request for multiple first visible children', async function () {61 await driver.findNativeElementOrElements(62 'xpath', '/*[@firstVisible="true"]', true)63 .should.eventually.be.rejectedWith(/Cannot get multiple/);64 });65 it('should convert magic first visible child xpath to class chain', async function () {66 const variants = [67 '/*[@firstVisible="true"]',68 "/*[@firstVisible='true']",69 "/*[@firstVisible = 'true']"70 ];71 let attribSpy = sinon.stub(driver, 'getAttribute');72 for (const variant of variants) {73 proxySpy.withArgs(74 '/element/ctx/element',75 'POST',76 {using: 'class chain', value: '*[1]'}77 ).returns({ELEMENT: 1});78 proxySpy.withArgs(79 '/element/ctx/element',80 'POST',81 {using: 'class chain', value: '*[2]'}82 ).returns({ELEMENT: 2});83 attribSpy.withArgs('visible', {ELEMENT: 1}).returns('false');84 attribSpy.withArgs('visible', {ELEMENT: 2}).returns('true');85 let el = await driver.findNativeElementOrElements('xpath',86 variant, false, {ELEMENT: 'ctx'});87 proxySpy.calledTwice.should.be.true;88 proxySpy.firstCall.args[2].should.eql({89 using: 'class chain',90 value: '*[1]',91 });92 proxySpy.secondCall.args[2].should.eql({93 using: 'class chain',94 value: '*[2]',95 });96 attribSpy.calledTwice.should.be.true;97 el.should.eql({ELEMENT: 2});98 proxySpy.reset();99 attribSpy.reset();100 }101 });102 it('should convert magic is scrollable xpath to class chain', async function () {103 const multSel = '**/*[`type == "XCUIElementTypeScrollView" OR ' +104 'type == "XCUIElementTypeTable" OR ' +105 'type == "XCUIElementTypeCollectionView" OR ' +106 'type == "XCUIElementTypeWebView"`]';107 const singleSel = `${multSel}[1]`;108 await verifyFind('xpath',109 '//*[@scrollable="true"]',110 singleSel,111 'class chain');112 await verifyFind('xpath',113 `//*[@scrollable='true']`,114 singleSel,115 'class chain');116 await verifyFind('xpath',117 `//*[@scrollable = 'true']`,118 singleSel,119 'class chain');120 await verifyFind('xpath',121 '//*[@scrollable="true"]',122 multSel,123 'class chain',124 true);125 });126 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const assert = require('assert');2const wdio = require('webdriverio');3const opts = {4 capabilities: {5 }6};7async function main () {8 const client = await wdio.remote(opts);9 const element = await client.$('~Accessibility');10 const isAccessibilityPresent = await element.isExisting();11 assert.equal(isAccessibilityPresent, true);12 await client.deleteSession();13}14main();15const assert = require('assert');16const wdio = require('webdriverio');17const opts = {18 capabilities: {19 }20};21async function main () {22 const client = await wdio.remote(opts);23 const element = await client.$('~Accessibility');24 const isAccessibilityPresent = await element.isExisting();25 assert.equal(isAccessibilityPresent, true);26 await client.deleteSession();27}28main();29const assert = require('assert');30const wdio = require('webdriverio');31const opts = {32 capabilities: {33 }34};35async function main () {36 const client = await wdio.remote(opts);37 const element = await client.$('~Accessibility');38 const isAccessibilityPresent = await element.isExisting();39 assert.equal(isAccessibilityPresent, true);40 await client.deleteSession();41}42main();43const assert = require('assert');44const wdio = require('webdriverio

Full Screen

Using AI Code Generation

copy

Full Screen

1const wd = require('wd');2const chai = require('chai');3const chaiAsPromised = require('chai-as-promised');4chai.use(chaiAsPromised);5chai.should();6const serverConfig = {7};8const desiredCaps = {9};10const driver = wd.promiseChainRemote(serverConfig);11driver.init(desiredCaps);12const find = async (strategy, selector) => {13 let element;14 try {15 element = await driver.elementByAccessibilityId(selector);16 } catch (err) {17 return false;18 }19 return element;20};21const verifyFind = async (strategy, selector) => {22 let element;23 try {24 element = await driver.elementByAccessibilityId(selector);25 } catch (err) {26 return false;27 }28 return true;29};30const findAndVerify = async (strategy, selector) => {31 let element;32 try {33 element = await driver.elementByAccessibilityId(selector);34 } catch (err) {35 return false;36 }37 return element;38};39const findAndVerifyWithDelay = async (strategy, selector, delay) => {40 let element;41 try {42 element = await driver.elementByAccessibilityId(selector);43 } catch (err) {44 return false;45 }46 await driver.sleep(delay);47 return element;48};49const findAndVerifyWithDelayAndRetry = async (strategy, selector, delay, retry) => {50 let element;51 try {52 element = await driver.elementByAccessibilityId(selector);53 } catch (err) {54 return false;55 }56 await driver.sleep(delay);57 return element;58};59const findAndVerifyWithDelayAndRetryAndBackoff = async (strategy, selector, delay, retry, backoff) => {60 let element;61 try {62 element = await driver.elementByAccessibilityId(selector);63 } catch (err) {64 return false;65 }66 await driver.sleep(delay);67 return element;68};69const findAndVerifyWithDelayAndRetryAndBackoffAndInterval = async (strategy, selector, delay, retry, back

Full Screen

Using AI Code Generation

copy

Full Screen

1const wdio = require('webdriverio');2const assert = require('assert');3const opts = {4 capabilities: {5 }6};7(async () => {8 const client = await wdio.remote(opts);9 await client.pause(5000);10 let element = await client.$('XCUIElementTypeButton');11 let elementId = await element.elementId;12 let response = await client.execute('mobile: verifyFind', [{13 }]);14 console.log(response);15 assert(response === elementId);16 await client.deleteSession();17})().catch(async (e) => {18 console.error(e);19 await client.deleteSession();20});21[0-0] 2019-04-25T10:12:13.126Z INFO webdriver: COMMAND findElement("accessibility id", "Buttons")22[0-0] 2019-04-25T10:12:13.126Z INFO webdriver: DATA { using: 'accessibility id', value: 'Buttons' }23[0-0] 2019-04-25T10:12:13.135Z INFO webdriver: COMMAND execute("mobile: verifyFind",[{using:"accessibility id",value:"Buttons"}])

Full Screen

Using AI Code Generation

copy

Full Screen

1const assert = require('assert');2const wd = require('wd');3const chai = require('chai');4const chaiAsPromised = require('chai-as-promised');5chai.use(chaiAsPromised);6chai.should();7const serverConfig = {8};9const desiredCaps = {10};11const driver = wd.promiseChainRemote(serverConfig);12driver.init(desiredCaps)13 .then(() => driver.waitForElementByAccessibilityId('myButton', 5000))14 .then((element) => {15 return element.getAttribute('name').should.eventually.equal('myButton');16 })17 .then(() => driver.quit());

Full Screen

Using AI Code Generation

copy

Full Screen

1var assert = require('assert');2var wd = require('wd');3var caps = {4};5driver.init(caps).then(function () {6}).then(function (exists) {7 assert.ok(exists, 'Button should exist');8 return driver.quit();9}).done();

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var assert = require('assert');3var xctest = require('appium-xcuitest-driver');4var driver = wd.promiseChainRemote('localhost', 4723);5var desired = {6};7 .init(desired)8 .then(function () {9 return driver.setImplicitWaitTimeout(5000);10 })11 .then(function () {12 return driver.verifyFind('accessibility id', 'myElement', 'myElement should be found');13 })14 .then(function () {15 return driver.verifyFind('accessibility id', 'myElement2', 'myElement2 should be found');16 })17 .then(function () {18 return driver.verifyFind('accessibility id', 'myElement3', 'myElement3 should be found');19 })20 .then(function () {21 return driver.verifyFind('accessibility id', 'myElement4', 'myElement4 should be found');22 })23 .then(function () {24 return driver.verifyFind('accessibility id', 'myElement5', 'myElement5 should be found');25 })26 .then(function () {27 return driver.verifyFind('accessibility id', 'myElement6', 'myElement6 should be found');28 })29 .then(function () {30 return driver.verifyFind('accessibility id', 'myElement7', 'myElement7 should be found');31 })32 .then(function () {33 return driver.verifyFind('accessibility id', 'myElement8', 'myElement8 should be found');34 })35 .then(function () {36 return driver.verifyFind('accessibility id', 'myElement9', 'myElement9 should be found');37 })38 .then(function () {39 return driver.verifyFind('accessibility id', 'myElement10', 'myElement10 should be found');40 })41 .then(function () {42 return driver.verifyFind('accessibility id', 'myElement11', 'myElement11 should be found');43 })44 .then(function () {45 return driver.verifyFind('accessibility id', 'myElement12', 'myElement12 should be found');46 })47 .then(function () {

Full Screen

Using AI Code Generation

copy

Full Screen

1const { verifyFind } = require('appium-base-driver').MJSONWP;2const { errors } = require('appium-base-driver');3describe('verifyFind', function () {4 it('should return true if element is found', function () {5 const el = {ELEMENT: '1'};6 const res = verifyFind(el);7 res.should.be.true;8 });9 it('should throw error if element is not found', function () {10 const res = () => verifyFind(null);11 res.should.throw(errors.NoSuchElementError);12 });13});

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 Xcuitest Driver automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Sign up Free
_

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful