How to use _press method in uiautomator

Best Python code snippet using uiautomator

Menu-test.js

Source:Menu-test.js Github

copy

Full Screen

...40 component.props.onPress(); // simulate press on component41};42const _toggleSubmenu = (treeRoot) => {43 const navToggle = treeRoot.findByType(NavToggle);44 _press(navToggle);45};46const mockImportedDocument = {47 name: 'test.csv',48 size: 64,49 type: 'success',50 uri: 'file:///data/user/0/host.exp.exponent/cache/ExperienceData/%2540mbezhanov%252Fmotivate/DocumentPicker/9e018921-301a-4c0b-9869-f69db3ed760fcsv'51};52describe('Menu', () => {53 let tree;54 let navigation;55 const quote = { id: 123, content: 'foo', author: 'bar', book: 'baz' };56 const onDelete = jest.fn();57 const onSuccessfulImport = jest.fn();58 beforeEach(() => {59 navigation = { push: jest.fn() };60 tree = renderer.create(61 <Menu62 navigation={navigation}63 quote={quote}64 onDelete={onDelete}65 onSuccessfulImport={onSuccessfulImport}66 />67 );68 Csv.importQuotes.mockClear();69 Alert.alert.mockClear();70 });71 it('renders correctly', () => {72 expect(tree.toJSON()).toMatchSnapshot();73 });74 it('displays all hidden submenu items when the nav toggle switch is pressed', () => {75 const a = tree.toJSON();76 const navToggle = tree.root.findByType(NavToggle);77 _press(navToggle);78 const b = tree.toJSON();79 const diff = snapshotDiff(a, b);80 expect(diff).toMatchSnapshot();81 });82 it('hides all displayed submenu items when the nav toggle switch is pressed', () => {83 const navToggle = tree.root.findByType(NavToggle);84 _press(navToggle); // open submenu items85 const a = tree.toJSON();86 _press(navToggle); // close submenu items87 const b = tree.toJSON();88 const diff = snapshotDiff(a, b);89 expect(diff).toMatchSnapshot();90 });91 it('lets the user pick a document when an import is requested', async () => {92 DocumentPicker.getDocumentAsync.mockResolvedValueOnce(mockImportedDocument);93 Csv.importQuotes.mockResolvedValueOnce(123);94 _toggleSubmenu(tree.root);95 const a = tree.toJSON();96 const importButton = tree.root.findByProps({ label: 'Import' });97 await _press(importButton);98 expect(DocumentPicker.getDocumentAsync).toBeCalledTimes(1);99 const b = tree.toJSON();100 const diff = snapshotDiff(a, b);101 expect(diff).toMatchSnapshot();102 });103 it('directly delegates control to the CSV service if the database is empty', async () => {104 tree = renderer.create(105 <Menu106 navigation={navigation}107 quote={null}108 onDelete={onDelete}109 onSuccessfulImport={onSuccessfulImport}110 />111 );112 DocumentPicker.getDocumentAsync.mockResolvedValueOnce(mockImportedDocument);113 Csv.importQuotes.mockResolvedValueOnce(123);114 _toggleSubmenu(tree.root);115 const importButton = tree.root.findByProps({ label: 'Import' });116 await _press(importButton);117 expect(Csv.importQuotes).toBeCalledTimes(1);118 });119 it('asks the user whether new quotes should be appended to or overwrite the existing collection, if the database is not empty', async () => {120 _toggleSubmenu(tree.root);121 DocumentPicker.getDocumentAsync.mockResolvedValueOnce(mockImportedDocument);122 Csv.importQuotes.mockResolvedValueOnce(123);123 const importButton = tree.root.findByProps({ label: 'Import' });124 await _press(importButton);125 expect(Alert.alert).toBeCalledTimes(1);126 expect(Alert.alert.mock.calls[0][2][0].text).toEqual('Overwrite');127 expect(Alert.alert.mock.calls[0][2][1].text).toEqual('Append');128 });129 it('can instruct the Csv service to overwrite the existing collection', async () => {130 _toggleSubmenu(tree.root);131 DocumentPicker.getDocumentAsync.mockResolvedValueOnce(mockImportedDocument);132 Csv.importQuotes.mockResolvedValueOnce(123);133 const importButton = tree.root.findByProps({ label: 'Import' });134 await _press(importButton);135 Alert.alert.mock.calls[0][2][0].onPress();136 expect(Csv.importQuotes).toBeCalledTimes(1);137 expect(Csv.importQuotes.mock.calls[0][0]).toEqual(mockImportedDocument.uri);138 expect(Csv.importQuotes.mock.calls[0][1]).toEqual(IMPORT_MODE_OVERWRITE);139 });140 it('can instruct the Csv service to append new quotes to the existing collection', async () => {141 _toggleSubmenu(tree.root);142 DocumentPicker.getDocumentAsync.mockResolvedValueOnce(mockImportedDocument);143 Csv.importQuotes.mockResolvedValueOnce(123);144 const importButton = tree.root.findByProps({ label: 'Import' });145 await _press(importButton);146 Alert.alert.mock.calls[0][2][1].onPress();147 expect(Csv.importQuotes).toBeCalledTimes(1);148 expect(Csv.importQuotes.mock.calls[0][0]).toEqual(mockImportedDocument.uri);149 expect(Csv.importQuotes.mock.calls[0][1]).toEqual(IMPORT_MODE_APPEND);150 });151 it('delegates control to the CSV service when an export is requested', async () => {152 Csv.exportQuotes.mockResolvedValueOnce(123);153 const a = tree.toJSON();154 const exportButton = tree.root.findByProps({ label: 'Export' });155 await _press(exportButton);156 const b = tree.toJSON();157 const diff = snapshotDiff(a, b);158 expect(Alert.alert).toBeCalledTimes(1);159 expect(Alert.alert.mock.calls[0][0]).toEqual('Success');160 expect(Alert.alert.mock.calls[0][1].indexOf('123')).not.toEqual(-1);161 expect(diff).toMatchSnapshot();162 });163 it('displays an error message if the CSV export fails', async () => {164 Csv.exportQuotes.mockRejectedValueOnce();165 const exportButton = tree.root.findByProps({ label: 'Export' });166 await _press(exportButton);167 expect(Alert.alert).toBeCalledTimes(1);168 expect(Alert.alert.mock.calls[0][0]).toEqual('Error');169 });170 it('navigates to the Form screen when the insertion of a new quote is requested', () => {171 const addButton = tree.root.findByProps({ label: 'Add' });172 _press(addButton);173 expect(navigation.push).toBeCalledTimes(1);174 expect(navigation.push.mock.calls[0][0]).toEqual('Form');175 });176 it('navigates to the Form screen when the update of an existing quote is requested', () => {177 const editButton = tree.root.findByProps({ label: 'Edit' });178 _press(editButton);179 expect(navigation.push).toBeCalledTimes(1);180 expect(navigation.push.mock.calls[0][0]).toEqual('Form');181 expect(navigation.push.mock.calls[0][1].quote).toEqual(quote);182 });183 it('asks the user for confirming the intention of deleting a particular quote', () => {184 const deleteButton = tree.root.findByProps({ label: 'Delete' });185 _press(deleteButton);186 expect(Alert.alert).toBeCalledTimes(1);187 expect(Alert.alert.mock.calls[0][0].indexOf('Delete')).not.toEqual(-1);188 });189 it('raises an event if the user confirms the intention of deleting a particular quote', () => {190 const deleteButton = tree.root.findByProps({ label: 'Delete' });191 _press(deleteButton);192 expect(Alert.alert).toBeCalledTimes(1);193 const okButton = Alert.alert.mock.calls[0][2][0];194 okButton.onPress();195 expect(onDelete).toBeCalledTimes(1);196 });...

