Skip to content

Commit 620a9e8

Browse files
fix(setOrientation): calc view port according to automation name (#244)
1 parent ec2c558 commit 620a9e8

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

Diff for: lib/appium-driver.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import { screencapture } from "./helpers/screenshot-manager";
4949
import { LogImageType } from "./enums/log-image-type";
5050
import { DeviceOrientation } from "./enums/device-orientation";
5151
import { NsCapabilities } from "./ns-capabilities";
52+
import { AutomationName } from "./automation-name";
5253

5354
export class AppiumDriver {
5455
private _defaultWaitTime: number = 5000;
@@ -548,14 +549,15 @@ export class AppiumDriver {
548549
await this._driver.setOrientation(orientation);
549550

550551
if (orientation === DeviceOrientation.LANDSCAPE && this.isAndroid) {
551-
if ((<NsCapabilities>this.nsCapabilities).tryGetApiLevel() < 6.0) {
552+
if ((<NsCapabilities>this.nsCapabilities).automationName === AutomationName.UiAutomator1
553+
|| (<NsCapabilities>this.nsCapabilities).automationName === AutomationName.Appium) {
552554
// HACK since the image is rotated and action bar is on the bottom of the image, it is needed to exclude action bar from bottom.
553555
const height = this._imageHelper.options.cropRectangle.width - this._imageHelper.options.cropRectangle.y;
554556
const width = this._imageHelper.options.cropRectangle.height + this._imageHelper.options.cropRectangle.y;
555557
this.imageHelper.options.cropRectangle.y = 0;
556558
this.imageHelper.options.cropRectangle.width = width;
557559
this.imageHelper.options.cropRectangle.height = height;
558-
} else if ((<NsCapabilities>this.nsCapabilities).tryGetApiLevel() >= 6.0) {
560+
} else if ((<NsCapabilities>this.nsCapabilities).automationName === AutomationName.UiAutomator2) {
559561
const height = this._imageHelper.options.cropRectangle.width - this.imageHelper.options.cropRectangle.y;
560562
const width = this._imageHelper.options.cropRectangle.height + this.imageHelper.options.cropRectangle.y;
561563
this.imageHelper.options.cropRectangle.width = width;

Diff for: lib/parser.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const config = (() => {
2525
describe: "Custom capabilities location `/some-path/appium.capabilities.json`",
2626
type: "string"
2727
})
28-
.option("appiumCaps", { alias: "caps", describe: "Apply additional appium capabilites" })
28+
.option("appiumCaps", { alias: "caps", describe: "Apply additional appium capabilities" })
2929
.option("capabilitiesName",
3030
{
3131
describe: "Capabilities file name",

0 commit comments

Comments
 (0)