AssistantTester.m 4.42 KB
Newer Older
DanmeiChen's avatar
DanmeiChen committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
 * Copyright (c) 2010-2019 Belledonne Communications SARL.
 *
 * This file is part of linphone-iphone
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
19

20
#import "AssistantTester.h"
Guillaume BIENKOWSKI's avatar
Guillaume BIENKOWSKI committed
21
#import <KIF/KIF.h>
22
#import "LinphoneManager.h"
23

24
@implementation AssistantTester
25 26

- (void)beforeEach {
27 28 29
	[super beforeEach];
	[UIView setAnimationsEnabled:false];

30 31
	[tester tapViewWithAccessibilityLabel:@"Side menu button"];
	[tester tapViewWithAccessibilityLabel:@"Assistant"];
32 33
}

34
- (void)afterEach {
35
	[super afterEach];
36
	[LinphoneManager.instance removeAllAccounts];
37 38 39
	if ([tester tryFindingTappableViewWithAccessibilityLabel:@"Cancel" error:nil]) {
		[tester tapViewWithAccessibilityLabel:@"Cancel"];
	}
40
	[tester tapViewWithAccessibilityLabel:@"Dialer"];
41 42
}

Guillaume BIENKOWSKI's avatar
Guillaume BIENKOWSKI committed
43 44
#pragma mark - Utilities

45
- (void)_linphoneLogin:(NSString *)username withPW:(NSString *)pw {
46
	[tester tapViewWithAccessibilityLabel:@"Use Linphone account"];
47 48 49

	[tester enterText:username intoViewWithAccessibilityLabel:@"Username"];
	[tester enterText:pw intoViewWithAccessibilityLabel:@"Password"];
Guillaume BIENKOWSKI's avatar
Guillaume BIENKOWSKI committed
50

51
	[tester tapViewWithAccessibilityLabel:@"Login"];
52
}
Guillaume BIENKOWSKI's avatar
Guillaume BIENKOWSKI committed
53

54
- (void)_externalLoginWithProtocol:(NSString *)protocol {
55
	[tester tapViewWithAccessibilityLabel:@"Use SIP account"];
56 57

	[tester enterText:[self me] intoViewWithAccessibilityLabel:@"Username"];
58
	[tester enterText:[self me] intoViewWithAccessibilityLabel:@"Password"];
59
	[tester clearTextFromViewWithAccessibilityLabel:@"Domain"];
60 61 62
	[tester enterText:[self accountDomain] intoViewWithAccessibilityLabel:@"Domain"];
	[tester tapViewWithAccessibilityLabel:protocol];

63
	[tester tapViewWithAccessibilityLabel:@"Login"];
Guillaume BIENKOWSKI's avatar
Guillaume BIENKOWSKI committed
64 65 66 67
}

#pragma mark - Tests

68 69
- (void)testAccountCreation {
	NSString *username = [NSString stringWithFormat:@"%@-%.2f", [self getUUID], [[NSDate date] timeIntervalSince1970]];
70
	[tester tapViewWithAccessibilityLabel:@"Create account" traits:UIAccessibilityTraitButton];
71 72 73

	[tester enterText:username intoViewWithAccessibilityLabel:@"Username"];
	[tester enterText:username intoViewWithAccessibilityLabel:@"Password "];
74
	[tester enterText:username intoViewWithAccessibilityLabel:@"Password confirmation"];
75 76
	[tester enterText:@"testios@.dev.null" intoViewWithAccessibilityLabel:@"Email"];

77
	[tester tapViewWithAccessibilityLabel:@"Create account" traits:UIAccessibilityTraitButton];
78

79 80
	[tester waitForViewWithAccessibilityLabel:@"Finish configuration" traits:UIAccessibilityTraitButton];
	[tester tapViewWithAccessibilityLabel:@"Finish configuration"];
81

82 83
	[tester waitForViewWithAccessibilityLabel:@"Account validation failed"];
	[tester tapViewWithAccessibilityLabel:@"Skip verification"];
84 85
}

86 87
- (void)testExternalLoginWithTCP {
	[self _externalLoginWithProtocol:@"TCP"];
88
	[self waitForRegistration];
89 90 91 92
}

- (void)testExternalLoginWithTLS {
	[self _externalLoginWithProtocol:@"TLS"];
93
	[self waitForRegistration];
94 95
}

96 97
- (void)testExternalLoginWithUDP {
	[self _externalLoginWithProtocol:@"UDP"];
98
	[self waitForRegistration];
99 100
}

Guillaume BIENKOWSKI's avatar
Guillaume BIENKOWSKI committed
101
- (void)testLinphoneLogin {
102
	[self _linphoneLogin:@"testios" withPW:@"testtest"];
103
	[self waitForRegistration];
104 105
}

Guillaume BIENKOWSKI's avatar
Guillaume BIENKOWSKI committed
106
- (void)testLinphoneLoginWithBadPassword {
107
	[self _linphoneLogin:@"testios" withPW:@"badPass"];
108 109 110 111

	[self setInvalidAccountSet:true];

	UIView *alertViewText =
112
		[tester waitForViewWithAccessibilityLabel:@"Connection failure" traits:UIAccessibilityTraitStaticText];
113
	if (alertViewText) {
114
		UIView *reason = [tester waitForViewWithAccessibilityLabel:@"Bad credentials, check your account settings"
115
															traits:UIAccessibilityTraitStaticText];
116 117 118
		if (reason == nil) {
			[tester fail];
		} else {
119
			[tester tapViewWithAccessibilityLabel:@"Continue"];
120 121 122 123
		}
	} else {
		[tester fail];
	}
Guillaume BIENKOWSKI's avatar
Guillaume BIENKOWSKI committed
124 125
}

126
- (void)testRemoteProvisioning {
127
	[tester tapViewWithAccessibilityLabel:@"Fetch remote configuration"];
128
	[tester enterText:@"smtp.linphone.org/testios_xml" intoViewWithAccessibilityLabel:@"URL"];
129
	[tester tapViewWithAccessibilityLabel:@"Fetch and apply"];
130 131
	[self waitForRegistration];
}
132
@end