1
00:00:06,110 --> 00:00:11,140
Everybody has a go and this is Caleb with Debb slopes and in this video we're going to be testing views

2
00:00:11,440 --> 00:00:15,500
to determine whether or not they have presented or have stopped presenting.

3
00:00:15,550 --> 00:00:20,950
And we're also going to test you alerts because those you know can be kind of pesky And we're going

4
00:00:20,950 --> 00:00:25,480
to I'm going to show you how to you I test views as well as alerts.

5
00:00:25,510 --> 00:00:32,560
So pull up in your project and what we're going to do is we're going to go ahead and basically go into

6
00:00:33,180 --> 00:00:35,210
our onboarding Visi or no.

7
00:00:35,230 --> 00:00:41,440
Rather our onboarding page AVC and that is the one that when you open the app when you come into here

8
00:00:41,830 --> 00:00:49,270
this is one of the pages but the done button when we tap done obviously user defaults completes it and

9
00:00:49,270 --> 00:00:50,320
it dismisses.

10
00:00:50,320 --> 00:00:55,860
I'm going to go ahead and comment that out for now and I'm going to add a UI alert controller so let.

11
00:00:55,860 --> 00:00:58,950
Alert equals UI alert controller.

12
00:00:59,170 --> 00:00:59,890
Whoops.

13
00:01:00,160 --> 00:01:01,280
There we go.

14
00:01:01,780 --> 00:01:05,630
And we're going to go ahead and give this thing a title saying you did it.

15
00:01:05,650 --> 00:01:06,580
Yay.

16
00:01:06,880 --> 00:01:09,310
Congratulations.

17
00:01:09,880 --> 00:01:18,230
You survived our onboarding experience and of course the style will be an alert.

18
00:01:18,430 --> 00:01:22,310
OK so next we need to add an alert action to give it a button.

19
00:01:22,330 --> 00:01:24,530
So type alert action.

20
00:01:24,610 --> 00:01:25,930
Give this one a title as well.

21
00:01:25,930 --> 00:01:30,080
This is what the button actually says so it's going to just say awesome.

22
00:01:30,180 --> 00:01:34,760
The style will be default and we don't need a handler so just make that call.

23
00:01:34,810 --> 00:01:41,110
Next we need to go ahead and add the action to the alert by typing alert an action and type an alert

24
00:01:41,140 --> 00:01:47,460
action and then we're going to present this just like any other view controller present alert.

25
00:01:47,590 --> 00:01:50,560
And of course animated is true and completion.

26
00:01:50,560 --> 00:01:51,600
We don't really care about.

27
00:01:51,730 --> 00:01:56,320
So if I actually build and run this before testing it we're going to just go ahead and see that when

28
00:01:56,320 --> 00:02:01,420
we get to the very end we will tap the done button and it will present an alert.

29
00:02:01,420 --> 00:02:02,280
So check it out.

30
00:02:02,290 --> 00:02:03,970
Boom an alert pops up.

31
00:02:03,970 --> 00:02:04,450
We tap.

32
00:02:04,450 --> 00:02:05,090
Awesome.

33
00:02:05,110 --> 00:02:06,680
It dismisses k.

34
00:02:06,700 --> 00:02:07,550
Very cool stuff.

35
00:02:07,570 --> 00:02:12,610
So now let's go ahead and let's test it to make sure that that actually works the way that we want.

36
00:02:12,610 --> 00:02:22,090
So let's write a new test phunk test onboarding and we are testing when done button tapped.

37
00:02:22,090 --> 00:02:25,220
Presents alert.

38
00:02:25,300 --> 00:02:30,730
So we're going to go ahead and launch the app after launch because remember every test gets a new instance

39
00:02:30,940 --> 00:02:31,990
of our app.

40
00:02:32,080 --> 00:02:36,310
So we're going to go ahead and just swipe to the left two times.

41
00:02:36,680 --> 00:02:44,380
OK then we need to tap on the done button and to do that we're going to type app dot buttons wups app

42
00:02:44,410 --> 00:02:48,890
dot buttons and we can just go ahead and put some brackets here.

43
00:02:49,030 --> 00:02:54,250
And then in quotes we can go ahead and type what the name of the or the title of the button is and in

