Skip to content

Commit

Permalink
Merge pull request #1654 from bugsnag/tms/carefree-dialogs-3
Browse files Browse the repository at this point in the history
Pull e2e test commands from Maze Runner
  • Loading branch information
twometresteve authored Apr 14, 2022
2 parents 3364e95 + 99e2868 commit 03840c7
Show file tree
Hide file tree
Showing 14 changed files with 58 additions and 76 deletions.
4 changes: 3 additions & 1 deletion features/fixtures/mazerunner/app/detekt-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?xml version="1.0" ?>
<SmellBaseline>
<ManuallySuppressedIssues></ManuallySuppressedIssues>
<CurrentIssues></CurrentIssues>
<CurrentIssues>
<ID>MagicNumber:MainActivity.kt$MainActivity$1000</ID>
</CurrentIssues>
</SmellBaseline>
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,41 @@ class MainActivity : Activity() {
sendBroadcast(closeDialog)
}

val clearUserData = findViewById<Button>(R.id.clearUserData)

clearUserData.setOnClickListener {
clearStoredApiKey()
val apiKeyField = findViewById<EditText>(R.id.manualApiKey)
apiKeyField.text.clear()
log("Cleared user data")
}

if (apiKeyStored()) {
val apiKey = getStoredApiKey()
val apiKeyField = findViewById<EditText>(R.id.manualApiKey)
apiKeyField.text.clear()
apiKeyField.text.append(apiKey)
}

startCommandRunner()
}

