|
| 1 | +using System.Drawing; |
| 2 | +using E2E.Utils; |
| 3 | +using Xunit; |
| 4 | +using Instabug.Captain; |
| 5 | + |
| 6 | +using NoSuchElementException = OpenQA.Selenium.NoSuchElementException; |
| 7 | + |
| 8 | +namespace E2E; |
| 9 | + |
| 10 | +[Collection("E2E")] |
| 11 | +public class BugReportingTests : CaptainTest |
| 12 | +{ |
| 13 | + private void AssertOptionsPromptIsDisplayed() |
| 14 | + { |
| 15 | + var optionsPrompt = captain.FindById( |
| 16 | + android: "instabug_main_prompt_container", |
| 17 | + ios: "IBGReportBugPromptOptionAccessibilityIdentifier" |
| 18 | + ); |
| 19 | + |
| 20 | + Assert.True(optionsPrompt.Displayed); |
| 21 | + } |
| 22 | + |
| 23 | + [Fact] |
| 24 | + public void ReportABug() |
| 25 | + { |
| 26 | + captain.FindById( |
| 27 | + android: "instabug_floating_button", |
| 28 | + ios: "IBGFloatingButtonAccessibilityIdentifier" |
| 29 | + ).Tap(); |
| 30 | + |
| 31 | + captain.FindByText("Report a bug").Tap(); |
| 32 | + |
| 33 | + captain.FindInput( |
| 34 | + android: "instabug_edit_text_email", |
| 35 | + ios: "IBGBugInputViewEmailFieldAccessibilityIdentifier" |
| 36 | + |
| 37 | + |
| 38 | + captain.FindById( |
| 39 | + android: "instabug_bugreporting_send", |
| 40 | + ios: "IBGBugVCNextButtonAccessibilityIdentifier" |
| 41 | + ).Tap(); |
| 42 | + |
| 43 | + Assert.True(captain.FindByText("Thank you").Displayed); |
| 44 | + } |
| 45 | + |
| 46 | + [Fact] |
| 47 | + public void FloatingButtonInvocationEvent() |
| 48 | + { |
| 49 | + captain.FindById( |
| 50 | + android: "instabug_floating_button", |
| 51 | + ios: "IBGFloatingButtonAccessibilityIdentifier" |
| 52 | + ).Tap(); |
| 53 | + |
| 54 | + AssertOptionsPromptIsDisplayed(); |
| 55 | + } |
| 56 | + |
| 57 | + [Fact] |
| 58 | + public void ShakeInvocationEvent() |
| 59 | + { |
| 60 | + if (!Platform.IsIOS) return; |
| 61 | + |
| 62 | + captain.FindByText("Shake").Tap(); |
| 63 | + |
| 64 | + captain.Shake(); |
| 65 | + |
| 66 | + AssertOptionsPromptIsDisplayed(); |
| 67 | + } |
| 68 | + |
| 69 | + [Fact] |
| 70 | + public void TwoFingersSwipeLeftInvocationEvent() |
| 71 | + { |
| 72 | + captain.FindByText("Two Fingers Swipe Left").Tap(); |
| 73 | + |
| 74 | + Thread.Sleep(500); |
| 75 | + |
| 76 | + // Do a two-finger swipe left |
| 77 | + var width = captain.Window.Size.Width; |
| 78 | + captain.TwoFingerSwipe( |
| 79 | + new Point(width - 50, 300), |
| 80 | + new Point(50, 300), |
| 81 | + new Point(width - 50, 350), |
| 82 | + new Point(50, 350) |
| 83 | + ); |
| 84 | + |
| 85 | + AssertOptionsPromptIsDisplayed(); |
| 86 | + } |
| 87 | + |
| 88 | + [Fact] |
| 89 | + public void NoneInvocationEvent() |
| 90 | + { |
| 91 | + captain.FindByText("None").Tap(); |
| 92 | + |
| 93 | + captain.WaitForAssertion(() => |
| 94 | + Assert.Throws<NoSuchElementException>(() => |
| 95 | + captain.FindById( |
| 96 | + android: "instabug_floating_button", |
| 97 | + ios: "IBGFloatingButtonAccessibilityIdentifier", |
| 98 | + wait: false |
| 99 | + ) |
| 100 | + ) |
| 101 | + ); |
| 102 | + } |
| 103 | + |
| 104 | + [Fact] |
| 105 | + public void ManualInvocation() |
| 106 | + { |
| 107 | + captain.FindByText("Invoke").Tap(); |
| 108 | + |
| 109 | + AssertOptionsPromptIsDisplayed(); |
| 110 | + } |
| 111 | + |
| 112 | + [Fact] |
| 113 | + public void MultipleScreenshotsInReproSteps() |
| 114 | + { |
| 115 | + captain.FindByText("Enter screen name").Tap(); |
| 116 | + captain.Type("My Screen"); |
| 117 | + captain.HideKeyboard(); |
| 118 | + |
| 119 | + captain.FindByText("Report Screen Change").Tap(); |
| 120 | + captain.FindByText("Send Bug Report").Tap(); |
| 121 | + captain.FindById( |
| 122 | + android: "instabug_text_view_repro_steps_disclaimer", |
| 123 | + ios: "IBGBugVCReproStepsDisclaimerAccessibilityIdentifier" |
| 124 | + ).Tap(); |
| 125 | + |
| 126 | + var reproSteps = captain.FindManyById( |
| 127 | + android: "ib_bug_repro_step_screenshot", |
| 128 | + ios: "IBGReproStepsTableCellViewAccessibilityIdentifier" |
| 129 | + ); |
| 130 | + Assert.Equal(2, reproSteps.Count); |
| 131 | + } |
| 132 | + |
| 133 | + [Fact] |
| 134 | + public void ChangeReportTypes() |
| 135 | + { |
| 136 | + ScrollDown(); |
| 137 | + captain.FindByText("Bug", exact: true).Tap(); |
| 138 | + |
| 139 | + if (Platform.IsAndroid) |
| 140 | + { |
| 141 | + ScrollUp(); |
| 142 | + captain.FindByText("Invoke").Tap(); |
| 143 | + |
| 144 | + // Shows bug reporting screen |
| 145 | + Assert.True(captain.FindById("ib_bug_scroll_view").Displayed); |
| 146 | + |
| 147 | + // Close bug reporting screen |
| 148 | + captain.GoBack(); |
| 149 | + captain.FindByText("DISCARD").Tap(); |
| 150 | + |
| 151 | + Thread.Sleep(500); |
| 152 | + |
| 153 | + ScrollDown(); |
| 154 | + } |
| 155 | + |
| 156 | + captain.FindByText("Feedback").Tap(); |
| 157 | + |
| 158 | + ScrollUp(); |
| 159 | + captain.FindByText("Invoke").Tap(); |
| 160 | + |
| 161 | + // Shows both bug reporting and feature requests in prompt options |
| 162 | + AssertOptionsPromptIsDisplayed(); |
| 163 | + |
| 164 | + Assert.True(captain.FindByText("Report a bug").Displayed); |
| 165 | + Assert.True(captain.FindByText("Suggest an improvement").Displayed); |
| 166 | + Assert.Throws<NoSuchElementException>(() => captain.FindByText("Ask a question", wait: false)); |
| 167 | + } |
| 168 | + |
| 169 | + [Fact] |
| 170 | + public void ChangeFloatingButtonEdge() |
| 171 | + { |
| 172 | + ScrollDown(); |
| 173 | + captain.FindByText("Move Floating Button to Left").Tap(); |
| 174 | + |
| 175 | + Thread.Sleep(500); |
| 176 | + |
| 177 | + captain.WaitForAssertion(() => |
| 178 | + { |
| 179 | + var floatingButton = captain.FindById( |
| 180 | + android: "instabug_floating_button", |
| 181 | + ios: "IBGFloatingButtonAccessibilityIdentifier" |
| 182 | + ); |
| 183 | + var screenWidth = captain.Window.Size.Width; |
| 184 | + |
| 185 | + Assert.True(floatingButton.Location.X < screenWidth / 2); |
| 186 | + }); |
| 187 | + } |
| 188 | + |
| 189 | + [Fact] |
| 190 | + public void OnDismissCallbackIsCalled() |
| 191 | + { |
| 192 | + captain.FindByText("Set On Dismiss Callback").Tap(); |
| 193 | + captain.FindByText("Invoke").Tap(); |
| 194 | + |
| 195 | + AssertOptionsPromptIsDisplayed(); |
| 196 | + |
| 197 | + captain.FindByText("Cancel").Tap(); |
| 198 | + |
| 199 | + var popUpText = captain.FindByText("onDismiss callback called with DismissType.cancel and ReportType.other"); |
| 200 | + Assert.True(popUpText.Displayed); |
| 201 | + } |
| 202 | +} |
0 commit comments