44
00:02:54,250 --> 00:02:57,270
this case it's done and to tap it.

45
00:02:57,280 --> 00:03:00,970
We just simply call DOT tap and that will tap the button.

46
00:03:00,970 --> 00:03:01,770
Very cool stuff.

47
00:03:01,780 --> 00:03:03,050
Very easy.

48
00:03:03,100 --> 00:03:08,290
And then of course that will actually go ahead and present our alert View Controller.

49
00:03:08,290 --> 00:03:11,740
And so then of course we need to check that it's actually there.

50
00:03:11,740 --> 00:03:14,580
So go into onboarding page AVC.

51
00:03:14,740 --> 00:03:17,780
And what we're going to do is we're going to go ahead and set alert.

52
00:03:18,010 --> 00:03:18,810
OK.

53
00:03:18,850 --> 00:03:30,450
Just alert dot accessibility identifier x ability let's go find the accessibility identifier.

54
00:03:30,550 --> 00:03:36,010
It's in here somewhere says Bill that he identifies.

55
00:03:36,050 --> 00:03:36,790
Oh you know what.

56
00:03:36,830 --> 00:03:37,410
I'm sorry.

57
00:03:37,520 --> 00:03:43,400
We need to go into alert dot view that accessibility identifier and we're going to set this just to

58
00:03:43,400 --> 00:03:48,890
be well I guess alert.

59
00:03:49,130 --> 00:03:49,830
OK.

60
00:03:50,210 --> 00:03:55,010
Now since I'm only using that once I'm not going to make a constant but I'm going to go into my tests

61
00:03:55,070 --> 00:04:02,090
now and what I can do is I can type LCT assert true and I can verify that it actually is there by typing

62
00:04:02,180 --> 00:04:05,660
app dot alerts.

63
00:04:05,720 --> 00:04:06,370
OK.

64
00:04:06,770 --> 00:04:10,840
And I can go ahead and actually search for a particular alert.

65
00:04:11,150 --> 00:04:12,140
And what did I name it.

66
00:04:12,140 --> 00:04:14,450
I named it alert.

67
00:04:14,540 --> 00:04:14,830
OK.

68
00:04:14,840 --> 00:04:21,590
And then we can type dot exists and if we run this test we should get a pass because it should show

69
00:04:21,590 --> 00:04:23,790
us that our alert exists.

70
00:04:23,810 --> 00:04:26,830
And so we're going to go ahead and pop open our application here.

71
00:04:26,900 --> 00:04:28,760
It's going to run that test.

72
00:04:28,880 --> 00:04:29,750
It will.

73
00:04:29,750 --> 00:04:30,910
Here we go.

74
00:04:32,150 --> 00:04:33,600
Launch our app.

75
00:04:33,680 --> 00:04:36,120
It'll swipe left twice swipe swipe.

76
00:04:36,220 --> 00:04:39,570
It will tap the done button and the test passes.

77
00:04:39,660 --> 00:04:40,020
OK.

78
00:04:40,040 --> 00:04:41,930
So that alert exists.

79
00:04:41,930 --> 00:04:43,820
Very very cool.

80
00:04:43,820 --> 00:04:46,430
Now we're going to go ahead and continue on.

81
00:04:46,430 --> 00:04:49,180
We know that the alert exists and let's make sure.

82
00:04:49,250 --> 00:04:49,690
Oh no.

83
00:04:49,700 --> 00:04:50,080
You know what.

84
00:04:50,080 --> 00:04:51,320
That actually that's our test.

85
00:04:51,320 --> 00:04:53,430
We're testing to make sure that it exists.

86
00:04:53,600 --> 00:04:55,490
So that test is now finished.

87
00:04:55,490 --> 00:05:00,200
Now in the previous video I told you that I would show you a more elegant way to check whether or not

88
00:05:00,230 --> 00:05:02,660
a certain view exists.

89
00:05:02,660 --> 00:05:03,470
OK.

90
00:05:03,560 --> 00:05:05,130
And there's a really cool way to do it.

91
00:05:05,150 --> 00:05:07,430
And I'm going to make some more space here to show you.

92
00:05:07,610 --> 00:05:13,280
But essentially we're going to create an extension of X-C UI application and we're going to create a

