-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Highlight elements that user searched for #344
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,19 +58,42 @@ export default class AppiumMethodHandler { | |
return {variableName, variableType, strategy, selector, elements}; | ||
} | ||
|
||
async executeElementCommand (elementId, methodName, args = []) { | ||
const cachedEl = this.elementCache[elementId]; | ||
async _execute ({elementId, methodName, args, skipScreenshotAndSource}) { | ||
let cachedEl; | ||
let res = {}; | ||
|
||
// Give the cached element a variable name (el1, el2, el3,...) the first time it's used | ||
if (!cachedEl.variableName && cachedEl.variableType === 'string') { | ||
cachedEl.variableName = `el${this.elVariableCounter++}`; | ||
if (elementId) { | ||
// Give the cached element a variable name (el1, el2, el3,...) the first time it's used | ||
cachedEl = this.elementCache[elementId]; | ||
if (!cachedEl.variableName && cachedEl.variableType === 'string') { | ||
cachedEl.variableName = `el${this.elVariableCounter++}`; | ||
} | ||
res = await cachedEl.el[methodName].apply(cachedEl.el, args); | ||
} else { | ||
// Specially handle the tap and swipe method | ||
if (methodName === 'tap') { | ||
res = await (new wd.TouchAction(this.driver)) | ||
.tap({x: args[0], y: args[1]}) | ||
.perform(); | ||
} else if (methodName === 'swipe') { | ||
const [startX, startY, endX, endY] = args; | ||
res = await (new wd.TouchAction(this.driver)) | ||
.press({x: startX, y: startY}) | ||
.moveTo({x: endX, y: endY}) | ||
.release() | ||
.perform(); | ||
} else if (methodName !== 'source' && methodName !== 'screenshot') { | ||
res = await this.driver[methodName].apply(this.driver, args); | ||
} | ||
} | ||
const res = await cachedEl.el[methodName].apply(cachedEl.el, args); | ||
|
||
// Give the source/screenshot time to change before taking the screenshot | ||
await Bluebird.delay(500); | ||
|
||
let sourceAndScreenshot = await this._getSourceAndScreenshot(); | ||
let sourceAndScreenshot; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume an empty array should be assigned to this variable by default since we apply ellipsis operator to it later There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When you pass |
||
if (!skipScreenshotAndSource) { | ||
sourceAndScreenshot = await this._getSourceAndScreenshot(); | ||
} | ||
|
||
return { | ||
...sourceAndScreenshot, | ||
|
@@ -79,34 +102,12 @@ export default class AppiumMethodHandler { | |
}; | ||
} | ||
|
||
async executeMethod (methodName, args = []) { | ||
let res = {}; | ||
|
||
// Specially handle the tap and swipe method | ||
if (methodName === 'tap') { | ||
res = await (new wd.TouchAction(this.driver)) | ||
.tap({x: args[0], y: args[1]}) | ||
.perform(); | ||
} else if (methodName === 'swipe') { | ||
const [startX, startY, endX, endY] = args; | ||
res = await (new wd.TouchAction(this.driver)) | ||
.press({x: startX, y: startY}) | ||
.moveTo({x: endX, y: endY}) | ||
.release() | ||
.perform(); | ||
} else if (methodName !== 'source' && methodName !== 'screenshot') { | ||
res = await this.driver[methodName].apply(this.driver, args); | ||
} | ||
|
||
// Give the source/screenshot time to change before taking the screenshot | ||
await Bluebird.delay(500); | ||
|
||
let sourceAndScreenshot = await this._getSourceAndScreenshot(); | ||
async executeElementCommand (elementId, methodName, args = [], skipScreenshotAndSource = false) { | ||
return await this._execute({elementId, methodName, args, skipScreenshotAndSource}); | ||
} | ||
|
||
return { | ||
...sourceAndScreenshot, | ||
res, | ||
}; | ||
async executeMethod (methodName, args = [], skipScreenshotAndSource = false) { | ||
return await this._execute({methodName, args, skipScreenshotAndSource}); | ||
} | ||
|
||
async _getSourceAndScreenshot () { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ import { ipcRenderer } from 'electron'; | |
import { notification } from 'antd'; | ||
import { push } from 'react-router-redux'; | ||
import _ from 'lodash'; | ||
import B from 'bluebird'; | ||
import { getLocators } from '../components/Inspector/shared'; | ||
import { showError } from './Session'; | ||
import { callClientMethod } from './shared'; | ||
|
@@ -46,11 +47,14 @@ export const CLEAR_SEARCH_RESULTS = 'CLEAR_SEARCH_RESULTS'; | |
export const ADD_ASSIGNED_VAR_CACHE = 'ADD_ASSIGNED_VAR_CACHE'; | ||
export const CLEAR_ASSIGNED_VAR_CACHE = 'CLEAR_ASSIGNED_VAR_CACHE'; | ||
export const SET_SCREENSHOT_INTERACTION_MODE = 'SET_SCREENSHOT_INTERACTION_MODE'; | ||
export const SET_SEARCHED_FOR_ELEMENT_BOUNDS = 'SET_SEARCHED_FOR_ELEMENT_BOUNDS'; | ||
export const CLEAR_SEARCHED_FOR_ELEMENT_BOUNDS = 'CLEAR_SEARCHED_FOR_ELEMENT_BOUNDS'; | ||
|
||
export const SET_SWIPE_START = 'SET_SWIPE_START'; | ||
export const SET_SWIPE_END = 'SET_SWIPE_END'; | ||
export const CLEAR_SWIPE_ACTION = 'CLEAR_SWIPE_ACTION'; | ||
|
||
|
||
// Attributes on nodes that we know are unique to the node | ||
const uniqueAttributes = [ | ||
'name', | ||
|
@@ -335,6 +339,7 @@ export function showLocatorTestModal () { | |
export function hideLocatorTestModal () { | ||
return (dispatch) => { | ||
dispatch({type: HIDE_LOCATOR_TEST_MODAL}); | ||
dispatch({type: CLEAR_SEARCHED_FOR_ELEMENT_BOUNDS}); | ||
}; | ||
} | ||
|
||
|
@@ -377,11 +382,19 @@ export function findAndAssign (strategy, selector, variableName, isArray) { | |
}; | ||
} | ||
|
||
|
||
// TODO: Is this obsolete? I don't think we use this. | ||
export function setLocatorTestElement (elementId) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't this function be also defined as async? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The function that is returned within it is |
||
return (dispatch) => { | ||
return async (dispatch) => { | ||
dispatch({type: SET_LOCATOR_TEST_ELEMENT, elementId}); | ||
dispatch({type: CLEAR_SEARCHED_FOR_ELEMENT_BOUNDS}); | ||
if (elementId) { | ||
try { | ||
const [location, size] = await(B.all([ | ||
callClientMethod({methodName: 'getLocation', args: [elementId], skipScreenshotAndSource: true, skipRecord: true}), | ||
callClientMethod({methodName: 'getSize', args: [elementId], skipScreenshotAndSource: true, skipRecord: true}), | ||
])); | ||
dispatch({type: SET_SEARCHED_FOR_ELEMENT_BOUNDS, location: location.res, size: size.res}); | ||
} catch (ign) { } | ||
} | ||
}; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can use
_.isString
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
variableType
is a hard-coded string that identifies what type the element is. It's used by the RecordedActions component which displays recorded code and it uses the variableType to determine if it should beel.text("String")
orel.text(123)
etc...