1
00:00:05,970 --> 00:00:09,050
Hey everybody has a go and this is Caleb with slopes dot com.

2
00:00:09,060 --> 00:00:13,250
And in this video we're going to talk about UI testing navigation.

3
00:00:13,270 --> 00:00:13,790
OK.

4
00:00:13,920 --> 00:00:16,360
There's a lot of different things we can do to test navigation.

5
00:00:16,360 --> 00:00:21,450
And I want to show you the app that is the start of project for what we're going to be learning.

6
00:00:21,510 --> 00:00:26,430
So I'm going to pull it up here in the simulator it's called bored to death and hopefully you're not

7
00:00:26,430 --> 00:00:32,220
bored to death while watching this but basically it's a simple app with an onboarding experience get

8
00:00:32,220 --> 00:00:33,660
it bored to death.

9
00:00:33,690 --> 00:00:40,800
Onboarding anyway and basically as you swipe through these different cards there are different onboarding

10
00:00:40,800 --> 00:00:44,750
experiences that just kind of describes the app what they're going to be doing.

11
00:00:44,850 --> 00:00:50,220
And then when they click Done it goes ahead and it dismisses the onboarding experience.

12
00:00:50,220 --> 00:00:56,670
Then of course if you were to come back into this and open it back up the user defaults save that you've

13
00:00:56,670 --> 00:01:00,360
seen that you've read through it and the onboarding no longer shows up.

14
00:01:00,360 --> 00:01:04,530
So let's go ahead and let's take a quick look through the code before we get into adding our testing

15
00:01:04,530 --> 00:01:06,930
target and adding some tests.

16
00:01:06,930 --> 00:01:14,520
Basically it is a UI page view controller already and we create a couple of instances we add them in

17
00:01:14,760 --> 00:01:19,680
to our page view controller using the proper delegate methods.

18
00:01:19,680 --> 00:01:27,000
We set up the indexes to basically show The View controllers in an ordered way and then essentially

19
00:01:27,000 --> 00:01:35,610
our onboarding page ADC when the done button is pressed on an instance of the onboarding page Visi like

20
00:01:35,610 --> 00:01:35,900
here.

21
00:01:35,910 --> 00:01:43,320
When I click the done button what it does is it sets our user defaults to allow our onboarding completed

22
00:01:43,350 --> 00:01:52,320
boolean to be set to true and therefore when we load up our view controller when this VC pops up if

23
00:01:52,410 --> 00:01:59,310
the onboarding View Controller property which is actually stored in this extension k it has been set

24
00:01:59,310 --> 00:02:01,010
to true.

25
00:02:01,140 --> 00:02:04,980
We're basically going to only present it if it's false.

26
00:02:04,980 --> 00:02:07,490
So once it's true it no longer presents.

27
00:02:07,610 --> 00:02:09,560
That's that so pretty easy stuff.

28
00:02:09,570 --> 00:02:11,760
Basic little onboarding experience.

29
00:02:11,880 --> 00:02:12,450
And if you want.

30
00:02:12,450 --> 00:02:15,550
You can use this code for your own onboarding experience in your app.

31
00:02:15,620 --> 00:02:16,800
It's up to you.

32
00:02:16,800 --> 00:02:19,770
But we're going to go ahead and add a testing target.

33
00:02:19,770 --> 00:02:28,080
So go ahead and click on File new target and we're going to be adding an iOS UI testing but also double

34
00:02:28,080 --> 00:02:29,060
click on that.

35
00:02:29,220 --> 00:02:31,580
And bored to death you eye test is fine.

36
00:02:31,740 --> 00:02:32,750
Click Finish.

37
00:02:32,790 --> 00:02:36,510
And there we go we've got ourselves a unit testing bundle.

38
00:02:36,570 --> 00:02:43,230
So go ahead and open up the board to death test file here and we're going to set it up just like we

39
00:02:43,230 --> 00:02:49,800
did in a previous video to essentially create an instance of our application and we're going to set

40
00:02:49,800 --> 00:02:57,240
it up so that when we run our app it automatically will launch and basically do a quick little test

41
00:02:57,240 --> 00:02:58,200
of navigation.

42
00:02:58,200 --> 00:03:05,070
So obviously as we are testing our onboarding experience we're testing the navigation of swiping through

43
00:03:05,070 --> 00:03:06,240
a particular experience.

44
00:03:06,270 --> 00:03:07,970
And I want to show you how to do that.

45
00:03:07,980 --> 00:03:13,440
So what I'm going to do is I'm going actually get rid of all these comments and random stuff get rid

46
00:03:13,440 --> 00:03:17,570
of that and then get rid of this sample test and to begin.

47
00:03:17,570 --> 00:03:24,250
I'm going to go ahead and create a variable called app and it's going to be of type C UI application.

48
00:03:24,510 --> 00:03:28,350
Then in our setup function we're going to go ahead and instantiate it.

49
00:03:28,380 --> 00:03:37,710
App equals X application then we're going to set the property continue after failure to be false because

50
00:03:38,280 --> 00:03:44,100
like best practices state if we had a single test that does not pass we should not be doing this so

