Best JavaScript code snippet using appium-android-driver
BadgeSelect.spec.js
Source:BadgeSelect.spec.js
1import React from 'react';2import BadgeSelect from '../BadgeSelect';3import { SKIN, SIZE, TYPE } from '../../Badge/constants';4import {5 createRendererWithDriver,6 cleanup,7 createRendererWithUniDriver,8} from '../../../test/utils/unit';9import badgeSelectPrivateDriverFactory from '../BadgeSelect.private.driver';10import { badgeSelectPrivateUniDriverFactory } from '../BadgeSelect.private.uni.driver';11describe('BadgeSelect', () => {12 describe('[sync]', () => {13 runTests(createRendererWithDriver(badgeSelectPrivateDriverFactory));14 });15 describe('[async]', () => {16 runTests(createRendererWithUniDriver(badgeSelectPrivateUniDriverFactory));17 });18 function runTests(render) {19 const initialOptionId = 0;20 const options = Object.values(SKIN).map((skin, id) => ({21 id: id.toString(),22 skin,23 text: skin,24 }));25 function createComponent(props = {}) {26 const combinedProps = {27 options,28 selectedId: initialOptionId.toString(),29 popoverProps: {30 appendTo: 'window',31 },32 ...props,33 };34 return render(<BadgeSelect {...combinedProps} />).driver;35 }36 afterEach(cleanup);37 it('should have a badge and hidden options by default', async () => {38 const { driver, badgeDriver } = createComponent();39 expect(await driver.exists()).toBe(true);40 expect(await driver.isDropdownShown()).toBe(false);41 expect(await badgeDriver.exists()).toBe(true);42 });43 it('should show badge with initial selected skin and text', async () => {44 const { badgeDriver } = createComponent();45 expect(await badgeDriver.getSkin()).toBe(options[initialOptionId].skin);46 expect(await badgeDriver.text()).toBe(options[initialOptionId].text);47 });48 it('should show badge with correct general props as default', async () => {49 const { badgeDriver } = createComponent();50 expect(await badgeDriver.getType()).toBe(TYPE.solid);51 expect(await badgeDriver.getSize()).toBe(SIZE.medium);52 expect(await badgeDriver.isUppercase()).toBe(true);53 });54 it('should show badge with props given', async () => {55 const { badgeDriver } = createComponent({56 type: TYPE.outlined,57 size: SIZE.small,58 uppercase: false,59 });60 expect(await badgeDriver.getType()).toBe(TYPE.outlined);61 expect(await badgeDriver.getSize()).toBe(SIZE.small);62 expect(await badgeDriver.isUppercase()).toBe(false);63 });64 it('should show badge selector when badge is clicked', async () => {65 const { driver, badgeDriver } = createComponent();66 await badgeDriver.click();67 expect(await driver.isDropdownShown()).toBe(true);68 });69 it('should hide options on selection', async () => {70 const { driver } = createComponent();71 await driver.click();72 await driver.clickAtOption(2);73 expect(await driver.isDropdownShown()).toBe(false);74 });75 it('should hide options on outside click', async () => {76 const { driver, badgeDriver } = createComponent();77 await badgeDriver.click();78 expect(await driver.isDropdownShown()).toBe(true);79 await driver.clickOutside();80 expect(await driver.isDropdownShown()).toBe(false);81 });82 it('should call onSelect when an option is selected', async () => {83 const onSelect = jest.fn();84 const selectedIndex = 3;85 const { driver } = createComponent({ onSelect });86 await driver.clickAtOption(selectedIndex);87 expect(onSelect).toBeCalled();88 expect(onSelect).toBeCalledWith(options[selectedIndex]);89 });90 describe('uncontrolled mode', () => {91 it('should pick the first option if no selectedId given', async () => {92 const uncontrolledProps = { selectedId: undefined };93 const { badgeDriver } = createComponent(uncontrolledProps);94 expect(await badgeDriver.getSkin()).toBe(options[0].skin);95 expect(await badgeDriver.text()).toBe(options[0].text);96 });97 it('should change badge after an option is selected', async () => {98 const uncontrolledProps = { selectedId: undefined };99 const { driver, badgeDriver } = createComponent(uncontrolledProps);100 const selectedIndex = 3;101 await driver.clickAtOption(selectedIndex);102 expect(await badgeDriver.getSkin()).toBe(options[selectedIndex].skin);103 expect(await badgeDriver.text()).toBe(options[selectedIndex].text);104 });105 });106 describe('controlled mode', () => {107 it('should not change badge after an option is selected', async () => {108 const { driver, badgeDriver } = createComponent();109 const selectedIndex = 3;110 await driver.clickAtOption(selectedIndex);111 expect(await badgeDriver.getSkin()).toBe(options[initialOptionId].skin);112 expect(await badgeDriver.text()).toBe(options[initialOptionId].text);113 });114 it('should change badge only on selectedIndex change', async () => {115 const dataHook = 'badge-select';116 const { driver, rerender } = render(117 <BadgeSelect118 selectedId={'0'}119 dataHook={dataHook}120 options={options}121 />,122 );123 const selectedIndex = 3;124 await driver.driver.clickAtOption(selectedIndex);125 rerender(126 <BadgeSelect127 selectedId={`${selectedIndex}`}128 dataHook={dataHook}129 options={options}130 />,131 );132 expect(await driver.badgeDriver.getSkin()).toBe(133 options[selectedIndex].skin,134 );135 expect(await driver.badgeDriver.text()).toBe(136 options[selectedIndex].text,137 );138 });139 });140 }...
drag-e2e-specs.js
Source:drag-e2e-specs.js
...71 });72 it('should drag by absolute position', async () => {73 let startEle = await driver.findElement("id", "io.appium.android.apis:id/drag_dot_3");74 let startLoc = await driver.getLocationInView(startEle.ELEMENT);75 let startSize = await driver.getSize(startEle.ELEMENT);76 let endEle = await driver.findElement("id", "io.appium.android.apis:id/drag_dot_2");77 let endLoc = await driver.getLocationInView(endEle.ELEMENT);78 let endSize = await driver.getSize(endEle.ELEMENT);79 let gestures = [{action: "longPress",80 options: {x: startLoc.x + (startSize.width / 2),81 y: startLoc.y + (startSize.height / 2)}},82 {action: "moveTo",83 options: {x: endLoc.x + (endSize.width / 2),84 y: endLoc.y + (endSize.height / 2)}},85 {action: "release", options: {}}];86 await driver.performTouch(gestures);87 let resultEle = await driver.findElement("id", "io.appium.android.apis:id/drag_result_text");88 await driver.getText(resultEle.ELEMENT).should.eventually.equal("Dropped!");89 });90 });...
Badge.spec.js
Source:Badge.spec.js
...55 });56 describe('size prop', () => {57 it('should be medium by default', async () => {58 const driver = createDriver(<Badge>Hello</Badge>);59 expect(await driver.getSize()).toBe(SIZE.medium);60 });61 Object.keys(SIZE).forEach(size => {62 it(`should be ${size}`, async () => {63 const driver = createDriver(<Badge size={size}>Hello</Badge>);64 expect(await driver.getSize()).toBe(size);65 });66 });67 });68 describe('onClick prop', () => {69 it('cursor should be default when no onClick', async () => {70 const driver = createDriver(<Badge>Hello</Badge>);71 expect(await driver.hasClickCursor()).toBe(false);72 });73 it('cursor should be pointer when onClick set', async () => {74 const driver = createDriver(<Badge onClick={e => e}>Hello</Badge>);75 expect(await driver.hasClickCursor()).toBe(true);76 });77 it('should call event handler on badge click', async () => {78 const handler = jest.fn();...
Text.spec.js
Source:Text.spec.js
...19 function runTests(render) {20 describe('size prop', () => {21 it(`should be ${SIZES.medium} by default`, async () => {22 const { driver } = render(<Text>Hello</Text>);23 expect(await driver.getSize()).toBe(SIZES.medium);24 });25 Object.keys(SIZES).forEach(size => {26 it(`should be ${size}`, async () => {27 const { driver } = render(<Text size={size}>Hello</Text>);28 expect(await driver.getSize()).toBe(size);29 });30 });31 });32 describe('weight prop', () => {33 it(`should be ${WEIGHTS.thin} by default`, async () => {34 const { driver } = render(<Text>Hello</Text>);35 expect(await driver.getWeight()).toBe(WEIGHTS.thin);36 });37 Object.keys(WEIGHTS).forEach(weight => {38 it(`should be ${weight}`, async () => {39 const { driver } = render(<Text weight={weight}>Hello</Text>);40 expect(await driver.getWeight()).toBe(weight);41 });42 });...
CircularProgressBar.spec.js
Source:CircularProgressBar.spec.js
...65 it(`should be ${size}`, async () => {66 const { driver } = render(67 createCircularProgressBar({ ...defaultProps, size: size }),68 );69 expect(await driver.getSize()).toBe(size);70 });71 });72 it(`should be default ${Size.medium}`, async () => {73 const { driver } = render(74 createCircularProgressBar({ ...defaultProps }),75 );76 expect(await driver.getSize()).toBe(Size.medium);77 });78 });79 }...
element-specs.js
Source:element-specs.js
1import { IosDriver } from '../../lib/driver';2import { uiauto } from '../..';3import chai from 'chai';4import sinon from 'sinon';5chai.should();6chai.expect();7let expect = chai.expect;8describe('content size', function () {9 let driver;10 beforeEach(function () {11 driver = new IosDriver();12 driver.uiAutoClient = new uiauto.UIAutoClient();13 });14 it('should be null for wrong element type', async function () {15 sinon.stub(driver.uiAutoClient, 'sendCommand').returns([]);16 sinon.stub(driver, 'getName').returns('UIAButton');17 let result = await driver.getElementContentSize('0');18 expect(result).to.be.null;19 });20 it('should return correct size for UIATableView', async function () {21 sinon.stub(driver.uiAutoClient, 'sendCommand').returns([{22 origin: {23 x: 0, y: 024 },25 size: {26 width: 320, height: 100027 }28 }, {29 origin: {30 x: 0, y: 100031 },32 size: {33 width: 320, height: 100034 }35 }]);36 sinon.stub(driver, 'getName').returns('UIATableView');37 sinon.stub(driver, 'getSize').returns({width: 320, height: 548});38 sinon.stub(driver, 'getLocationInView').returns({x: 0, y: 20});39 let contentSize = JSON.parse(await driver.getElementContentSize('0'));40 contentSize.left.should.equal(0);41 contentSize.top.should.equal(20);42 contentSize.width.should.equal(320);43 contentSize.height.should.equal(548);44 contentSize.scrollableOffset.should.equal(2000);45 });46 it('should return correct size for UIACollectionView', async function () {47 sinon.stub(driver.uiAutoClient, 'sendCommand').returns([{origin: {x: 0, y: 44}, size: {width: 100, height: 500}},48 {origin: {x: 110, y: 44}, size: {width: 100, height: 500}},49 {origin: {x: 220, y: 44}, size: {width: 100, height: 500}},50 {origin: {x: 0, y: 554}, size: {width: 100, height: 500}},51 {origin: {x: 110, y: 554}, size: {width: 100, height: 500}},52 {origin: {x: 220, y: 554}, size: {width: 100, height: 500}}]);53 sinon.stub(driver, 'getName').returns('UIACollectionView');54 sinon.stub(driver, 'getSize').returns({width: 320, height: 524});55 sinon.stub(driver, 'getLocationInView').returns({x: 0, y: 44});56 let contentSize = JSON.parse(await driver.getElementContentSize('0'));57 contentSize.left.should.equal(0);58 contentSize.top.should.equal(44);59 contentSize.width.should.equal(320);60 contentSize.height.should.equal(524);61 contentSize.scrollableOffset.should.equal(1010);62 });...
ToggleSwitch.spec.js
Source:ToggleSwitch.spec.js
...27 });28 describe('size prop', () => {29 it('should be "large" by default', async () => {30 const { driver } = render(<ToggleSwitch />);31 expect(await driver.getSize()).toBe(SIZES.large);32 });33 Object.values(SIZES).forEach(size => {34 it(`should be "${size}"`, async () => {35 const { driver } = render(<ToggleSwitch size={size} />);36 expect(await driver.getSize()).toBe(size);37 });38 });39 });40 describe('skin prop', () => {41 it('should be "standard" by default', async () => {42 const { driver } = render(<ToggleSwitch />);43 expect(await driver.getSkin()).toBe(SKINS.standard);44 });45 Object.values(SKINS).forEach(skin => {46 it(`should be "${skin}"`, async () => {47 const { driver } = render(<ToggleSwitch skin={skin} />);48 expect(await driver.getSkin()).toBe(skin);49 });50 });...
InfoIcon.spec.js
Source:InfoIcon.spec.js
...23 });24 describe('size prop', () => {25 it('should have default value "medium"', async () => {26 const { driver } = render(createInfoIcon());27 expect(await driver.getSize()).toBe('medium');28 });29 it('should set value to "medium"', async () => {30 const { driver } = render(createInfoIcon({ size: 'medium' }));31 expect(await driver.getSize()).toBe('medium');32 });33 it('should set value to "small"', async () => {34 const { driver } = render(createInfoIcon({ size: 'small' }));35 expect(await driver.getSize()).toBe('small');36 });37 });...
Using AI Code Generation
1var webdriver = require('selenium-webdriver'),2 until = webdriver.until;3var driver = new webdriver.Builder()4 .forBrowser('chrome')5 .build();6driver.findElement(By.name('q')).sendKeys('webdriver');7driver.findElement(By.name('btnG')).click();8driver.wait(until.titleIs('webdriver - Google Search'), 1000);9driver.quit();10driver.manage().window().getSize().then(function(size) {11 console.log(size);12 driver.quit();13});14var webdriver = require('selenium-webdriver'),15 until = webdriver.until;16var driver = new webdriver.Builder()17 .forBrowser('chrome')18 .build();19driver.findElement(By.name('q')).sendKeys('webdriver');20driver.findElement(By.name('btnG')).click();21driver.wait(until.titleIs('webdriver - Google Search'), 1000);22driver.quit();23driver.manage().window().getSize().then(function(size) {24 console.log(size);25 driver.quit();26});27var webdriver = require('selenium-webdriver'),28 until = webdriver.until;29var driver = new webdriver.Builder()30 .forBrowser('chrome')31 .build();32driver.findElement(By.name('q')).sendKeys('webdriver');33driver.findElement(By.name('btnG')).click();34driver.wait(until.titleIs('webdriver - Google Search'), 1000);35driver.quit();36driver.manage().window().getSize().then(function(size) {37 console.log(size);38 driver.quit();39});40var webdriver = require('selenium-webdriver'),41 until = webdriver.until;42var driver = new webdriver.Builder()43 .forBrowser('chrome')44 .build();45driver.findElement(By.name('q')).sendKeys
Using AI Code Generation
1var webdriver = require('selenium-webdriver');2var driver = new webdriver.Builder()3 .withCapabilities(webdriver.Capabilities.android())4 .build();5driver.getSize().then(function(size) {6 console.log(size);7});8driver.quit();9{ width: 480, height: 800 }
Using AI Code Generation
1var driver = new webdriver.Builder()2 .forBrowser('android')3 .build();4driver.getSize().then(function(size) {5 console.log(size);6});7driver.quit();8{ width: 1440, height: 2560 }
Using AI Code Generation
1var wd = require('wd');2var desired = {3};4var driver = wd.promiseChainRemote('localhost', 4723);5 .init(desired)6 .setImplicitWaitTimeout(5000)7 .elementByTagName('body')8 .getSize()9 .then(function (size) {10 console.log('size: ' + JSON.stringify(size));11 })12 .fin(function () { return driver.quit(); })13 .done();14var wd = require('wd');15var desired = {16};17var driver = wd.promiseChainRemote('localhost', 4723);18 .init(desired)19 .setImplicitWaitTimeout(5000)20 .elementByTagName('body')21 .getSize()22 .then(function (size) {23 console.log('size: ' + JSON.stringify(size));24 })25 .fin(function () { return driver.quit(); })26 .done();27var wd = require('wd');28var desired = {29};30var driver = wd.promiseChainRemote('localhost', 4723);31 .init(desired)
Using AI Code Generation
1var webdriver = require('appium-android-driver');2var driver = new webdriver.Driver();3driver.getSize().then(function(size) {4 console.log("Screen size is ", size);5});6driver.getSize().then(function(size) {7 console.log("Screen width is ", size.width);8});9driver.getSize().then(function(size) {10 console.log("Screen height is ", size.height);11});
Using AI Code Generation
1import wd from 'wd';2import {assert} from 'chai';3describe('Test', function () {4 this.timeout(300000);5 let driver;6 before(async () => {7 await driver.init({
Using AI Code Generation
1var wd = require('wd');2var assert = require('assert');3var desiredCaps = {4};5var driver = wd.promiseChainRemote('localhost', 4723);6 .init(desiredCaps)7 .then(function() {8 return driver.getSize();9 })10 .then(function(size) {11 console.log(size);12 })13 .fin(function() {14 return driver.quit();15 })16 .done();17var wd = require('wd');18var assert = require('assert');19var desiredCaps = {20};21var driver = wd.promiseChainRemote('localhost', 4723);22 .init(desiredCaps)23 .then(function() {24 return driver.getDeviceTime();25 })26 .then(function(deviceTime) {27 console.log(deviceTime);28 })29 .fin(function() {30 return driver.quit();31 })32 .done();33var wd = require('wd');34var assert = require('assert');35var desiredCaps = {36};37var driver = wd.promiseChainRemote('localhost', 4723);38 .init(desiredCaps)39 .then(function() {40 return driver.getNetworkConnection();41 })42 .then(function(networkConnection) {43 console.log(networkConnection);44 })45 .fin(function() {46 return driver.quit();47 })48 .done();49var wd = require('wd');50var assert = require('assert');
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!!