Skip to content

Commit 24dce59

Browse files
a7medevHeshamMegid
authored andcommitted
[MOB-10740] Add More iOS E2E Tests (#313)
* Remove restart Instabug tap in iOS UI tests * UI test iOS surveys * UI test iOS primary color changes * UI test iOS repro steps * UI test iOS floating button edge * UI test iOS invocation events * UI test iOS report types * UI test iOS bug reporting onDismiss callback * UI test iOS feature requests
1 parent 5005a07 commit 24dce59

10 files changed

+318
-66
lines changed
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#import <XCTest/XCTest.h>
2+
#import "Util/XCUIElement+Instabug.h"
3+
4+
@interface BugReportingUITests : XCTestCase
5+
6+
@property (nonatomic, strong) XCUIApplication *app;
7+
8+
@end
9+
10+
@implementation BugReportingUITests
11+
12+
- (void)setUp {
13+
self.continueAfterFailure = NO;
14+
self.app = [[XCUIApplication alloc] init];
15+
[self.app launch];
16+
}
17+
18+
- (void)testMultipleScreenshotsInReproSteps {
19+
NSString *screen = @"My Screen";
20+
21+
XCUIElement *screenField = self.app.textFields[@"Enter screen name"];
22+
[screenField tap];
23+
[screenField typeText:screen];
24+
[screenField closeKeyboard];
25+
[self.app.buttons[@"Report Screen Change"] tapWithNumberOfTaps:2 numberOfTouches:1];
26+
27+
[self.app.buttons[@"Send Bug Report"] tap];
28+
[self.app.staticTexts[@"IBGBugVCReproStepsDisclaimerAccessibilityIdentifier"] tap];
29+
30+
NSPredicate *screensPredicate = [NSPredicate predicateWithFormat:@"label == %@", screen];
31+
XCUIElementQuery *screensQuery = [self.app.staticTexts matchingPredicate:screensPredicate];
32+
33+
XCTAssertEqual(2, screensQuery.count);
34+
}
35+
36+
- (void)testFloatingButtonInvocationEvent {
37+
// Grabbing the "Floating Button" invocation event button
38+
// inside the "Change Invocation Events" section as it
39+
// conflicts with Instabug's floating button.
40+
XCUIElement *invocationEvents = [[self.app.otherElements containingPredicate:[NSPredicate predicateWithFormat:@"label == 'Change Invocation Event'"]] element];
41+
[invocationEvents.buttons[@"Floating Button"] forceTap];
42+
[self.app.buttons[@"IBGFloatingButtonAccessibilityIdentifier"] tap];
43+
44+
[self assertOptionsPromptIsVisible];
45+
}
46+
47+
- (void)testNoneInvocationEvent {
48+
[self.app.buttons[@"None"] tap];
49+
50+
[self.app.buttons[@"IBGFloatingButtonAccessibilityIdentifier"] assertDoesNotExist];
51+
}
52+
53+
- (void)testManualInvocation {
54+
[self.app.buttons[@"Invoke"] tap];
55+
56+
[self assertOptionsPromptIsVisible];
57+
}
58+
59+
- (void)testOnDismissCallbackIsCalled {
60+
[self.app.buttons[@"Set On Dismiss Callback"] scrollDownAndTap];
61+
[self.app.buttons[@"Invoke"] scrollUpAndTap];
62+
[self.app.buttons[@"Cancel"] tap];
63+
64+
[self.app.staticTexts[@"onDismiss callback called with DismissType.cancel and ReportType.bug"] assertExistsWithTimeout:2];
65+
}
66+
67+
- (void)testChangeReportTypes {
68+
[self.app.buttons[@"Bug"] scrollDownAndTap];
69+
[self.app.buttons[@"Feedback"] scrollDownAndTap];
70+
[self.app.buttons[@"Invoke"] scrollUpAndTap];
71+
72+
[self assertOptionsPromptIsVisible];
73+
[self.app.staticTexts[@"Report a bug"] assertExistsWithTimeout:2000];
74+
[self.app.staticTexts[@"Suggest an improvement"] assertExistsWithTimeout:2000];
75+
[self.app.staticTexts[@"Ask a question"] assertDoesNotExist];
76+
}
77+
78+
- (void)testChangeFloatingButtonEdge {
79+
// Grabbing the "Floating Button" invocation event button
80+
// inside the "Change Invocation Events" section as it
81+
// conflicts with Instabug's floating button.
82+
XCUIElement *invocationEvents = [[self.app.otherElements containingPredicate:[NSPredicate predicateWithFormat:@"label == 'Change Invocation Event'"]] element];
83+
[invocationEvents.buttons[@"Floating Button"] forceTap];
84+
[self.app.buttons[@"Move Floating Button to Left"] scrollDownAndTap];
85+
86+
XCUIElement *floatingButton = self.app.buttons[@"IBGFloatingButtonAccessibilityIdentifier"];
87+
CGFloat floatingButtonLeft = floatingButton.frame.origin.x;
88+
CGFloat screenMiddle = self.app.frame.size.width / 2.0f;
89+
XCTAssertLessThan(floatingButtonLeft, screenMiddle, @"Floating button isn't to the left of the screen");
90+
}
91+
92+
- (void)assertOptionsPromptIsVisible {
93+
[self.app.cells[@"IBGReportBugPromptOptionAccessibilityIdentifier"] assertExistsWithTimeout:2];
94+
}
95+
96+
@end
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#import <XCTest/XCTest.h>
2+
#import "Util/XCUIElement+Instabug.h"
3+
#import "Util/InstabugUITestsUtils.h"
4+
5+
@interface FeatureRequestsUITests : XCTestCase
6+
7+
@property (nonatomic, strong) XCUIApplication *app;
8+
9+
@end
10+
11+
@implementation FeatureRequestsUITests
12+
13+
- (void)setUp {
14+
self.continueAfterFailure = NO;
15+
self.app = [[XCUIApplication alloc] init];
16+
[self.app launch];
17+
}
18+
19+
- (void)testShowFeatureRequestsScreen {
20+
[self.app.buttons[@"Show Feature Requests"] scrollDownAndTap];
21+
22+
[self.app.staticTexts[@"Feature Requests"] assertExistsWithTimeout:2];
23+
}
24+
25+
@end

example/ios/InstabugSampleUITests/InstabugSampleUITests.m

Lines changed: 0 additions & 63 deletions
This file was deleted.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#import <XCTest/XCTest.h>
2+
#import "Util/XCUIElement+Instabug.h"
3+
#import "Util/InstabugUITestsUtils.h"
4+
5+
@interface InstabugUITests : XCTestCase
6+
7+
@property (nonatomic, strong) XCUIApplication *app;
8+
9+
@end
10+
11+
@implementation InstabugUITests
12+
13+
- (void)setUp {
14+
self.continueAfterFailure = NO;
15+
self.app = [[XCUIApplication alloc] init];
16+
[self.app launch];
17+
}
18+
19+
- (void)testChangePrimaryColor {
20+
NSString *color = @"#FF0000";
21+
UIColor *expected = [UIColor redColor];
22+
XCUIElement *colorField = self.app.textFields[@"Enter primary color"];
23+
[colorField tap];
24+
[colorField typeText:color];
25+
[colorField closeKeyboard];
26+
[self.app.buttons[@"Change Primary Color"] tap];
27+
28+
XCUIElement *floatingButton = self.app.buttons[@"IBGFloatingButtonAccessibilityIdentifier"];
29+
UIImage *image = [[floatingButton screenshot] image];
30+
int x = image.size.width / 2;
31+
int y = 5;
32+
UIColor *actual = [InstabugUITestsUtils getPixelColorWithImage:image x:x y:y];
33+
XCTAssertTrue([actual isEqual:expected]);
34+
}
35+
36+
@end
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#import <XCTest/XCTest.h>
2+
#import "Util/XCUIElement+Instabug.h"
3+
#import "Util/InstabugUITestsUtils.h"
4+
5+
@interface SurveysUITests : XCTestCase
6+
7+
@property (nonatomic, strong) XCUIApplication *app;
8+
9+
@end
10+
11+
@implementation SurveysUITests
12+
13+
- (void)setUp {
14+
self.continueAfterFailure = NO;
15+
self.app = [[XCUIApplication alloc] init];
16+
[self.app launch];
17+
}
18+
19+
- (void)testShowManualSurvey {
20+
[self.app.buttons[@"Show Manual Survey"] scrollDownAndTap];
21+
22+
[self.app.otherElements[@"SurveyNavigationVC"] assertExistsWithTimeout:2];
23+
}
24+
25+
@end
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#import <Foundation/Foundation.h>
2+
#import <UIKit/UIKit.h>
3+
4+
@interface InstabugUITestsUtils : NSObject
5+
6+
+ (UIColor *)getPixelColorWithImage:(UIImage *)image x:(NSInteger)x y:(NSInteger)y;
7+
8+
@end
9+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#import "InstabugUITestsUtils.h"
2+
3+
@implementation InstabugUITestsUtils
4+
5+
+ (UIColor *)getPixelColorWithImage:(UIImage *)image x:(NSInteger)x y:(NSInteger)y {
6+
CGImageRef cgImage = image.CGImage;
7+
CGFloat width = image.size.width;
8+
CGFloat height = image.size.height;
9+
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
10+
int bytesPerPixel = 4;
11+
NSUInteger bitsPerComponent = 8;
12+
UInt8 pixelData[4] = {0, 0, 0, 0};
13+
CGContextRef context = CGBitmapContextCreate(pixelData, 1, 1, bitsPerComponent, bytesPerPixel, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
14+
CGColorSpaceRelease(colorSpace);
15+
CGContextSetBlendMode(context, kCGBlendModeCopy);
16+
17+
CGContextTranslateCTM(context, -x, y - height);
18+
CGContextDrawImage(context, CGRectMake(0.0f, 0.0f, width, height), cgImage);
19+
CGContextRelease(context);
20+
21+
CGFloat red = pixelData[0] / 255.0f;
22+
CGFloat green = pixelData[1] / 255.0f;
23+
CGFloat blue = pixelData[2] / 255.0f;
24+
CGFloat alpha = pixelData[3] / 255.0f;
25+
return [UIColor colorWithRed:red green:green blue:blue alpha:alpha];
26+
}
27+
28+
@end
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#import <XCTest/XCTest.h>
2+
3+
@interface XCUIElement (Instabug)
4+
5+
- (void)scrollDownAndTap;
6+
- (void)scrollUpAndTap;
7+
- (void)closeKeyboard;
8+
- (void)forceTap;
9+
- (void)assertExistsWithTimeout:(NSTimeInterval)timeout;
10+
- (void)assertDoesNotExist;
11+
12+
@end
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#import "XCUIElement+Instabug.h"
2+
3+
@implementation XCUIElement (Instabug)
4+
5+
- (void)scrollDownAndTap {
6+
[self scrollDownAndTapWithBlock:^(XCUIApplication *app) {
7+
[app swipeUp];
8+
}];
9+
}
10+
11+
- (void)scrollUpAndTap {
12+
[self scrollDownAndTapWithBlock:^(XCUIApplication *app) {
13+
[app swipeDown];
14+
}];
15+
}
16+
17+
- (void)scrollDownAndTapWithBlock:(void (^)(XCUIApplication *app))block {
18+
XCUIApplication *app = [[XCUIApplication alloc] init];
19+
20+
int count = 0;
21+
while (!self.isHittable && count < 10) {
22+
block(app);
23+
count++;
24+
}
25+
26+
sleep(1);
27+
[self tap];
28+
}
29+
30+
- (void)closeKeyboard {
31+
[self typeText:@"\n"];
32+
}
33+
34+
/// Taps on the button's coordinates without checking if it's visible.
35+
/// This is useful as XCUITest fails to scroll to Flutter widgets even though they might be visible
36+
/// on the screen.
37+
- (void)forceTap {
38+
XCUICoordinate *coordinate = [self coordinateWithNormalizedOffset:CGVectorMake(0.0f, 0.0f)];
39+
[coordinate tap];
40+
}
41+
42+
- (void)assertExistsWithTimeout:(NSTimeInterval)timeout {
43+
XCTAssertTrue([self waitForExistenceWithTimeout:timeout], "Element described by: %@ doesn't exist, expected to exist", self.description);
44+
}
45+
46+
- (void)assertDoesNotExist {
47+
XCTAssertFalse([self waitForExistenceWithTimeout:2], "Element described by: %@ exists, expected to not exist", self.description);
48+
}
49+
50+
@end

0 commit comments

Comments
 (0)