51
00:03:44,100 --> 00:03:48,600
we're going to actually fail the entire thing if one test fails.

52
00:03:48,600 --> 00:03:54,060
So that's set up in the tear down function we're going to set up to be equal to nil so that every single

53
00:03:54,060 --> 00:03:58,840
time a new test runs we get a fresh instance of our application.

54
00:03:58,940 --> 00:04:05,100
OK now we are going to talk in a future video about App State and we're going to talk about how we can

55
00:04:05,100 --> 00:04:11,880
actually reset our app state every time because user defaults if we set up an instance of our application

56
00:04:11,910 --> 00:04:14,850
if we run it again those user defaults will still be there.

57
00:04:14,850 --> 00:04:19,980
So we're going to set it up so that we can actually essentially like delete the app and then reinstall

58
00:04:19,980 --> 00:04:21,510
it with fresh user defaults.

59
00:04:21,540 --> 00:04:22,050
It's pretty cool.

60
00:04:22,050 --> 00:04:26,970
We'll talk about it later but for now let's go ahead and write our first test for this application.

61
00:04:26,970 --> 00:04:33,630
So type phunk test and we're testing the onboarding so we can say that then we're going to say what

62
00:04:33,630 --> 00:04:34,360
we're testing.

63
00:04:34,440 --> 00:04:40,140
Well the swiping we're going to test the swiping on the page controller so just say when swiped.

64
00:04:40,140 --> 00:04:42,060
That's what we're testing is when it is swiped.

65
00:04:42,060 --> 00:04:43,390
What's it supposed to do.

66
00:04:43,410 --> 00:04:45,270
It should load the next controller.

67
00:04:45,270 --> 00:04:49,600
So go ahead and just type next VC loads.

68
00:04:50,070 --> 00:04:50,810
OK.

69
00:04:51,210 --> 00:04:53,490
Now this is where we launch our application.

70
00:04:53,490 --> 00:05:00,660
Every test we should launch our instance of X-C UI application so type app launch and there goes it

71
00:05:00,660 --> 00:05:04,060
launches and it'll start you know displaying in the console here.

72
00:05:04,080 --> 00:05:05,780
We've set that up.

73
00:05:05,990 --> 00:05:07,390
But it launches Aryeh.

74
00:05:07,610 --> 00:05:13,310
And now what we need to do is we need to verify that a something from our screen that we know will be

75
00:05:13,310 --> 00:05:13,820
there.

76
00:05:13,910 --> 00:05:17,730
Whoops let me delete this actually because you know user defaults saved that.

77
00:05:17,780 --> 00:05:20,000
I've already gone through onboarding.

78
00:05:20,160 --> 00:05:24,920
There is a label on the first screen that's displayed and this should be displaying every time it says

79
00:05:24,920 --> 00:05:26,750
welcome to bored to death.

80
00:05:26,750 --> 00:05:32,160
So what I'm going to do is I'm going to check that that is indeed showing by typing ex-city assert.

81
00:05:32,170 --> 00:05:33,000
True.

82
00:05:33,140 --> 00:05:40,490
I'm going to assert that the label welcome to bored to death is showing or that it exists on the screen.

83
00:05:40,810 --> 00:05:48,320
So type app OK and we're going to access a property called static texts K and static text basically

84
00:05:48,980 --> 00:05:55,790
is a way that we can query all of the static texts or the labels on the screen and I can search for

85
00:05:55,790 --> 00:06:02,540
a particular content of a label like welcome to bored to death and make sure that you're typing that

86
00:06:02,540 --> 00:06:03,480
case sensitive.

87
00:06:03,500 --> 00:06:07,840
It's probably best to put this inside of a constant file like I have done here.

88
00:06:07,850 --> 00:06:13,070
These are basically just non string identifiers for string properties so that I can't type them wrong

89
00:06:13,700 --> 00:06:15,890
but I'm just going to go ahead and leave that as it is.

90
00:06:15,890 --> 00:06:16,440
OK.

91
00:06:16,760 --> 00:06:22,280
Now we're going to go ahead and check in the static text for this particular label and type.

92
00:06:22,280 --> 00:06:24,370
Dot exists.

93
00:06:24,550 --> 00:06:25,340
OK.

94
00:06:25,430 --> 00:06:30,170
And what that's going to return is a Boolean if it exists it will return true if it doesn't it will

95
00:06:30,170 --> 00:06:31,230
return false.

96
00:06:31,250 --> 00:06:33,190
So it should return true.

97
00:06:33,200 --> 00:06:34,700
And that means our test will pass.

98
00:06:34,730 --> 00:06:36,170
If it does exist.

99
00:06:36,170 --> 00:06:40,200
So let's actually go ahead and let's just run this first to make sure that it works.

100
00:06:40,450 --> 00:06:42,800
Click the little diamond there and the test will run.

101
00:06:42,800 --> 00:06:46,880
Our application will pop open and our test should pass.

102
00:06:46,880 --> 00:06:51,060
But of course our test is not actually testing whether or not this label is there.

