Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

fix hybrid element position determination #1906

Merged
merged 3 commits into from
Sep 19, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions app/main/appium-method-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export default class AppiumMethodHandler {

async _getContextsSourceAndScreenshot () {
let contexts, contextsError, currentContext, currentContextError, platformName,
source, sourceError, screenshot, screenshotError, statBarHeight, windowSize, windowSizeError;
source, sourceError, screenshot, screenshotError, statBarHeight, windowSize, windowSizeError, webViewPosition;

if (!await this._hasContextsCommand()) {
currentContext = null;
Expand Down Expand Up @@ -232,6 +232,17 @@ export default class AppiumMethodHandler {
}

if (currentContext !== NATIVE_APP) {
const isAndroid = _.toLower(platformName) === 'android';
try {
// Get the webview offset
const el = await this.driver.elementOrNull(
isAndroid ? 'xpath' : '-ios class chain',
isAndroid ? '//android.webkit.WebView' : '**/XCUIElementTypeWebView'
);
if (!webViewPosition) {
wswebcreation marked this conversation as resolved.
Show resolved Hide resolved
webViewPosition = await this.driver.getLocation(el.value);
}
} catch (ign) {}
await this.driver.context(currentContext);
}
// End of note
Expand All @@ -242,9 +253,15 @@ export default class AppiumMethodHandler {
*/
try {
if (currentContext !== NATIVE_APP) {
const webviewStatusAddressBarHeight = await this.driver.execute(getWebviewStatusAddressBarHeight, [{platformName, statBarHeight}]);

await this.driver.execute(setHtmlElementAttributes, [{platformName, webviewStatusAddressBarHeight}]);
// Fallback if the webview position can't be determined,
// then do it based on the web context
if (!webViewPosition) {
webViewPosition = {
x: 0,
y: await this.driver.execute(getWebviewStatusAddressBarHeight, [{platformName, statBarHeight}]),
};
}
await this.driver.execute(setHtmlElementAttributes, [{platformName, webviewStatusAddressBarHeight: webViewPosition.y}]);
mykola-mokhnach marked this conversation as resolved.
Show resolved Hide resolved
}
} catch (ign) {}
}
Expand Down
22 changes: 10 additions & 12 deletions app/renderer/actions/Session.js
Original file line number Diff line number Diff line change
Expand Up @@ -802,29 +802,27 @@ export function setVisibleProviders () {
* @param {object} caps
*/
function addCustomCaps (caps) {
const {browserName = '', platformName = ''} = caps;
const safariCustomCaps = {
// Add the includeSafariInWebviews for future HTML detection
includeSafariInWebviews: true,
};
const chromeCustomCaps = {
const {platformName = ''} = caps;
const androidCustomCaps = {
// @TODO: remove when this is defaulted in the newest Appium 1.8.x release
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1.8.x? must be a quite old one

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was code I copied over, not sure if we still need it but didn't want to change that in this PR

ensureWebviewsHavePages: true,
// Make sure the screenshot is taken of the whole screen when the ChromeDriver is used
// for or Chrome, or for Hybrid apps
nativeWebScreenshot: true,
// Set the ChromeDriver to w3c:false because all internal calls are still JSONWP calls
chromeOptions: {
'w3c': false,
},
};
const androidCustomCaps = {
// @TODO: remove when this is defaulted in the newest Appium 1.8.x release
ensureWebviewsHavePages: true,
const iosCustomCaps = {
// Always add the includeSafariInWebviews for future HTML detection
// This will ensure that if you use AD to switch between App and browser
// that it can detect Safari as a webview
includeSafariInWebviews: true,
};
const iosCustomCaps = {};

return {
...caps,
...(browserName.toLowerCase() === 'safari' ? safariCustomCaps : {}),
...(browserName.toLowerCase() === 'chrome' ? chromeCustomCaps : {}),
...(platformName.toLowerCase() === 'android' ? androidCustomCaps : {}),
...(platformName.toLowerCase() === 'ios' ? iosCustomCaps : {}),
};
Expand Down