Skip to content

Commit 593774b

Browse files
author
Chuan Ren
authored
E2e tests split (#2401)
1 parent b3f2abc commit 593774b

14 files changed

+411
-343
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
1-
//
2-
// Use this file to import your target's public headers that you would like to expose to Swift.
3-
//
1+
/*
2+
* Copyright 2019 Google
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
416

517
#import "FIRAuthApiTestsBase.h"

Example/Auth/ApiTests/GoogleAuthTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class GoogleAuthTestsSwift: FIRAuthApiTestsBase {
7272
data = receivedData
7373
expectation.fulfill()
7474
}
75-
75+
7676
waitForExpectations(timeout: kExpectationsTimeout) { error in
7777
if error != nil {
7878
XCTFail(String(format: "Failed to wait for expectations in exchanging Google account tokens. Error: %@", error!.localizedDescription))

Example/Auth/E2eTests/BYOAuthTests.m

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
* Copyright 2019 Google
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#import "FIRAuthE2eTestsBase.h"
18+
19+
/** The url for obtaining a valid custom token string used to test BYOAuth. */
20+
static NSString *const kCustomTokenUrl = @"https://fb-sa-1211.appspot.com/token";
21+
22+
/** The invalid custom token string for testing BYOAuth. */
23+
static NSString *const kInvalidCustomToken = @"invalid token.";
24+
25+
/** The user name string for BYOAuth testing account. */
26+
static NSString *const kTestingAccountUserID = @"BYU_Test_User_ID";
27+
28+
@interface BYOAuthTests : FIRAuthE2eTestsBase
29+
30+
@end
31+
32+
@implementation BYOAuthTests
33+
34+
/** Test sign in with a valid BYOAuth token retrived from a remote server. */
35+
- (void)testSignInWithValidBYOAuthToken {
36+
NSError *error;
37+
NSString *customToken = [NSString stringWithContentsOfURL:[NSURL URLWithString:kCustomTokenUrl]
38+
encoding:NSUTF8StringEncoding
39+
error:&error];
40+
if (!customToken) {
41+
GREYFail(@"There was an error retrieving the custom token: %@", error);
42+
}
43+
44+
[[[EarlGrey selectElementWithMatcher:grey_allOf(grey_text(@"Sign In (BYOAuth)"),
45+
grey_sufficientlyVisible(), nil)]
46+
usingSearchAction:grey_scrollInDirection(kGREYDirectionDown, kShortScrollDistance)
47+
onElementWithMatcher:grey_allOf(grey_scrollView(), grey_kindOfClass([UITableView class]),
48+
nil)] performAction:grey_tap()];
49+
50+
[[[EarlGrey selectElementWithMatcher:grey_kindOfClass([UITextView class])]
51+
performAction:grey_replaceText(customToken)] assertWithMatcher:grey_text(customToken)];
52+
53+
[[EarlGrey selectElementWithMatcher:grey_text(@"Done")] performAction:grey_tap()];
54+
55+
[self waitForElementWithText:@"OK" withDelay:kWaitForElementTimeOut];
56+
57+
[[EarlGrey selectElementWithMatcher:grey_text(@"OK")] performAction:grey_tap()];
58+
59+
[[[EarlGrey selectElementWithMatcher:grey_allOf(grey_text(kTestingAccountUserID),
60+
grey_sufficientlyVisible(), nil)]
61+
usingSearchAction:grey_scrollInDirection(kGREYDirectionUp, kShortScrollDistance)
62+
onElementWithMatcher:grey_allOf(grey_scrollView(), grey_kindOfClass([UITableView class]),
63+
nil)] assertWithMatcher:grey_sufficientlyVisible()];
64+
}
65+
66+
- (void)testSignInWithInvalidBYOAuthToken {
67+
[[[EarlGrey selectElementWithMatcher:grey_allOf(grey_text(@"Sign In (BYOAuth)"),
68+
grey_sufficientlyVisible(), nil)]
69+
usingSearchAction:grey_scrollInDirection(kGREYDirectionDown, kShortScrollDistance)
70+
onElementWithMatcher:grey_allOf(grey_scrollView(), grey_kindOfClass([UITableView class]),
71+
nil)] performAction:grey_tap()];
72+
73+
[[[EarlGrey selectElementWithMatcher:grey_kindOfClass([UITextView class])]
74+
performAction:grey_replaceText(kInvalidCustomToken)]
75+
assertWithMatcher:grey_text(kInvalidCustomToken)];
76+
77+
[[EarlGrey selectElementWithMatcher:grey_text(@"Done")] performAction:grey_tap()];
78+
79+
NSString *invalidTokenErrorMessage = @"Sign-In Error";
80+
81+
[self waitForElementWithText:invalidTokenErrorMessage withDelay:kWaitForElementTimeOut];
82+
83+
[[EarlGrey selectElementWithMatcher:grey_text(@"OK")] performAction:grey_tap()];
84+
}
85+
86+
@end
+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright 2017 Google
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#import "FIRAuthE2eTestsBase.h"
18+
19+
@interface FIRAuthE2eTests : FIRAuthE2eTestsBase
20+
21+
@end
22+
23+
@implementation FIRAuthE2eTests
24+
25+
- (void)testSignInExistingUser {
26+
NSString *email = @"[email protected]";
27+
[[[EarlGrey selectElementWithMatcher:grey_allOf(grey_text(@"Sign in with Email/Password"),
28+
grey_sufficientlyVisible(), nil)]
29+
usingSearchAction:grey_scrollInDirection(kGREYDirectionDown, kShortScrollDistance)
30+
onElementWithMatcher:grey_allOf(grey_scrollView(), grey_kindOfClass([UITableView class]),
31+
nil)] performAction:grey_tap()];
32+
33+
id<GREYMatcher> comfirmationButtonMatcher =
34+
grey_allOf(grey_kindOfClass([UILabel class]), grey_accessibilityLabel(@"OK"), nil);
35+
36+
[[EarlGrey selectElementWithMatcher:
37+
#warning TODO Add accessibilityIdentifiers for the elements.
38+
grey_kindOfClass(NSClassFromString(@"_UIAlertControllerView"))]
39+
performAction:grey_typeText(email)];
40+
41+
[[EarlGrey selectElementWithMatcher:comfirmationButtonMatcher] performAction:grey_tap()];
42+
43+
[[EarlGrey
44+
selectElementWithMatcher:grey_kindOfClass(NSClassFromString(@"_UIAlertControllerView"))]
45+
performAction:grey_typeText(@"password")];
46+
47+
[[EarlGrey selectElementWithMatcher:comfirmationButtonMatcher] performAction:grey_tap()];
48+
49+
[[[EarlGrey
50+
selectElementWithMatcher:grey_allOf(grey_text(email), grey_sufficientlyVisible(), nil)]
51+
usingSearchAction:grey_scrollInDirection(kGREYDirectionUp, kShortScrollDistance)
52+
onElementWithMatcher:grey_allOf(grey_scrollView(), grey_kindOfClass([UITableView class]),
53+
nil)] assertWithMatcher:grey_sufficientlyVisible()];
54+
}
55+
56+
@end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright 2019 Google
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#import <XCTest/XCTest.h>
18+
19+
#import <EarlGrey/EarlGrey.h>
20+
21+
#import "FirebaseAuth.h"
22+
23+
NS_ASSUME_NONNULL_BEGIN
24+
25+
extern CGFloat const kShortScrollDistance;
26+
27+
extern NSTimeInterval const kWaitForElementTimeOut;
28+
29+
/** Convenience function for EarlGrey tests. */
30+
id<GREYMatcher> grey_scrollView(void);
31+
32+
@interface FIRAuthE2eTestsBase : XCTestCase
33+
34+
/** Sign out current account. */
35+
- (void)signOut;
36+
37+
/** Wait for an element with text to appear. */
38+
- (void)waitForElementWithText:(NSString *)text withDelay:(NSTimeInterval)maxDelay;
39+
40+
@end
41+
42+
NS_ASSUME_NONNULL_END
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright 2019 Google
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#import "FIRAuthE2eTestsBase.h"
18+
19+
CGFloat const kShortScrollDistance = 400;
20+
21+
NSTimeInterval const kWaitForElementTimeOut = 15;
22+
23+
/** Convenience function for EarlGrey tests. */
24+
id<GREYMatcher> grey_scrollView(void) {
25+
return [GREYMatchers matcherForKindOfClass:[UIScrollView class]];
26+
}
27+
28+
@implementation FIRAuthE2eTestsBase
29+
30+
/** To reset the app so that each test sees the app in a clean state. */
31+
- (void)setUp {
32+
[super setUp];
33+
34+
[self signOut];
35+
36+
[[EarlGrey selectElementWithMatcher:grey_allOf(grey_scrollView(),
37+
grey_kindOfClass([UITableView class]), nil)]
38+
performAction:grey_scrollToContentEdge(kGREYContentEdgeTop)];
39+
}
40+
41+
- (void)tearDown {
42+
[super tearDown];
43+
}
44+
45+
/** Sign out current account. */
46+
- (void)signOut {
47+
NSError *signOutError;
48+
BOOL status = [[FIRAuth auth] signOut:&signOutError];
49+
50+
// Just log the error because we don't want to fail the test if signing out fails.
51+
if (!status) {
52+
NSLog(@"Error signing out: %@", signOutError);
53+
}
54+
}
55+
56+
/** Wait for an element with text to appear. */
57+
- (void)waitForElementWithText:(NSString *)text withDelay:(NSTimeInterval)maxDelay {
58+
GREYCondition *displayed =
59+
[GREYCondition conditionWithName:@"Wait for element"
60+
block:^BOOL {
61+
NSError *error = nil;
62+
[[EarlGrey selectElementWithMatcher:grey_text(text)]
63+
assertWithMatcher:grey_sufficientlyVisible()
64+
error:&error];
65+
return !error;
66+
}];
67+
GREYAssertTrue([displayed waitWithTimeout:maxDelay], @"Failed to wait for element '%@'.", text);
68+
}
69+
70+
@end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright 2018 Google
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#import "FIRAuthE2eTestsBase.h"
18+
19+
@interface VerifyIOSClientTests : FIRAuthE2eTestsBase
20+
21+
@end
22+
23+
@implementation VerifyIOSClientTests
24+
25+
/** Test verify ios client*/
26+
- (void)testVerifyIOSClient {
27+
[[[EarlGrey selectElementWithMatcher:grey_allOf(grey_text(@"Verify iOS client"),
28+
grey_sufficientlyVisible(), nil)]
29+
usingSearchAction:grey_scrollInDirection(kGREYDirectionDown, kShortScrollDistance)
30+
onElementWithMatcher:grey_allOf(grey_scrollView(), grey_kindOfClass([UITableView class]),
31+
nil)] performAction:grey_tap()];
32+
33+
[self waitForElementWithText:@"OK" withDelay:kWaitForElementTimeOut];
34+
35+
[[EarlGrey selectElementWithMatcher:grey_text(@"OK")] performAction:grey_tap()];
36+
}
37+
38+
@end

0 commit comments

Comments
 (0)