93
00:05:13,280 --> 00:05:19,420
boolean variable that is set depending on whether or not a certain view is visible.

94
00:05:19,430 --> 00:05:25,510
So go ahead and type extension X-C UI application and go ahead and type.

95
00:05:25,510 --> 00:05:33,660
Var is displaying onboarding of type bool OK.

96
00:05:33,860 --> 00:05:42,410
And then inside of this we're going to go ahead and return basically the onboarding view if the onboarding

97
00:05:42,410 --> 00:05:46,020
view controller is showing up if it exists.

98
00:05:46,130 --> 00:05:47,260
We will return the boolean.

99
00:05:47,270 --> 00:05:50,220
Otherwise if it doesn't exist it will return false.

100
00:05:50,210 --> 00:05:52,660
Now onboarding page visi.

101
00:05:52,670 --> 00:06:01,100
That is one of the pages that is shown right when when the onboarding is being displayed.

102
00:06:01,100 --> 00:06:05,450
And so what we're going to do is we're going to go into the UI page view controller and we're going

103
00:06:05,450 --> 00:06:07,720
to go ahead and take a look at what I've done here.

104
00:06:07,880 --> 00:06:12,100
Now I've set an accessibility identifier a view ID on board view.

105
00:06:12,110 --> 00:06:19,040
Now of course if you look it's really onboarding view and all I've done is set an accessibility identifier

106
00:06:19,080 --> 00:06:24,920
and that will basically allow us to check hey if a certain view with that name is visible we're going

107
00:06:24,920 --> 00:06:30,530
to return true so to access that what we need to type is other elements.

108
00:06:30,660 --> 00:06:35,190
That's kind of weird but there's not actually a property specifically for views.

109
00:06:35,300 --> 00:06:37,680
But what we can do is we can type in that identifier.

110
00:06:37,700 --> 00:06:39,320
But actually it's not a string.

111
00:06:39,440 --> 00:06:48,460
I can just take the name here view Id onboard view OK and I can type that in here view Id let's build

112
00:06:48,460 --> 00:06:54,300
it so we can actually access it on board view.

113
00:06:54,580 --> 00:06:55,130
OK.

114
00:06:55,360 --> 00:07:02,950
And then after that I can go ahead and type datt exists and we can build it and see if that works.

115
00:07:02,950 --> 00:07:05,040
Now of course we're not getting a problem here.

116
00:07:05,170 --> 00:07:11,920
It's having some trouble building and verifying and it's saying view use of unresolved identifier view

117
00:07:11,920 --> 00:07:13,220
Id onward view.

118
00:07:13,450 --> 00:07:20,040
The reason for that is we never imported our project so go ahead type at testable import.

119
00:07:20,440 --> 00:07:23,630
And the name is bored to death.

120
00:07:23,830 --> 00:07:26,790
OK now build and of course it can access that.

121
00:07:26,800 --> 00:07:27,730
My bad.

122
00:07:27,730 --> 00:07:28,930
So there we go.

123
00:07:28,930 --> 00:07:33,790
Basically what is happening is other elements checks through all the other elements that are not the

124
00:07:33,790 --> 00:07:39,870
ones that are prescribed like we could have checked for buttons we could have checked for static texts

125
00:07:39,880 --> 00:07:44,520
which checks all instances of label but other elements is for views.

126
00:07:44,530 --> 00:07:50,320
So this will be set to Boole whether or not this will be set to True or false depending on if the view

127
00:07:50,320 --> 00:07:51,140
is visible.

128
00:07:51,310 --> 00:08:02,980
So we have our identifiers set up we have where were we we are yet in our tests so we are basically

129
00:08:02,980 --> 00:08:06,770
going to say phunk test.

130
00:08:06,910 --> 00:08:09,360
We're going to test to make sure onboarding is visible.

131
00:08:09,370 --> 00:08:19,550
So go ahead and type phunk test and we're going to go ahead and type onboarding OK when finished Visi

132
00:08:19,570 --> 00:08:23,360
or let's say onboard Visi dismisses.

133
00:08:23,860 --> 00:08:24,940
OK.

134
00:08:25,120 --> 00:08:29,160
And what we can do is we can call app don't launch to launch the app from beginning.

