Skip to content

Commit 14a37e5

Browse files
authored
feat(replay): Add maestro orientation change flow (#4472)
1 parent a33339c commit 14a37e5

File tree

5 files changed

+94
-2
lines changed

5 files changed

+94
-2
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
This folder contains the Maestro flows for the Sentry Android SDK.
2+
3+
## Running the Flows
4+
5+
First, make sure you have the Maestro CLI installed. You can find the installation instructions in the [Maestro documentation](https://docs.maestro.dev/getting-started/installing-maestro).
6+
7+
To run the Maestro flows, navigate to this directory in your terminal and execute the following command:
8+
9+
```bash
10+
maestro run <flow_name>.yaml
11+
```
12+
13+
Replace `<flow_name>` with the name of the flow you want to run, such as `orientation_change_flow.yaml`.
14+
15+
## Available Flows
16+
17+
- `orientation_change_flow.yaml`: This flow tests the orientation change/window size change functionality for replays.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
appId: io.sentry.samples.android
2+
3+
---
4+
- launchApp:
5+
arguments:
6+
isOrientationChange: true
7+
- scrollUntilVisible:
8+
element:
9+
id: "show_dialog"
10+
- tapOn: Show Dialog
11+
- tapOn: Close
12+
- scrollUntilVisible:
13+
element:
14+
id: "open_compose_activity"
15+
- tapOn: Open Compose Activity
16+
- extendedWaitUntil:
17+
visible: randText # Any random text that does not exist in the UI
18+
optional: true # This should be true so that the test won't fail
19+
timeout: 2000
20+
- tapOn: Show Dialog
21+
- tapOn:
22+
point: 25%, 25%
23+
- tapOn: "Navigate to Github"
24+
- extendedWaitUntil:
25+
visible: randText # Any random text that does not exist in the UI
26+
optional: true # This should be true so that the test won't fail
27+
timeout: 2000
28+
- back
29+
- tapOn: Show Dialog
30+
- tapOn:
31+
point: 25%, 25%
32+
- back
33+
- extendedWaitUntil:
34+
visible: randText # Any random text that does not exist in the UI
35+
optional: true # This should be true so that the test won't fail
36+
timeout: 2000
37+
- back
38+
- back

sentry-samples/sentry-samples-android/src/main/java/io/sentry/samples/android/MainActivity.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package io.sentry.samples.android;
22

33
import android.content.Intent;
4+
import android.content.pm.ActivityInfo;
5+
import android.content.res.Configuration;
46
import android.os.Bundle;
57
import android.os.Handler;
68
import androidx.appcompat.app.AlertDialog;
@@ -38,6 +40,8 @@ public class MainActivity extends AppCompatActivity {
3840
protected void onCreate(Bundle savedInstanceState) {
3941
super.onCreate(savedInstanceState);
4042

43+
SharedState.INSTANCE.setOrientationChange(
44+
getIntent().getBooleanExtra("isOrientationChange", false));
4145
final ActivityMainBinding binding = ActivityMainBinding.inflate(getLayoutInflater());
4246

4347
final File imageFile = getApplicationContext().getFileStreamPath("sentry.png");
@@ -282,7 +286,16 @@ public void run() {
282286
.setPositiveButton(
283287
"Close",
284288
(dialog, which) -> {
285-
dialog.dismiss();
289+
if (SharedState.INSTANCE.isOrientationChange()) {
290+
int currentOrientation = getResources().getConfiguration().orientation;
291+
if (currentOrientation == Configuration.ORIENTATION_PORTRAIT) {
292+
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
293+
} else if (currentOrientation == Configuration.ORIENTATION_LANDSCAPE) {
294+
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
295+
}
296+
} else {
297+
dialog.dismiss();
298+
}
286299
})
287300
.show();
288301
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package io.sentry.samples.android
2+
3+
object SharedState {
4+
@Volatile
5+
var isOrientationChange: Boolean = false
6+
}

sentry-samples/sentry-samples-android/src/main/java/io/sentry/samples/android/compose/ComposeActivity.kt

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
package io.sentry.samples.android.compose
44

5+
import android.app.Activity
6+
import android.content.pm.ActivityInfo
7+
import android.content.res.Configuration
58
import android.os.Bundle
69
import androidx.activity.ComponentActivity
710
import androidx.activity.compose.setContent
@@ -34,6 +37,7 @@ import androidx.compose.ui.ExperimentalComposeUiApi
3437
import androidx.compose.ui.Modifier
3538
import androidx.compose.ui.graphics.Color
3639
import androidx.compose.ui.graphics.ColorFilter
40+
import androidx.compose.ui.platform.LocalContext
3741
import androidx.compose.ui.platform.testTag
3842
import androidx.compose.ui.res.painterResource
3943
import androidx.compose.ui.text.input.TextFieldValue
@@ -49,6 +53,7 @@ import io.sentry.android.replay.sentryReplayUnmask
4953
import io.sentry.compose.SentryTraced
5054
import io.sentry.compose.withSentryObservableEffect
5155
import io.sentry.samples.android.GithubAPI
56+
import io.sentry.samples.android.SharedState
5257
import kotlinx.coroutines.launch
5358
import io.sentry.samples.android.R as IR
5459

@@ -71,6 +76,8 @@ fun Landing(
7176
navigateGithubWithArgs: () -> Unit
7277
) {
7378
var showDialog by remember { mutableStateOf(false) }
79+
val context = LocalContext.current
80+
val activity = context as? Activity ?: return
7481

7582
SentryTraced(tag = "buttons_page") {
7683
Column(
@@ -119,7 +126,18 @@ fun Landing(
119126
if (showDialog) {
120127
BasicAlertDialog(
121128
onDismissRequest = {
122-
showDialog = false
129+
if (SharedState.isOrientationChange) {
130+
val orientation = activity.resources.configuration.orientation
131+
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
132+
activity.requestedOrientation =
133+
ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
134+
} else if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
135+
activity.requestedOrientation =
136+
ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
137+
}
138+
} else {
139+
showDialog = false
140+
}
123141
},
124142
content = {
125143
Surface(

0 commit comments

Comments
 (0)