-
Notifications
You must be signed in to change notification settings - Fork 281
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add setOrientation
command
#2121
Open
johntmcintosh
wants to merge
4
commits into
mobile-dev-inc:main
Choose a base branch
from
johntmcintosh:feature/set-orientation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6376824
Create a new setOrientation command (for iOS only initially)
johntmcintosh c978384
Add an enum for representing the valid orientations
johntmcintosh de55e0f
Add android support for setting orientation
johntmcintosh 90b4677
Update additional test cases
johntmcintosh 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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package maestro | ||
|
||
enum class DeviceOrientation { | ||
PORTRAIT, | ||
LANDSCAPE_LEFT, | ||
LANDSCAPE_RIGHT, | ||
UPSIDE_DOWN; | ||
|
||
// Return the camelCase representation of the enum name, for example "landscapeLeft" | ||
val camelCaseName: String | ||
get() = name.split("_") | ||
.mapIndexed { index, part -> | ||
if (index == 0) part.lowercase() | ||
else part.lowercase().capitalize() | ||
} | ||
.joinToString("") | ||
|
||
companion object { | ||
// Support lookup of enum value by name, ignoring underscores and case. This allow inputs like | ||
// "LANDSCAPE_LEFT" or "landscapeLeft" to both be matched to the LANDSCAPE_LEFT enum value. | ||
fun getByName(name: String): DeviceOrientation? { | ||
return values().find { | ||
comparableName(it.name) == comparableName(name) | ||
} | ||
} | ||
|
||
private fun comparableName(name: String): String { | ||
return name.lowercase().replace("_", "") | ||
} | ||
} | ||
} |
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
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
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
3 changes: 3 additions & 0 deletions
3
maestro-ios-driver/src/main/kotlin/xcuitest/api/SetOrientationRequest.kt
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package xcuitest.api | ||
|
||
data class SetOrientationRequest(val orientation: String) |
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
21 changes: 21 additions & 0 deletions
21
...o-ios-xctest-runner/maestro-driver-iosUITests/Routes/Handlers/SetOrientationHandler.swift
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import Foundation | ||
import FlyingFox | ||
import os | ||
import XCTest | ||
|
||
@MainActor | ||
struct SetOrientationHandler: HTTPHandler { | ||
private let logger = Logger( | ||
subsystem: Bundle.main.bundleIdentifier!, | ||
category: String(describing: Self.self) | ||
) | ||
|
||
func handleRequest(_ request: HTTPRequest) async throws -> HTTPResponse { | ||
guard let requestBody = try? JSONDecoder().decode(SetOrientationRequest.self, from: request.body) else { | ||
return AppError(type: .precondition, message: "incorrect request body provided for set orientation").httpResponse | ||
} | ||
|
||
XCUIDevice.shared.orientation = requestBody.orientation.uiDeviceOrientation | ||
return HTTPResponse(statusCode: .ok) | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...tro-ios-xctest-runner/maestro-driver-iosUITests/Routes/Models/SetOrientationRequest.swift
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import Foundation | ||
import UIKit | ||
|
||
struct SetOrientationRequest: Codable { | ||
let orientation: Orientation | ||
|
||
enum Orientation: String, Codable { | ||
case portrait | ||
case landscapeLeft | ||
case landscapeRight | ||
case upsideDown | ||
|
||
var uiDeviceOrientation: UIDeviceOrientation { | ||
switch self { | ||
case .portrait: | ||
return .portrait | ||
case .landscapeLeft: | ||
return .landscapeLeft | ||
case .landscapeRight: | ||
return .landscapeRight | ||
case .upsideDown: | ||
return .portraitUpsideDown | ||
} | ||
} | ||
} | ||
} |
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Random thought - not sure it's something we should care about - but from my understanding the "auto-rotate" that is disabled here is never re-enabled.
That also seems to be true for the
user_rotation
system settings: the lastsetOrientation
call will "persist" the chosenuser_rotation
system setting beyond the current running flow.If someone is reusing the same android device to run multiple flows one after the other, it might introduce some side effect between them: if one flow is using
setOrientation
commands while another expect the orientation to be in "auto-rotate" mode (or expect a "default" orientation).Edit: if this "side effect" is not something desired, it might be possible to mimic what is done for the
setProxy
: if set, proxy is "reset" whenAndroidDriver
isclosed
:maestro/maestro-client/src/main/java/maestro/drivers/AndroidDriver.kt
Line 162 in 673e4ff
(
setProxy
is also using settings under the hood)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.
Hey @vbarthel-fr 👋 first off, thanks so much pulling and performing an android test for me!
You bring up a good topic here that I hadn't thought about yet. (And thanks for the pointer to
resetProxy
as an example being called fromclose()
.)Do you foresee any holes in doing something like this:
setOrientation
is called for a flow we store the current values ofaccelerometer_rotation
anduser_rotation
(and for iOS just theXCUIDevice.shared.orientation
)close()
, if those were saved we reset them to the original values.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.
Yep, that sounds good to me :)
But I'm not knowledgeable enough to know for sure that is OK to rely on
AndroidDriver.close()
. Tomorrow, I will try to have a closer look at the source code, starting by understanding whenclose()
is called.