135
00:08:29,320 --> 00:08:33,860
But then what we're going to do is we're going to check to see hey at the beginning is it showing.

136
00:08:34,060 --> 00:08:37,480
Then we'll go through the process to dismiss it and then we'll check again.

137
00:08:37,510 --> 00:08:38,110
If it shows.

138
00:08:38,140 --> 00:08:44,770
So go ahead and type ex-city assert true app dot and since we wrote an extension we can just type app

139
00:08:44,770 --> 00:08:49,780
dot is displaying onboarding and it's going to check for us then we're going to go ahead and go through

140
00:08:49,780 --> 00:08:56,320
the process of swiping through the onboarding tapping done and then checking to see if the test passes.

141
00:08:56,320 --> 00:09:01,520
So app dot swipe left app dot swipe left.

142
00:09:01,540 --> 00:09:03,310
Then we to tap on are done button.

143
00:09:03,310 --> 00:09:09,370
So app dot buttons and of course the name of that button is done.

144
00:09:09,370 --> 00:09:13,180
The title from the storyboard and then we're going to check again.

145
00:09:13,260 --> 00:09:16,180
Ex-city assert false.

146
00:09:16,650 --> 00:09:17,380
OK.

147
00:09:17,590 --> 00:09:22,000
App dot is displaying onboarding because at that point it should be false right.

148
00:09:22,000 --> 00:09:26,690
Let's go ahead and let's build this or test Diamond shows up and click on it to test it.

149
00:09:26,710 --> 00:09:28,060
And now let's see what happens.

150
00:09:28,060 --> 00:09:28,840
Oh look at that.

151
00:09:28,840 --> 00:09:31,200
We get a weird problem here.

152
00:09:31,210 --> 00:09:36,500
Let's go ahead and clean with a shift command K and then command B to build.

153
00:09:36,640 --> 00:09:38,410
That should fix us up here.

154
00:09:39,380 --> 00:09:41,530
Let's see if it'll build successfully.

155
00:09:41,540 --> 00:09:42,280
Looks like it is.

156
00:09:42,290 --> 00:09:42,800
Yep.

157
00:09:42,990 --> 00:09:47,580
OK so now let's go ahead and click the diamond to run just that test alone.

158
00:09:47,780 --> 00:09:54,000
But it's given me a weird problem it's saying that we are referencing it from something that's not linked.

159
00:09:54,020 --> 00:09:58,760
So you know what I'm going to actually go ahead and I'm going to save this and I'm going to actually

160
00:09:58,760 --> 00:10:02,700
quit out of X code and go back in just a second.

161
00:10:03,200 --> 00:10:05,680
Let's see if that'll fix our problem here.

162
00:10:07,690 --> 00:10:10,090
All right let's try that one more time.

163
00:10:10,130 --> 00:10:15,480
The onboarding should dismiss when I build this and it's given me a really weird error.

164
00:10:15,490 --> 00:10:16,830
I have not seen this before.

165
00:10:16,840 --> 00:10:18,590
So let's go look at what's going on.

166
00:10:18,940 --> 00:10:22,480
It's saying symbols not found for architecture.

167
00:10:22,920 --> 00:10:26,140
Xx 86 64.

168
00:10:26,200 --> 00:10:27,400
That's really bizarre.

169
00:10:27,400 --> 00:10:30,130
So let's see we imported our project.

170
00:10:30,430 --> 00:10:35,360
We have our application here let's clean it one more time.

171
00:10:35,620 --> 00:10:37,530
Yes that belongs to that.

172
00:10:37,540 --> 00:10:42,180
This all belongs to the proper project bored to death.

173
00:10:42,220 --> 00:10:43,560
UI tests.

174
00:10:43,710 --> 00:10:46,910
We have an extension that looks good.

175
00:10:46,910 --> 00:10:48,140
We have one test.

176
00:10:48,170 --> 00:10:49,770
Let's go ahead and do command you.

177
00:10:49,820 --> 00:10:51,620
Let's see if it's going to allow us to do it.

178
00:10:51,650 --> 00:10:56,060
Still saying no failed with exit code 2 555.

179
00:10:56,060 --> 00:10:58,670
So let's go ahead and let's quit the simulator here.