Full Screen

Full Screen

commands.js

Source:commands.js Github

copy

Full Screen

...21 this.key = this.inputHandler.getKey;22 this.key.press = this._press.bind(this);23 this.key.release = this._release.bind(this);24 }25 _press() {26 console.log('BTN IS PRESSED');27 }28 29 _release() {30 console.log('BTN IS RELEASED');31 }32}33// this.carSpeed += DRIVE_POWER;34export class UpCommand extends Command { 35 constructor(inputHandler, state) {36 super(inputHandler);37 this.state = state;38 }39 40 _press() {41 this.trigger({ name: 'forward', speed: this.state.speed });42 }43 _release() {44 this.trigger({ name: 'forward', speed: 0 });45 }46}47// this.carSpeed -= REVERSE_POWER;48export class DownCommand extends Command { 49 constructor(inputHandler, state) {50 super(inputHandler);51 this.state = state;52 }53 54 _press() {55 this.trigger({ name: 'back', speed: this.state.speed * -1 });56 }57 58 _release() {59 this.trigger({ name: 'back', speed: 0 });60 }61}62 63// this.carAng -= TURN_RATE*Math.PI;64export class LeftCommand extends Command { 65 constructor(inputHandler, state) {66 super(inputHandler);67 this.state = state;68 }69 _press() {70 this.trigger({ name: 'turnLeft', angle: (this.state.TURN_RATE * Math.PI) * -1 });71 }72 _release() {73 this.trigger({ name: 'turnLeft', angle: 0 });74 }75}76 77// this.carAng += TURN_RATE*Math.PI;78export class RightCommand extends Command { 79 constructor(inputHandler, state) {80 super(inputHandler);81 this.state = state;82 }83 84 _press() {85 this.trigger({ name: 'turnRight', angle: this.state.TURN_RATE * Math.PI });86 }87 88 _release() {89 this.trigger({ name: 'turnRight', angle: 0 });90 }91}92 93export class ShotCommand extends Command { 94 constructor(inputHandler, state) {95 super(inputHandler);96 this.state = state;97 }98 _press() {99 this.trigger({ name: 'shot' });100 }101 _release() {}102}103 104export class FlashCommand extends Command { 105 constructor(inputHandler, state) {106 super(inputHandler);107 this.state = state;108 }109 110 _press() {111 this.trigger({ name: 'flash' });112 }113 114 _release() {115 }116}117// // this.carSpeed += DRIVE_POWER;118// export class UpCommand extends Command { 119// constructor(inputHandler, state) {120// super(inputHandler);121// this.state = state;122// }123 124// _press() {125// this.state.direction = 'up';126// this.state.currDirection = { x: 0, y: -1 };127// this.state.rotateDegree = 0;128// this.trigger({ name: 'direction', x: 0, y: this.state.speed * -1 });129// }130// _release() {131// if (this.state.direction != 'down' && this.state.fighter.fighterContainer.vx === 0) {132// this.trigger({ name: 'direction', x: 0, y: 0 });133// }134// }135// }136// // this.carSpeed -= REVERSE_POWER;137// export class DownCommand extends Command { 138// constructor(inputHandler, state) {139// super(inputHandler);140// this.state = state;141// }142 143// _press() {144// this.state.direction = "down";145// this.state.currDirection = { x: 0, y: 1 };146// this.state.rotateDegree = 3.2;147// this.trigger({ name: 'direction', x: 0, y: this.state.speed });148// }149 150// _release() {151// if (this.state.direction != 'up' && this.state.fighter.fighterContainer.vx === 0) {152// this.trigger({ name: 'direction', x: 0, y: 0 });153// }154// }155// }156 157// // this.carAng -= TURN_RATE*Math.PI;158// export class LeftCommand extends Command { 159// constructor(inputHandler, state) {160// super(inputHandler);161// this.state = state;162// }163// _press() {164// this.state.direction = "left";165// this.state.currDirection = { x: -1, y: 0 };166// this.state.rotateDegree = -1.6;167// this.trigger({ name: 'direction', x: this.state.speed * -1, y: 0 });168// }169// _release() {170// if (this.state.direction != 'right' && this.state.fighter.fighterContainer.vy === 0) {171// this.trigger({ name: 'direction', x: 0, y: 0 });172// }173// }174// }175 176// // this.carAng += TURN_RATE*Math.PI;177// export class RightCommand extends Command { 178// constructor(inputHandler, state) {179// super(inputHandler);180// this.state = state;181// }182 183// _press() {184// this.state.direction = "right";185// this.state.currDirection = { x: 1, y: 0 };186// this.state.rotateDegree = 1.6;187// this.trigger({ name: 'direction', x: this.state.speed, y: 0 });;188// }189 190// _release() {191// if (this.state.direction != 'left' && this.state.fighter.fighterContainer.vy === 0) {192// this.trigger({ name: 'direction', x: 0, y: 0 });193// }194// }...

