-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Highlight elements that user searched for #344
Changes from 5 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,7 +58,7 @@ export default class AppiumMethodHandler { | |
return {variableName, variableType, strategy, selector, elements}; | ||
} | ||
|
||
async executeElementCommand (elementId, methodName, args = []) { | ||
async executeElementCommand (elementId, methodName, args = [], skipScreenshot = false) { | ||
const cachedEl = this.elementCache[elementId]; | ||
|
||
// Give the cached element a variable name (el1, el2, el3,...) the first time it's used | ||
|
@@ -70,7 +70,10 @@ export default class AppiumMethodHandler { | |
// Give the source/screenshot time to change before taking the screenshot | ||
await Bluebird.delay(500); | ||
|
||
let sourceAndScreenshot = await this._getSourceAndScreenshot(); | ||
let sourceAndScreenshot; | ||
if (!skipScreenshot) { | ||
sourceAndScreenshot = await this._getSourceAndScreenshot(); | ||
} | ||
|
||
return { | ||
...sourceAndScreenshot, | ||
|
@@ -79,7 +82,7 @@ export default class AppiumMethodHandler { | |
}; | ||
} | ||
|
||
async executeMethod (methodName, args = []) { | ||
async executeMethod (methodName, args = [], skipScreenshot = false) { | ||
let res = {}; | ||
|
||
// Specially handle the tap and swipe method | ||
|
@@ -101,7 +104,11 @@ export default class AppiumMethodHandler { | |
// 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. can we avoid code duplication here? 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. Yeah I'll make it so there's one main method. |
||
|
||
if (!skipScreenshot) { | ||
sourceAndScreenshot = await this._getSourceAndScreenshot(); | ||
} | ||
|
||
return { | ||
...sourceAndScreenshot, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -301,6 +301,7 @@ function connectClientMethodListener () { | |
fetchArray = false, // Optional. Are we fetching an array of elements or just one? | ||
elementId, // Optional. Element being operated on | ||
args = [], // Optional. Arguments passed to method | ||
skipScreenshot = false, // Optional. Do we want the updated source and screenshot? | ||
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. perhaps, we can select better name for this variable if it also affects source update? 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. Good call |
||
} = data; | ||
|
||
let renderer = evt.sender; | ||
|
@@ -322,15 +323,15 @@ function connectClientMethodListener () { | |
if (methodName) { | ||
if (elementId) { | ||
console.log(`Handling client method request with method '${methodName}', args ${JSON.stringify(args)} and elementId ${elementId}`); | ||
res = await methodHandler.executeElementCommand(elementId, methodName, args); | ||
res = await methodHandler.executeElementCommand(elementId, methodName, args, skipScreenshot); | ||
} else { | ||
console.log(`Handling client method request with method '${methodName}' and args ${JSON.stringify(args)}`); | ||
res = await methodHandler.executeMethod(methodName, args); | ||
res = await methodHandler.executeMethod(methodName, args, skipScreenshot); | ||
} | ||
} else if (strategy && selector) { | ||
if (fetchArray) { | ||
console.log(`Fetching elements with selector '${selector}' and strategy ${strategy}`); | ||
res = await methodHandler.fetchElements(strategy, selector); | ||
res = await methodHandler.fetchElements(strategy, selector, skipScreenshot); | ||
} else { | ||
console.log(`Fetching an element with selector '${selector}' and strategy ${strategy}`); | ||
res = await methodHandler.fetchElement(strategy, selector); | ||
|
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], skipScreenshot: true, skipRecord: true}), | ||
callClientMethod({methodName: 'getSize', args: [elementId], skipScreenshot: 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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
When you pass
undefined
ornull
into an object via ellipsis (spread) operator, it has no effect.