 Selamat datang ke POPETI GROUP. Pementerian pertama kita ada di IOS Automation XC-UI TESTS. Nama saya Kenneth dan saya IOS Engineer di POPETI GROUP. Saya suka JAL, X2 Programming. Di sini di PG, kami menerima banyak test. Sebenarnya, di IOS Reportatory, kami mempunyai lebih dari 1,000 test di Repo. Jalan Automation saya bermula dengan Calibash IOS dan kami sekarang bergerak ke IOS XC-UI TESTS. Jadi, kode yang diberitahu di selaks boleh diperkenalkan di sini. Jadi, jelas-jelas. Berapa banyak orang dalam bilik testa QA? Tidak. Pemenang? Bagus. Jadi, bagaimana pemenang pemenangan unit test? Bagus. Apa tentang test IOS Automation? Bagus. Bagus. Jadi, bagi orang yang tidak bermula menulis test IOS Automation saya harap ini akan menginsipkan anda kembali dan mulai menulis untuk projek sendiri. Jadi, agenda untuk hari ini saya akan berikan perjalanan ke IOS XC-UI TESTS dan berdasarkan beberapa perkembangan, kami akan mencuba menulis perbuatan anda dan kami akan mencuba menulis test IOS XC-UI TESTS. Selepas itu, kami akan menulis perbuatan perkembangan dan bagaimana kami boleh membawa perbuatan ini kepada test IOS XC-UI TESTS. Jadi, test IOS XC-UI TESTS adalah pemenangan pemenangan IOS Automation yang dibuat pada Xcode pada tahun lalu. Selepas itu, anda akan menulis test dengan mencuba perkembangan dan perkembangan pada pemenangan main app. Pemenangan IOS XC-UI TESTS menggunakan framework test XC-UI TESTS yang menggunakan pemenangan IOS XC-UI TESTS semasa anda mempunyai kelasa-kelasa dan memakai kelasa-kelasa dan menggunakan kelasa-kelasa. Apabila kami menulis test IOS XC-UI TESTS, kami membuat dan membangun perbuatan perkembangan dan perkembangan. Perkembangan perkembangan akan memperkenalkan perkembangan dan memperkenalkan kelasa-kelasa di jalan. Pemenangan IOS XC-UI TESTS tidak dapat melihat kelasa-kelasa. Jadi, untuk kelasa-kelasa ini, kami membuat perkembangan Blackboard. Jadi, tidak ada cara memakai mod. Kami tidak dapat menggunakan mod OC di IOS XC-UI TESTS. Pemenangan IOS XC-UI TESTS adalah kelasa-kelasa. Jadi, ini adalah contoh. Jadi, kita mulakan dengan bawah kelasa-kelasa di bawah. Jadi, apabila anda menggunakan kelasa-kelasa dan apabila kami memperkenalkan dengan kelasa-kelasa, XC-UI TESTS akan membuat kelasa-kelasa untuk anda. Sekejap lagi. Pemenangan IOS XC-UI TESTS adalah kelasa-kelasa dengan kelasa-kelasa dan XC-UI TESTS akan membuat kelasa-kelasa untuk anda. Jadi, saya tidak mengapa. Jadi, kelasa-kelasa di IOS XC-UI TESTS adalah kelasa-kelasa XC-UI TESTS. Jadi, daripada kelasa-kelasa, kelasa-kelasa adalah kelasa-kelasa dan menggunakan kelasa-kelasa untuk memperkenalkan kelasa-kelasa dan kelasa-kelasa. Pemenangan IOS XC-UI TESTS adalah kelasa-kelasa dan kelasa-kelasa dan kelasa-kelasa di periuk. Dan kita dapat menggunakan kelasa-kelasa yang menerima kelasa-kelasa UI. Keplasa-kelasa UI akan berikan kelasa-kelasa UI menerima kelasa-kelasa UI. Jadi, kita dapat mengubah kelasa-kelasa bersama dengan menggunakan kelasa-kelasa app.tables.static.taks kelasa-kelasa UI diperkenalkan kelasa-kelasa UI dan kita dapat menggultu kelasa-kelasa dengan menggunakan identifier kelasa-kelasa app.tasic.taks menerima lebar-lebar dengan kelasa-lebar atau kelasa-lebar hallo lo kelasa-kelasa app.table kelasa-kelasa UI dengan label Accessibility My Table. Jadi di sini ada yang lain actually your elements that the API provides. So as you can see there is windows, sheets, probably your action sheets, buttons, we have keys, we have toggles, and if we can also use the last one at the other elements, and this returns the subviews of anything that is subtype UI view. So now that we know about the elements, how about the interactions. So we can take an element and invoke.exist, and this returns true if the element exists on screen. With the buttons we can tab. We can also swipe up on the table. And if we have an input field, we can use text text, and that will enter the fields just like the demo, the little G file that we saw enter the values into the text field. Other interactions include pinch rescale, press for duration, and double tapping. So we can combine this with assertions. So app.statictextalloworld.exist true. This shows an exception if the label exists on screen. So now you have some idea what the API can do. Let's go ahead and write our very first XC UI test case. So given these requirements, I create an app given that I'm at the city search screen. When I search for a valley city, London, then I should see weather details page of the city. Number two, given I am at the city search screen when I search for an invalid city, let's say a string called not the city, then I should see an error message. So I'll show you what we have built so far. So we tab. So this is the example of the app. We tab on the search field. We tab London. And then this is the details page. Alright. So the second one. Sorry. So this is the second part. So we tab not the city and we just get record the API and we get an error message. Okay. To start off, we will need to create our UI test target. So take note it starts off with the plus sign at the bottom. So tab on the plus sign. First we need to create our test target. We select a UI testing bundle. So our first test target. And that will also create the test case class for us. So one more time adding a UI test target bundle. This will generate our UI test target as well as our actually test case class. Okay. So far so good. Very simple. So now we will now record the test case for our very first requirement for a valid city. So So this is the test method we tab on record. Now we open up the app. And as we type, you can see Xcode will now generate the codes for us. We tab London. We tab on the search button. And now we have the weather details. And notice that we're going on each of the UI labels one more time. Press on record button. We launch the app. We perform the actions and Xcode will generate the corresponding actions in Xcode. So now tab on the search field. Then we tab on London. Tab London. Tab on the search button. And we tab on the UI labels. So one important tip here you may want to click on the elements doing the recordings because Xcode will help to generate the statements that you may want that you may have to use later. So for the invalid city very simple. So now we launch the app and we type an invalid city here. We curious the API and now we have an error message. Again we tab on the error and the error message. And after that we close the alert sheet. Okay. So now let's look at the generated codes. So what we have here app because of app 2. Definitely this is something not correct. And now we assuming app is the represented object across the views on the screen. So now we have we look for search fields where we filter by the identifier search city. As you can guess it's probably the text used as the placeholder. We tap on it and after that if you can re-imagine the whole UI flow we are supposed to type in London into the search field but here again it's missing. Next we actually we query for the buttons and we filter by the search string. Then this represents the keyboard search button and then we tap. So the lower part we actually query the table for the static text which is the UI labels and we look for London 53 and partly cloudy and we tap. So as you can see when you use the record functionality Xcode may not always generate the desired codes for you. And in this case the codes for typing the search string is actually missing. So we again we get the search field tap it we are supposed to type in the velocity we tap on the keyboard button and the later part what happens that we tap on the error and the error message as well as closing the error action sheet. So of course we are not well done over here so let's go ahead and refactor the codes So for the first test case we have app equals to XCUI application we get the search field after that we tap on it we use the method type text where we enter London into the search field after that we tap on the search button So here we have a private function where we create expectations using a predicate and we wait for 5 5s time out we evaluate whether this is true So for this portion after 5s if London 53 and partly cloudy cloudy doesn't appear on screen after 5s the test case test method will show an exception and fill the test So this is a pattern you will see later in the slides which I will use to to assert that something appears on screen So for the in velocity we have same thing app equals to application we get the search field we enter the value using type text and then we tap on the search button and again we use the helper function to see text we have error unable to and then we wait to see unable to find any weather location to the query submitted once we created the expectation wait for 5s and next we have user taps on alert button So the private function we have here simply application.buttons pass in the stream So as you can see here we didn't really do much we simply fill in the blanks or incorrect codes and then we organise them a bit so it's pretty simple to use So here is scheme management so you can use scheme to manage your test by opening up scheme management go to test and over here you can see the test target the test class and the test methods and then you can decide which test to run for which scheme and in that way this allows you to build test build test against just one test target but you can use different schemes to decide which test you want to run for example I may have a scheme that selects all the test cases and I can call it regression test or I can have a scheme priority smoke test or what or having one scheme select those that I can run locally or an adapt and different schemes to run test against different environments so of course changing environments require you to change api target in your app so if you want to change which environment you want to run in your app you can use the scheme you can go to the build pre-action and if you have a configuration file you can actually create a run script and do your modification here if you simply use p-list you can use p-list body and change the values so of course if you're going to use configuration in your iOS app just remember to equip your configuration file before the package into your .app or ipfl so first part done actually you are test so next, gurkin don't know what gurkin is this is an example of a feature file written in gurkin so gurkin is a human readable syntax used to construct acceptance test cases usually used in BDD behavior driven development so the key words in gurkin are feature so feature describes what the XT test case will do mapping scenario test method and below scenario gurkin steps mainly given when and then so today we will focus on the 3 steps given some precondition or given that I am at a particular screen when the user perform an action on the app then we do some checking or we do some assertions so for given given that some precondition have been met or the user is currently at this particular screen when the user perform some actions on the app then we do some checking or assertions so just give some some example example, if you are at the user registration screen given I am at the user registration page when I enter in valid email address I tap register then as you see in valid email address so another example assuming I am doing shopping and I have existing items in my shopping cart so given I have one wallet one belt in my shopping cart and I am at the shopping item details page for bag when I select quantity as 1 or add to shopping cart I should be at the shopping cart screen and I should see 3 total items in my shopping cart so now for our own acceptance test good given I am at the weather search from page when I enter city search for London then I should be at the weather details page and I wait to see London and I should see 53 53 I think is the humidity so for our invalid test invalid city test given I am at the weather search from page when I enter city search for not the city then I wait to see error message I wait to see unable to error unable to message and I tap on alert button okay so Gherkin is a language used to specify software requirements with examples so this English written file is executable and because it is easily read by non-technical people you can facilitate collaboration with your QA your product owners as well so now let's try to add Gherkin into our Xcode project by using this port actually test Gherkin so this is what we want to achieve in test case file you want to specify the given when in this way after that we will create a subclass of step definer and we override the define steps and then we put our definition of our steps over here so the step definer will evaluates the given steps mentioned in the exit test so let's go step by step first one given at I am at search form page so the step i will create is given I am or should be at the weather search form page and here i will create a search page struct and in initialization of the struct initialization of the struct we will wait to see whether this element exist on the page once we run this step and we create a struct after 5 seconds if this identifier is not found the test method will show an exception so if you are wondering where i don't see this screen in our address now where should i put it you can actually go to the view controller view node method enter self.view accessibility identifier equal to this train so next so when i enter city search for London so i create the step for i enter city search for rejects and we create a weather search page and then we create a function user search for city and passing the argument and in this method the statements that we created earlier on what we do we created actually your application object we get the search field tap on it and we enter the city in and we tap on the search on the search keyboard button so the next part i should be a weather details page here i will initialize the weather details page struct notice that i use so that i can use this statement for both at the event and at the then when i use the then steps so similarly for this chart when we initialize we look for weather forecast which is on navigation bar title weather forecast so the next one i wait to see London so this part is very simple i wait to see rejects we use the wait expectation again we wait for standard text that matches the argument we wait for 5 seconds to the last part then i tap on alert button okay actually your actually your application the buttons and we tap on the button so if so if i if i cannot locate the button this statement will fail and will fail so let's see our finished product we have our search page so this is a struct and this is the function that we created and if you want to i found a port which is called jerry test helper and so you can actually reduce this into you don't have to specify simplify your statement so next this is the weather details page struct same thing so now we wait for we look for the static text weather forecast and here are the steps so i create different subclasses of step definer i put all the navigational steps like navigation assertion steps even that i am here at the search form page or at the details page and these are the steps this is for the home page that you saw when i enter city search for particular stream so i have another class which is for wait steps so here i put the i wait to see rejects and here is the alert steps basically interaction with the alert box so finally this is how actually ui test look like so here is the given when then so you can see we actually extract the code form we extract the implementation code from the test method and if in fact you can actually in this port you can actually run directly run using the feature file over here so so why should i use the key with test firstly it facilitates test driven design you can work with your qa they can fill up the features for you in fact you will want them to specify the features as a test case hook it up to your continuous integration process and then ask the developers to code to get them to passed and once we in PG in our team we actually ask the PO to write and commit the files so we start writing any code so this also allows cross platform testing without the need for third party tools so for example if you are doing iOS or Android development you basically only need the feature files to bind the same requirements on both platforms together for example for the android programming you can use android testing you can use terapia or calabash but for iOS you don't need any special third party tools hence all your coding is done in objective cswift you don't need to learn ruby just to use calabash so that's the one major advantage so so any questions i have 2 first one is step definer is it from guilkin so so the tool that runs guilkin is mainly cucumber written in ruby so they have broken down how to write your test in english and for each one for each statement you will write the underlying implementation for platform pacific you were supposing from step definer that step definer came from the party so for this presentation it's kind of long i actually had slides that explained under the hood how it works but i think that part might bore quite a lot of people so i took it out my second question is have you reached a scenario where you couldn't test you actually hit a wall hit a wall yeah sometimes as you can see when we create record some flows and somehow the recording expert doesn't give you the exact statement and it's wrong so i hit a big wall and try to find out how do i query complex ui within complex ui so sometimes that's the problem i hit other than that nothing else actually ui test you can easily run on your device as well so you can actually test this again like 32-bit architecture phone 64-bit yeah any more question sir how do you use frame use previous? no i've not used so i one thing that i haven't used ex-ui test that much i use frame mostly for the query they use accessibility identifier so you can put accessibility identifier for literally any new component the thing with ex-ui test i think this for some of the things like search still or things like label it uses the name of the label that's right how many or how much you need to modify if you have to write automation test for multiple languages for example if you have localization will you create multiple future files for each of the languages or the same feature file the same feature file will not go because the test will be different in different languages i think this part for localization i think this part you would do the extraction when you choose the scheme for example i'm running this app in english i would do in the in the file you will not use the exact string you will use a kind of a paste holder id that you use to map into your into the specific word and you will do this matching actually outside running of the test case so that's how you can do a bit more complex task like if you want to set up complex features you might also want to consider using scheme so just running running the test method may not be sufficient enough to run your test especially if you need complex setup anymore go ahead fellow teammate is it possible to use the test recorder but instead of generating the code we generate gukin no not yet maybe next time for now i don't see it's possible because it's quite limited to what apple has created in the api so gukin is just it's a testing tool how you want to run to make your test how you actually want to work with people outside the engineering department that's what i can say another question from your experience how maintainable is the generated code from the test recorder if you just take it straight off quite poor because you can see the sort of duplication you can't just depend on it whether i use that quick way to find out because sometimes when we build apps you have complex UI nested with this other by clicking it just help me to query for the elements if it's possible easily get the elements and of course after that you do a refactoring and you probably want to create apple methods to make your life easier you cannot always depend on the recording tool one more question what would be the flow when there is a change in the requirement and your previous written test now have to be a change in the way would you use a test recorder for this again or would you just change the test code actually it really depends if i happen to create a new a new UI label i would just quickly do a quick one and click on the label just to find out how to if i can easily access it it would completely depend on using the recorder any more test? okay so i hope you guys have gotten a good picture on how to use xeoy test plus gurkin any of you need help to kick start automation in your personal world or company world feel free to bus me later or via my email thank you so i hand over to supran su