This repository has been archived by the owner on Apr 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Highlight elements that user searched for #344
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,20 +58,40 @@ export default class AppiumMethodHandler { | |
return {variableName, variableType, strategy, selector, elements}; | ||
} | ||
|
||
async executeElementCommand (elementId, methodName, args = [], skipScreenshot = false) { | ||
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; | ||
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 (!skipScreenshot) { | ||
if (!skipScreenshotAndSource) { | ||
sourceAndScreenshot = await this._getSourceAndScreenshot(); | ||
} | ||
|
||
|
@@ -82,38 +102,12 @@ export default class AppiumMethodHandler { | |
}; | ||
} | ||
|
||
async executeMethod (methodName, args = [], skipScreenshot = false) { | ||
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; | ||
|
||
if (!skipScreenshot) { | ||
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 () { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back 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.
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...