Full Screen

Full Screen

UiesScreen.test.js

Source:UiesScreen.test.js Github

copy

Full Screen

1import renderer from 'react-test-renderer'2import React from 'react'3import {Text, Button, Image} from 'react-native'4import UiesScreen from "../js/screen/UiesScreen";5import {shallow} from "enzyme";6import TestImage from "../js/component/TestImage";7describe('test Ui Screen', () => {8 test('check has one <Text/> child', ()=> {9 const wrapper = shallow(<UiesScreen/>)10 expect(wrapper.find(Text).length).toBe(1)11 })12 test('check text in screen', () => {13 const wrapper = shallow(<UiesScreen title="san" imageName={null} onPress={null}/>)14 expect(wrapper.instance().props.title).toBe('san')15 })16 test('check the click event: approach 1', ()=>{17 let num = 018 let _press = () => num++19 const wrapper = shallow(<UiesScreen title="san" imageName={null} onPress={_press}/>)20 wrapper.simulate('press')21 expect(num).toBe(1)22 })23 test('check the click event: approach 2', ()=>{24 let _press = jest.fn()25 const wrapper = shallow(<UiesScreen title="san" imageName={null} onPress={_press}/>)26 wrapper.simulate('press')27 expect(_press).toBeCalled()28 })29 test('check set state/props methods', ()=>{30 let _press = jest.fn()31 const wrapper = shallow(<UiesScreen/>)32 wrapper.setProps({title: "23", imageName: null, onPress: _press})33 let textView = wrapper.find(Text).getElement() //=> {"key":null,"ref":null,"props":{"children":"23"},"_owner":null,"_store":{}}34 expect(textView.props.children).toBe('23')35 })36 test('check the method to get state', ()=> {37 let _press = jest.fn()38 const wrapper = shallow(<UiesScreen title="san" imageName={null} onPress={_press}/>)39 expect(wrapper.state()).toEqual({num: 10})40 // 或是用 " expect(wrapper.state('num')).toEqual(10) "41 })42 test('check the simulate method', ()=> {43 let _press = jest.fn()44 const wrapper = shallow(<UiesScreen title="san" imageName={null} onPress={_press}/>)45 wrapper.find(Button).simulate('kiss')46 expect(wrapper.state('num')).toEqual(13)47 })48 test('check has one <Image/> child', ()=> {49 const wrapper = shallow(<UiesScreen/>)50 // console.log("dive() : " + wrapper.debug())51 expect(wrapper.find(TestImage).dive().find(Image).length).toBe(1)52 })53 test('check two Image exist', ()=> {54 const wrapper = shallow(<UiesScreen/>)55 expect(wrapper.find(Image).length).toBe(2)56 })57 test('check two Images with source propers exist', ()=> {58 const wrapper = shallow(<UiesScreen/>)59 expect(wrapper.findWhere(n => n.prop('source')!== undefined).length).toBe(2)60 })61 test('check Image with source=1 exist', ()=> {62 const wrapper = shallow(<UiesScreen/>)63 expect(wrapper.findWhere(n => n.prop('source') === 1).length).toBe(1)64 })65 test('check Image with source=3 does not exist', ()=> {66 const wrapper = shallow(<UiesScreen/>)67 expect(wrapper.findWhere(n => n.prop('source') === 3).length).toBe(0)68 })...

Full Screen

Full Screen

MenuTop.js

Source:MenuTop.js Github

copy

Full Screen

...41 <StatusBar backgroundColor={primary} barStyle="light-content" />42 <View style={styles.container}>43 <TouchableOpacity44 style={styles.menu}45 onPress={() => _press()}46 accessibilityLabel="Voltar">47 <Icone style={styles.configItem} name={iconemenu} size={28} />48 </TouchableOpacity>49 <Image50 source={icone}51 style={{ width: 40, height: 40, marginHorizontal: 10 }}52 />53 <Text style={[styless.textoG, styless.white]}>{title}</Text>54 {!!btnEsquerdo && (55 <TouchableOpacity56 style={[{ position: "absolute", right: 10 }]}57 onPress={_handlerOpemConfig}>58 {!!btnEsquerdo && btnEsquerdo}59 </TouchableOpacity>...

Full Screen

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 uiautomator 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