180
00:10:58,670 --> 00:11:00,430
Let's try that one more time.

181
00:11:02,300 --> 00:11:03,740
Really weird bugs here.

182
00:11:04,530 --> 00:11:06,240
Building OK it's exceeded.

183
00:11:06,240 --> 00:11:06,810
So that's good.

184
00:11:06,810 --> 00:11:08,610
The simulator is opening again.

185
00:11:08,610 --> 00:11:13,500
Hopefully that means we'll be able to run our tests very soon.

186
00:11:13,830 --> 00:11:20,180
Of course there are bugs even in you know really nice applications like X code there can still be issues.

187
00:11:20,310 --> 00:11:21,560
And let's see if we're going to run.

188
00:11:21,570 --> 00:11:21,900
OK.

189
00:11:21,930 --> 00:11:22,740
So it runs.

190
00:11:22,740 --> 00:11:24,800
Now our testing should work as well.

191
00:11:24,840 --> 00:11:29,280
So click test and we're still getting that error that is so weird.

192
00:11:30,050 --> 00:11:34,580
So you know what let's go ahead let's go back to our tests here.

193
00:11:34,910 --> 00:11:39,230
We're referencing the proper file here.

194
00:11:39,230 --> 00:11:39,640
You know what.

195
00:11:39,650 --> 00:11:44,900
Let me try just changing this back to the actual onboarding view.

196
00:11:45,020 --> 00:11:46,550
And let's see if that lets us test

197
00:11:50,240 --> 00:11:51,290
that is so weird.

198
00:11:51,290 --> 00:11:59,440
So for some reason it does not like referencing this Constance file even though it's public and it's

199
00:11:59,440 --> 00:12:02,350
linked it doesn't like that I was using that Constans files.

200
00:12:02,350 --> 00:12:04,980
That's the weirdest thing I've ever seen.

201
00:12:04,990 --> 00:12:05,280
OK.

202
00:12:05,290 --> 00:12:07,630
So we're testing our first test here we tap the button.

203
00:12:07,630 --> 00:12:08,720
The alert exists.

204
00:12:08,770 --> 00:12:12,810
Awesome that passes we're testing the onboarding when it's finished.

205
00:12:12,850 --> 00:12:14,770
The onboard Visi should dismiss.

206
00:12:14,770 --> 00:12:20,170
Here we go tap the button and we get a test failed because the onboarding is still displaying.

207
00:12:20,170 --> 00:12:24,710
So let's go back into I believe it was onboarding page visi.

208
00:12:25,000 --> 00:12:27,580
And we're actually going to go ahead and comment this out.

209
00:12:27,580 --> 00:12:33,100
For now we're going to go ahead and re or I guess re-enable this code.

210
00:12:33,100 --> 00:12:35,480
And now we're going to go run our tests once more.

211
00:12:35,470 --> 00:12:37,510
So let's go ahead and run them again.

212
00:12:37,510 --> 00:12:39,130
Now of course you know it's going to happen here.

213
00:12:39,130 --> 00:12:41,540
This test will now fail because there's no alert.

214
00:12:41,770 --> 00:12:48,860
And the top 10 or the bottom test will pass because our display will be you know dismissed.

215
00:12:49,240 --> 00:12:53,910
So there we go first test passes which is awesome or sorry first test fails.

216
00:12:54,040 --> 00:12:58,350
Second test is going to also fail.

217
00:12:58,360 --> 00:12:58,950
OK.

218
00:12:58,990 --> 00:13:01,810
Now you might be thinking wait a minute our code is good.

219
00:13:01,810 --> 00:13:02,960
Everything should be working.

220
00:13:03,040 --> 00:13:08,930
And that's exactly what brings us into needing to know about the apps state in the next video.

221
00:13:08,980 --> 00:13:15,310
We're going to go ahead and set up a little function in our app delegate that's basically going to delete

222
00:13:15,460 --> 00:13:20,510
the user defaults for every single time that we go in to our tests.

223
00:13:20,530 --> 00:13:25,960
Every test we run we should clear out the user defaults so we get a fresh app state every single time.

224
00:13:25,960 --> 00:13:28,360
Let's head over to the next video and let's fix this problem.

225
00:13:28,360 --> 00:13:29,110
I'll see you there.
