Hey everybody How's it going.
This is Caleb with Deb's slopes dot com and we're here with one final video on you.
Testing for now.
And basically we're going to talk about testing data in fields like text fields etc. etc. and so penélope
in your project here.
And we need to get into actually adding some text fields to our project.
We don't have any yet.
So go to main storyboard and we're going to go all the way back here to our interface visi.
Now let's go ahead and let's add in some text fields here.
And this is going to basically I want you to think of this as if you were creating some type of log
in flow for your application.
And of course you have an email field in a password field.
Right.
So I'm going to go ahead and actually duplicate this and then put it into a stack view.
OK so select both put it into a stack view and then I'm going to Pinet.
Let's do.
Yeah how about 300 from the top let's do 20 20 and let's give it a fixed height known at a fixed height.
Let's just let's just do that.
That's good.
Although Strange that's not supposed to I guess go over that.
So let's actually go ahead and delete this.
Let's move move the whole stack view actually.
And we're going to go ahead and pin this 20 from the bottom.
OK.
There we go.
Now I want to actually give it some spacing here so let's do 20 pieces of spacing or pieces at points
and so set a placeholder here for maybe email that looks good.
Set a placeholder here for password and we can even set it so that it is secure text entry for a password
that be pretty cool.
And now I'm going to go ahead and just say enter.
Well no I guess we are to have a placeholder text there.
Cool.
So I'm going to go ahead and change the background color of this to be green and the background color.
This one to be blue.
Just for fun.
And let's set the text color to be white again just for fun.
And then we're going to go ahead and link this to interface visi.
So let's select that let's go into the automatic connection there and let's go ahead and create some
Iby outlets for this.
So this will be email text field.
All righty.
And then this will be password textfield
field.
There we go.
And this is a pretty common way you know to do things pretty cool basic stuff.
And now if we want to test how this works we can just go straight into our UI tests.
OK.
And what we can do is we can test the input here so phunk test let's do email input.
That's what we're going to test.
So when given e-mail fills textfield let's just make sure that the text is actually going into our text
field.
That's important right.
So what we're going to do is we're going to go ahead and launch our app opt out launch then we're going
to go ahead and create an instance.
You can also do this check it out create an instance of our e-mail textfield.
So let email textfield equals app dot text fields.
Or you can also do text views but we're going to choose the one with a particular title so we're going
to go ahead and just say email already.
Now what I can do is I can call email textfield tap tap on the textfield and then we can type email
textfield dot type text and I can give it a string.
So my email could be Caleb.
Caleb at Debb slopes dot com.
And then what we're going to do is we're going to go ahead and say ex-city assert true.
Email textfield dot static texts we're going to go ahead and verify that the static text is in fact.
But def slopes.
OK.
So let's go ahead and let's actually run just this singular test.
Oh you know what.
It does not like that cannot convert value of x c UI element to type bool 0.
We need to do what exists of course we need to make sure that that is actually where it should be.
So perfect run this test.
Pull open your simulator and we can actually see it happen.
It's going to go ahead and launch our app and we'll see how we did.
Oh you know what our test will fail.
It's going to time out because we never actually go back to our UI.
So let's go ahead and let's say
interesting.
So do we have an instance of user defaults here.
We do not.
Let's go ahead and let's just go through the onboarding process just to make this a little bit easier
for us.
Let's run the test again instead of messing with user defaults in the test.
I'm actually just going to go ahead and go through the process where my code sets the user defaults.
You know you know how it goes.
And then we should be able to actually tap on our textfield type some text and then be done.
So all right then I don't know if you saw that I saw that it started typing but I don't know if it finished
so we're not going to actually have to move that textfield up to see if it's actually doing what it's
supposed to.
So I made a bad call putting it so low on the screen.
Let's go ahead and select that stack view again.
Move it up to the top ish side and sure 32 went up.
Let's do that again let's run our test.
OK here we go.
We're going to see what happens.
I'm only running this one test so that should be should be pretty cool if it does what I'm hoping it
does.
The thing I like about this is you can actually kind of simulate what a brand new user would be doing
in your application every time which is really cool.
OK.
Check it out.
That's awesome.
So that is pretty good.
It appears that we did not successfully find static text 0 because static text refers to labels.
We need to actually check to see if Yeah if email field at Caleb.
OK.
So what we're going to do is we're going to actually check app dot WIPs.
We're going to check to make sure that app dot text fields has one with this value because remember
at the beginning it has no value.
And of course at the end the call that exists now run this test.
And we should be able to successfully verify that our information is there.
It should open should type and then we should check to see if that textfield is there.
So swipe through dismiss awesome.
We're going to type and our test passes because that is then.
They're awesome.
Now we can do the same thing.
I'm going to actually go ahead and just copy this and paste it and it's going to be a different test
so password input
when given password.
Word fills textfield So we're going to need to go into the textfield that says password OK and it's
placeholder and we're going to type Manby mamby pamby unicorn's.
Sounds good.
Then we're going to check to verify that my password actually exists and if it does then we know our
test has passed.
So click the diamond open your simulator and we should see the test go through.
Should enter a password for me.
And yeah of course as this gets more complicated you can basically set up you know your code so that
if you don't have a username and password it wouldn't let you do what you want.
And it looks like you that did not work.
So interesting.
Hmm.
No match found.
Oh well this is still called e-mail password that's not going to make a difference.
But I'll go ahead and fix this.
Let's go ahead and let's head back to our storyboard here and see what the deal is.
So this has a placeholder for e-mail.
This has a placeholder for password.
Oh you know what I wonder if secure text entry is getting in the way.
Let's go ahead and let's test it and then see if that is in fact getting in the way.
Because I guess the text is obscured by the secure text entry.
We're checking if password is indeed there.
Then we tap on it then we type text.
And that should be it.
So swipe through
a tap on the textfield k we type our password.
That's awesome.
So I guess when you're testing leave it as plain text but when you submit it for production you can
always change it to you know secure text entry that's fine.
Well it's good to know that it really is very very secure even from you.
So this is how you can test the input on text fields text views et cetera et cetera to ensure that your
data is actually going in and is getting validated in the way that you hope you eye testing when combined
with unit testing is a very powerful way to ensure that future problems are never introduced into your
app because your tests will fail.
This is very very cool stuff.
And we're going to head over now to an exercise where you're going to put your knowledge of UI testing
to the test.