103
00:06:51,080 --> 00:06:53,930
We're testing to make sure the next Visi loads.

104
00:06:53,930 --> 00:06:56,030
Now of course our test passes.

105
00:06:56,090 --> 00:07:02,740
Now if I were to remove that label obviously the test would fail if I were to change that label.

106
00:07:02,740 --> 00:07:07,430
The test would fail which is why testing is so amazing because it ensures that things stay exactly the

107
00:07:07,430 --> 00:07:08,980
way they were when everything was good.

108
00:07:09,140 --> 00:07:09,920
Okay that's perfect.

109
00:07:09,920 --> 00:07:12,980
So now we want to test navigation.

110
00:07:12,980 --> 00:07:18,560
We want to make sure that we are able to actually swipe through our apps so all we have to do to type

111
00:07:18,560 --> 00:07:24,330
that are all we have to do to make that happen is type app dot and check it out.

112
00:07:24,380 --> 00:07:32,660
I can call swipe swipe left swipe up down or right and you can specifically set where a touchpoint goes

113
00:07:32,660 --> 00:07:34,010
down on the screen and to where.

114
00:07:34,010 --> 00:07:40,000
Swipes but just for a simple swipe left gesture this function works just fine.

115
00:07:40,010 --> 00:07:47,360
So if we came into our app and swipe left obviously welcome to bored to death no longer exists.

116
00:07:47,360 --> 00:07:53,810
But now there's new content so we can actually go ahead and type ex-city assert true.

117
00:07:54,050 --> 00:07:57,020
And we can check to see if our new label shows up.

118
00:07:57,020 --> 00:08:05,030
So app dot static texts like so put some square brackets there and we're going to go ahead and search

119
00:08:05,150 --> 00:08:09,640
for custom puppy content.

120
00:08:09,740 --> 00:08:11,630
And of course I typed that incorrectly.

121
00:08:11,660 --> 00:08:17,240
Thankfully our test would catch this but we're going to check to see if that label exists and if it

122
00:08:17,270 --> 00:08:19,320
does that means that our test is good.

123
00:08:19,340 --> 00:08:25,040
It means when swiped the next VC is loading because this content is exclusive to that controller.

124
00:08:25,070 --> 00:08:27,450
So let's go ahead and run our test.

125
00:08:27,450 --> 00:08:29,130
Click that little diamond shape.

126
00:08:29,180 --> 00:08:34,130
It should run our test and you'll actually see it swipe on the screen which is pretty cool.

127
00:08:34,130 --> 00:08:35,570
So it's going to go ahead and load it.

128
00:08:35,570 --> 00:08:37,250
It will crash and rebuild it.

129
00:08:37,250 --> 00:08:40,810
We get a swipe action here or we should.

130
00:08:40,800 --> 00:08:43,550
Anyway here we go.

131
00:08:46,610 --> 00:08:50,550
The app launched we checked to see if it existed.

132
00:08:51,360 --> 00:08:58,350
And the test fails so failure requesting automation session for Stoltze apps waiting for Target to check

133
00:08:58,350 --> 00:08:58,440
in.

134
00:08:58,440 --> 00:09:03,980
OK so if this happens just go ahead and actually delete the instance of the application UI.

135
00:09:03,990 --> 00:09:05,840
Testing is a bit buggy.

136
00:09:05,940 --> 00:09:06,820
Or it can be.

137
00:09:06,930 --> 00:09:10,070
So you'll go ahead and try it one more time if you get that issue.

138
00:09:10,170 --> 00:09:13,110
And if you don't then you should be just fine.

139
00:09:13,120 --> 00:09:13,770
It should run.

140
00:09:13,770 --> 00:09:17,910
It should pass because what we've done has basically proven that this works OK.

141
00:09:17,970 --> 00:09:20,220
Did you see that it successfully swiped.

142
00:09:20,310 --> 00:09:24,200
So sometimes it has a hard time getting a hold of the instance of the app that we made.

143
00:09:24,360 --> 00:09:30,750
But what happened was it opened our app it checked for the starting label swipe left and it checked

144
00:09:30,750 --> 00:09:33,210
for the new label so our test passes.

145
00:09:33,300 --> 00:09:39,490
We've successfully navigated through our application and we have verified that a certain label exists.

146
00:09:39,510 --> 00:09:41,610
This is awesome guys this is so so cool.

147
00:09:41,610 --> 00:09:46,720
Now there is a more elegant way to do this and we're actually going to talk about that in the next video.

148
00:09:46,830 --> 00:09:53,970
But for now this is a great intro to how to navigate through your application in Iowa UI testing.

149
00:09:53,970 --> 00:09:59,610
So we're going to move on to the next video and we're going to basically test to see if particular views

150
00:09:59,670 --> 00:10:03,540
are visible and we're going to actually learn a little bit more elegant of a way to see if something

151
00:10:03,540 --> 00:10:04,680
is on the screen or not.

152
00:10:04,680 --> 00:10:06,790
So let's head over to the next video.

153
00:10:06,900 --> 00:10:07,780
I'll see there.