// Starts a thread to poll for Maze Runner actions to perform
private fun startCommandRunner() {
// Get the next maze runner command
findViewById<Button>(R.id.run_command).setOnClickListener {
log("run_command pressed")
thread(start = true) {
thread(start = true) {
while (true) {
Thread.sleep(1000)
try {
// Get the next command from Maze Runner
val commandUrl: String = "http://bs-local.com:9339/command"
val commandStr = URL(commandUrl).readText()
if (commandStr == "null") {
log("No Maze Runner commands queued")
continue
}
log("Received command: $commandStr")

var command = JSONObject(commandStr)
val action = command.getString("action")
val scenarioName = command.getString("scenario_name")
Expand All @@ -67,22 +93,6 @@ class MainActivity : Activity() {
}
}
}

val clearUserData = findViewById<Button>(R.id.clearUserData)

clearUserData.setOnClickListener {
clearStoredApiKey()
val apiKeyField = findViewById<EditText>(R.id.manualApiKey)
apiKeyField.text.clear()
log("Cleared user data")
}

if (apiKeyStored()) {
val apiKey = getStoredApiKey()
val apiKeyField = findViewById<EditText>(R.id.manualApiKey)
apiKeyField.text.clear()
apiKeyField.text.append(apiKey)
}
}

// load the scenario first, which initialises bugsnag without running any crashy code
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@
android:layout_height="match_parent"
android:orientation="vertical">

<Button
android:id="@+id/run_command"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="4"
android:text="Run command" />

<EditText
android:id="@+id/notify_endpoint"
android:layout_width="match_parent"
Expand Down
5 changes: 2 additions & 3 deletions features/full_tests/auto_notify.feature
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,10 @@ Feature: Switching automatic error detection on/off for Unity
# PLAT-6620
@skip_android_8_1
Scenario: ANR captured with autoDetectAnrs reenabled
When I run "AutoDetectAnrsTrueScenario"
When I clear any error dialogue
And I run "AutoDetectAnrsTrueScenario"
And I wait for 2 seconds
And I tap the screen 3 times
And I wait for 4 seconds
And I clear any error dialogue
And I wait to receive an error
Then the error is valid for the error reporting API version "4.0" for the "Android Bugsnag Notifier" notifier
And the error payload field "events" is an array with 1 elements
Expand Down
8 changes: 4 additions & 4 deletions features/full_tests/detect_anr_jvm.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ Feature: ANRs triggered in JVM code are captured
Given I clear all persistent data

Scenario: ANR triggered in JVM loop code is captured
When I run "JvmAnrLoopScenario"
When I clear any error dialogue
And I run "JvmAnrLoopScenario"
And I wait for 2 seconds
And I tap the screen 3 times
Then I wait to receive an error
Expand All @@ -21,11 +22,10 @@ Feature: ANRs triggered in JVM code are captured
# on Samsung as it is explicitly design to test ANRs caused by a sleeping thread.
@skip_samsung
Scenario: ANR triggered in JVM sleep code is captured
When I run "JvmAnrSleepScenario"
When I clear any error dialogue
And I run "JvmAnrSleepScenario"
And I wait for 2 seconds
And I tap the screen 3 times
And I wait for 4 seconds
And I clear any error dialogue
Then I wait to receive an error
And the error is valid for the error reporting API version "4.0" for the "Android Bugsnag Notifier" notifier
And the exception "errorClass" equals "ANR"
Expand Down
1 change: 0 additions & 1 deletion features/full_tests/detect_ndk_crashes.feature
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ Feature: Verifies autoDetectNdkCrashes controls when NDK crashes are reported
Scenario: No crash reported when autoDetectNdkCrashes disabled
When I run "AutoDetectNdkDisabledScenario" and relaunch the crashed app
And I configure Bugsnag for "AutoDetectNdkDisabledScenario"
And I wait for 2 seconds
Then I should receive no requests
2 changes: 2 additions & 0 deletions features/full_tests/discarded_events.feature
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ Feature: Discarding events
And I configure Bugsnag for "DiscardOldEventsScenario"
Then I should receive no requests

# Skip pending PLAT-8374
@skip
Scenario: Discard an on-disk error that failed to send and is too big
# Fail to send initial handled error. Client stores it to disk.
Given I set the endpoints to the terminating server
Expand Down
1 change: 0 additions & 1 deletion features/full_tests/native_event_tracking.feature
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ Feature: Synchronizing app/device metadata in the native layer
Scenario: Capture foreground state while in a background crash
When I run "CXXDelayedCrashScenario"
And I send the app to the background for 10 seconds
And I clear any error dialogue
And I relaunch the app after a crash
And I configure Bugsnag for "CXXDelayedCrashScenario"
And I wait to receive an error
Expand Down
5 changes: 2 additions & 3 deletions features/full_tests/startup_anr.feature
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ Feature: onCreate ANR
# fire at all). Since we can't cover a KILL signal in a test, we skip Android 10.
@skip_android_10
Scenario: onCreate ANR is reported
When I run "ConfigureStartupAnrScenario"
When I clear any error dialogue
And I run "ConfigureStartupAnrScenario"
And I relaunch the app after a crash
And I wait for 30 seconds
And I clear any error dialogue
Then I wait to receive an error
And the exception "errorClass" equals "ANR"
1 change: 0 additions & 1 deletion features/full_tests/threaded_startup.feature
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ Feature: Switching automatic error detection on/off for Unity
Scenario: Starting Bugsnag & calling it on separate threads
When I run "MultiThreadedStartupScenario" and relaunch the crashed app
And I configure Bugsnag for "MultiThreadedStartupScenario"
And I wait for 2 seconds
Then I should receive no error
1 change: 0 additions & 1 deletion features/minimal/detect_anr_minimal.feature
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ Feature: ANRs triggered in a fixture with only bugsnag-android-core are captured
And I wait for 2 seconds
And I tap the screen 3 times
And I wait for 4 seconds
And I clear any error dialogue
Then I wait to receive an error
And the error is valid for the error reporting API version "4.0" for the "Android Bugsnag Notifier" notifier
And the exception "errorClass" equals "java.lang.RuntimeException"
Expand Down
5 changes: 2 additions & 3 deletions features/smoke_tests/unhandled.feature
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,10 @@ Feature: Unhandled smoke tests

@skip_android_8_1
Scenario: ANR detection
When I run "JvmAnrLoopScenario"
When I clear any error dialogue
And I run "JvmAnrLoopScenario"
And I wait for 2 seconds
And I tap the screen 3 times
And I wait for 4 seconds
And I clear any error dialogue
And I wait to receive an error

# Exception details
Expand Down
41 changes: 10 additions & 31 deletions features/steps/android_steps.rb
Original file line number Diff line number Diff line change
@@ -1,36 +1,12 @@
When('I clear all persistent data') do
execute_command :clear_persistent_data, ''
execute_command :clear_persistent_data
end

# Waits 5s for an element to be present. If it isn't assume a system error dialog is
# blocking its view and dismiss it before trying once more.
#
# @step_input element_id [String] The element to wait for
When('any dialog is cleared and the element {string} is present') do |element_id|
count = 0
present = false
timeout = 3
until present || count > 5
present = Maze.driver.wait_for_element(element_id, timeout = timeout)
break if present
count += 1
clicked = click_if_present('android:id/button1') ||
click_if_present('android:id/aerr_close') ||
click_if_present('android:id/aerr_restart')
$logger.info "System dialog cleared, reattempting wait_for_element" if clicked
end

Maze.check.true(present, "The element #{element_id} could not be found")
end

def execute_command(action, scenario_name)
def execute_command(action, scenario_name = '')
command = { action: action, scenario_name: scenario_name, scenario_mode: $scenario_mode }
Maze::Server.commands.add command

# Tapping saves a lot of time finding and clicking elements with Appium
tap_at 200, 200
$scenario_mode = ''
$reset_data = false

# Ensure fixture has read the command
count = 600
Expand All @@ -45,13 +21,17 @@ def tap_at(x, y)
end

When("I clear any error dialogue") do
click_if_present 'android:id/button1'
click_if_present 'android:id/aerr_close'
click_if_present 'android:id/aerr_restart'
# It can take multiple clicks to clear a dialog,
# so keep pressing until nothing is pressed
keep_clicking = true
while keep_clicking
keep_clicking = click_if_present('android:id/button1') ||
click_if_present('android:id/aerr_close') ||
click_if_present('android:id/aerr_restart')
end
end

When('I run {string}') do |scenario_name|
step 'I clear any error dialogue'
execute_command :run_scenario, scenario_name
end

Expand All @@ -63,7 +43,6 @@ def tap_at(x, y)
end

When("I configure Bugsnag for {string}") do |event_type|
step 'I clear any error dialogue'
execute_command :start_bugsnag, event_type
end

Expand Down
5 changes: 4 additions & 1 deletion features/support/env.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
BeforeAll do
$api_key = "a35a2a72bd230ac0aa0f52715bbdc6aa"
$scenario_mode = ''
Maze.config.receive_no_requests_wait = 10
Maze.config.receive_requests_wait = 60
end

Before do
$scenario_mode = ''
end

Before('@skip') do |scenario|
skip_this_scenario("Skipping scenario")
end
Expand Down

0 comments on commit 03840c7

Please sign in to comment.