 So welcome everyone to the session getting started with Xcode UI tests by none other than Shobhan Babu. So we are glad they could join us today. And without further delay, over to you Shobhan. Thank you Shweta. So let's share my screen quickly. Hello everyone. Hope everyone doing good and hope everyone is fine during this pandemic. So just we are starting with getting started with XCY test. So in this session, right, so I am going to cover how you can automate things with XCY test and we'll discuss more how XCY test response and the test how you can write everything. So before starting my session, I would like to introduce myself. So this is Shobhan Babu. I am a consultant at ThoughtWorks. So I have a six plus years of experience in manual and automation. And these are so I'm basically very passionate about automating new tools and technologies and learn from it. And this is my GitHub IDs and LinkedIn and Twitter so you can follow me and if there is any questions after this session, you can reach out to me this using this tag. So without further delay, we'll get into the agenda of today. Little bit we speak about what XCY test and what are the downsides of XCY test. And we are going to write a first test. And we some sometime talk about what is API is in XCY test and what is the waiting strategies and gestures how you can automate with gestures and parallels how you can parallelize your test execution and see a integration with your XCY test. And finally we'll be having some time to ask questions and answers. Hope you clear with agenda. Okay, so what is XCY test right so XCY test is a native framework which helps us to automate your native applications. And it's it's very, you know, support for the iOS application and iOS platforms and XCY test is written, you know, the test is written using Objective C and Shift. So it's a part of the Xcode. So you don't need to download the XCY test explicitly downloaded in your code so whenever we install the latest version of Xcode it will automatically download your XCY test bundle. So this is what the XCY test. And then I'm going to touch upon the shift the language. So it's a native language which also helps have to write a automation test for XCY. And it will support seamlessly with your existing Cocoa framework so Cocoa framework is nothing but is existing though the native framework so we can support with the shift language. It's very modern and fast and it's very, you know, type safe and it's very easy to learn when compared to the other languages like so basically the shift developers right so they took ideology from the other languages like Python Ruby, you know, C sharp so that is much different to learn about shift. So this is pretty much about the shift. So we'll jump into why XCY test, why we need it so already some of you got an idea so XCY test helps us to automate the native know applications and also it's a native framework, and it's a very easy to set up things and you easily the why so why it is easy to maintenance because the XCY test it sit sit upon your development core. So it will emphasize your code pairing with the devs so you can easily, you know, approach developers and you can write a test and you can get immediate feedback from it. So this is why XCY test helps more more on our execution flow, and the, the, the most thing is an accessibility so you don't need to spend extra effort on testing the accessibility. So why I'm saying is XCY test to morally, you know, depends on your accessibility modifier so here we don't see any IDs or expert. So those things so it's more dependent on your accessibility modifiers so I can apparently say when you do with the accessibility modifiers you can avoid most of the flakiness right flakiness on your test because you are going with your accessibility modifiers so two in a one way. So this is what the XCY test and so definitely will be having some cons about each framework right so here in XCY test there are some cons some people already got to know it's only support for native frameworks and the cross platform which will not allow with using XCY test and you can use only the native languages the objective C and so other than then so you know these are the cons from the XCY test. We quickly jump into so many of the people has in mind rate what XCY test and XCY test because when I started I have the doubts in my mind. So from the image you can actually you can directly get the context so XCY test is mainly for white box testing and you know so it purely on unit testing and you can do integration and network monitoring and no performance everything you can do it with XCY test but XCY test is purely on black box testing which we are doing like interacting with UI components and the accessibility testing everything you can cover with XCY test package and the difference between XCY test and XCY test because both are fit into your dev code the only different is XCY test supports HTTP protocols so like in APM we will be doing the external HTTP calls using XCY node page like so likewise so the XCY test will not support the HTTP protocols so that's the only difference between XCY test and XCY test okay so now how my tests look like so this is my first test case so here I have attached the sample test case how it looks like so we have used CIFL as a language and I have imported XCY test because XCY test come from XCY package and I have created my first class my first test case and this extends from the XCY test case class and here I am initializing my application as an app variable XCY application so that I can use across all the methods and pages and there are three functions here I am derived so one is setup and test example and tier down so inside the setup you all know right we need to initialize the application and launch and the basic setup before you launch everything will be carried out in the setup method and the test example whatever we do actions right tab or you know the assertions interaction between you elements everything will fit into test examples so in the setup I have you know I have defined my setup as a super so that I can you know get the all the context to and share to the other pages and other functions so that you know you can interact with multiple pages and the second I am setting up the flag you can also set up the flag here continue after failure falls so it means if there is any failure during my execution it will not stop immediately it will execute the next test case and it will provide you the feedback and the app.lunch it's straightforward it will launch your application and here as I talk about we don't find we don't need to use any of the ids, xpath and everything so everything will depend on your access accessibility modifiers so here app is the application which I launched the static text is a class which helps us to take the element for view schedule link so I am taking the element for view schedule link and I am using tab method I am clicking the element so this how you can do interaction between you know application with your application and using xct assert class I am asserting whether the u1 alert box is you know exist or not and you can handle the alerts also using app.alerts so this is the part of it can be a native alerts also it can be your application alerts so both the ways you can handle using the alerts we will see how it goes further without further delay I would like to take you the demo so how it looks like in the xcode right so this is xcode IDE and here I have a first test case what I explained in the slides so how you create a test case first I already said right so we are setting up our xui test inside the development code so we need first the code base which have the successful build and which can either deploy the application into your simulators and the likewise I have the application here which is developed for the gaming application so it will have a manage members so this is the sample application so if you see my emulator so I am opening my application so this is a simple application so it has a more info it will direct to you the web view and manage team you can manage your teams like size there is a slide bar and pickers so this is a simple application to manage your gaming purpose and this is a code setup for that and there is a second package called products which has your .app and .ipa will fit into this package when you build your application and this is your test which I already created the first thing what you need to do is so you have to go to file and you need to create a target for your application so it means you are creating your xui test bundle so just a minute it is opening so here this is the way you need to create a target okay yeah it is open sorry for the delay and here you need to select the ios because I am going to write xui test for ios application here you need to search for ui bundle this is the testing bundle which carries your all the packages xui test packages here and if you click on next you will see the product name which you need to mention and if you click on finish you can see the packages created for you so this will be having one playlist which has default configuration and this will be having one .shift file okay and you have some curious right how you can run your test with your Xcode IDE so here there is an option providing the play button so you can simply run the functions or test using this icon so let me quickly run the application now so when you started running so it will terminate already open the application yes so the testing is started so I can see the launching ui test here so you can see the ui test runner is you know the installed for each xui test run so the ui test runner it helps us to interact with your application for example in apm when you run the apm test it will install the driver agent in your emulators right so likewise the xui test will install the test runner first and then the test runner will interact your application so my test runner is installed now so now it will deploy the application which is volley here so now my tests are launching volley this is the application name I will go through the chat if there is anything can the load and look into yes I have a code in github so I will be sharing after the session so it's launched my app and it will click the view schedule option here so I should finish game and click have some so now my test is finished so once the test is finished you will be getting the pop up here and then the test green will be passed and that report right when you have multiple test you will be having the confusion what test is passed and failed right so if you click right side there will be a jump to option they are providing the native reports with xui test and you can see the very basic level of reporting here and in this session I am not covering out the report configuration everything so here are the basic reports that you can debug your tests actually hope you understand how we can write a test and how it is interacting with your xui application right so yeah so let's talk about what is xui test APIs when I say APIs right so API is very important to interact with components and whatever actions you do that you know communicate with the API right in xui test we have you know three APIs that is major you know major contribution of your xui application sorry you know IOS application so xui application is an first API which helps us to launch the application and tear down the application and if you want to launch with the arguments or the environment variables so that you can do with xui application and then xui elements which takes you know which takes the control of your current snapshot and it helps us to click the element or whatever action you want to do with the components that will take care of your xui element API and xui element query this API helps us to you know take a snapshot of your page of elements and it will help us to query, assert and finding the element so everything will be covered as part of this xui element query API so quickly we go through we will compare our first test with our execution flow how it works with the APIs right xui application first it will call xui application API and it will launch the app and then it will call the xui element query and then it will find the elements which we find out view there is a game tab right so that so that element will be find out using xui element query and xui element API will actually talk to the element or tap to this tap the element on the screen and then we have asserted the element using xui element query and then we need to tear down right that will take out xui element application sorry xui application API so this is how the execution flow will be carried out through your entire you know test cases okay let's see the demo how it works you know with your application right so for having a demo I am having enabled the debug mode and I am running my test again the same test okay so you can see my UI test runner is installed and you know my testing is progressed yeah so you can also see the console locks here so once my application is deployed in my simulator so my debug debug area will be open okay you can see it's starting automation session actually it will creating a session ID here in this step and if you can see it will attach our test you know test cases with our application actually my system is something you know slow so that yeah so my now application is open and also you can see my debug area is also open here so now what I am going to do is I am going to interact my application using the APS which we discussed about first I am you know I am just calling a print object you know method which helps us to print the console locks when you interact with the APS I need to get the application right xui application dot okay so when I do this it will actually interact with your page and it will get all the you know page source which is available as a current snapshot like we do in selenium right if you want to display the get whole page source you can display the page source here and also we will have some curiosity right how we can find the elements using this API right so for that what we can do is for example if you want to get the elements for buttons right let's say if I do buttons so actually buttons come from xui element query which find the elements on your page okay so when I click on enter you can see it will interact with your snapshot and it will provide the buttons which is available in the screen so here I have only one button which is more info so I am copying that element here and what I do is I am just going to interact with the element so there are you know tab there are most methods as available as an action so if you want to tap you can tap your element and it will be going to the web view so that is a expected functionality here so it's already clicked the more info button so it will move quickly to the web view actually it's like a ripple for example if you take an example of typo whatever actions we do in the console we can see immediate feedback from the web page or application so likewise the xui test the xui test APIs also communicate with your iOS applications and it will provide and it will give the feedback to you so this is how you can interact with your APIs and also if you want to launch the application right so you can launch the application launching with arguments and launching with environments so there are many launching you know launching options is available with using these you know classes you can do with the launching methods so for example if you want to do if you want to change the context between apps right you can use bundle identifier and also you can switch your apps for example there is a default app is available in iOS right Apple news so I am going to open Apple news using the bundle identifier so when I click that you can see here it will it will open your Apple news using the bundle identifier so these are you can interact your application with the API so once you before you're writing the test case you can interact with that and you can probably get the feedback and you can write your test cases it's pretty cool right so one more thing how you will be updating how your I already said right this is our accessibility modifier how would you identify and how you how you can modify right so here whenever you have a dev course right so there are options in your application and each application will be having a storyboard okay when you click the storyboard it will open it will open your the navigation of the screens so once that is open you can actually click on the element which you want to update the accessibility modifiers okay so let it open so this is a storyboard right so main dot storyboard it will having the views for each screen let's say if you are in a home screen you will be getting the home screen components in the storyboard and you can select that and you can modify your accessibility elements okay we'll quickly go to the next topic and then we'll come back until it load okay my next is the waiting strategy right when I talk about the waiting strategy so the XUI test having some you know the default waiting strategy is provided so here I have listed down some of the waiting strategies here the first one is the wait for the existence so it will explicitly wait for the element to be appear or it exists based on the time mode and the next one you know the expectation so you can set the expectations and then you can get the you know now get the whether or true or false you can get that and you can wait for the expectations so this is a second thing here I have provided one example as expectation here I am using NS predicate so predicate is nothing but is a pouring language in shift which helps us to query the exact match of your elements I don't want to dig more into the what is predicates and everything so that helps us to match the elements based on our query so here I am setting up my query like exists equal to equal to true okay so I am setting up against my identifier as buttons okay my button which has identifier accessibility it will wait for five seconds and then it will satisfy the conditions if not it will actually throw the exceptions so this is how you can set the expectation and wait for acceptations and the last one is thread dot sleep actually the thread dot sleep you know it's not a recommender in any of the languages so here I have striked out but the option is available in Xcode sorry XUI test as well and there are many other waiting strategies like until wait for until but those things are having a different framework like cookpad so that's a framework available for XUI test so if you are going with that framework you can use the many until wait and wait for the you know wait for the flu and so everything those kind of page you can handle in the different frameworks okay so initially we talked about the storyboard right so this is a storyboard so this is a home page you can find the elements using the storyboard and here I am giving an example of more info when I click more info so here there will be a class path available okay it's loading again so it's loaded you can see the custom class in the navigation bars in Xcode so here you will be having some accessibility the section here you can enable the accessibility so you are enabling the accessibility and providing the label as more info then you know you can directly interact with your accessibility modifier so here we are you know you know majorly decreasing your communications here so whenever you want something you want accessibility modifier you can you know quickly go to the application code and you can change your accessibility monitors so if you are for example if you are using Appium for you know the applications iOS application and native applications you can directly come here and you can change and you can do you can get the accessibility modifiers in an Appium test as well so this how it helps to update the accessibility modifiers okay cool next I am jumping into gestures so how gestures will look like in native applications and how you will be automating it the first thing is tap so here the tap is called for click it will be clicking when you call this tap method and the double tap it will double tap the element based on the element you are querying and two finger tap when you want to tap with two fingers you can call this method and one major thing is you can tap with number of taps and number of touches so that you can configure within a one tap so you can just to provide the elements and sorry the arguments in a number format and you can do the taps in between your application and the press is for long press if you want if you provide the duration it will press until the duration is completed and the scrolls right the scrolls you can do simply calling the swipe left method it will be like left of the element and swipe right and swipe up and swipe down so these are the scroll methods and pinch so this is special option here the pinch if you want to zoom in if you give a velocity of pinch and just it will it will zoom in and zoom out of your know the page or whatever the image which you provide the element and the adjust right so these methods know it the same method will be interacting with your slide bars I will show you how the slide bar will look like here and the picker wheel so picker wheel is a native component in the applications right I was application so you can automate the picker wheel by selecting the value here by calling the adjust method. Okay, so let's quickly I will jump to my test case. I have some gestures here. Yeah. So this is my I have provided all the gestures methods tests here. For example, I have a manage roster here. So in the manager manager roster I want to scroll down so that I want to scroll down so that. Okay, now it's not happening. Okay, fine. We'll move to the next one. Okay, so it's a luster picker. For example, the manager team you will be finding the pickers right here. So I want to select the values from the pickers. Okay. Okay, so for that what I did is so I just a tapping manage team button from the home page and you know I'm I'm giving the the the values of my picker values I'm providing in the selected format variables and I'm I'm asserting whether it is exist or not before I select the values and I'm using here the predicate which I need to exactly match with the element so which is attackers information. There are two things here. Now one is attackers information and other one is the setters information. So attackers and setters. So I'm just to coding with the attackers and using the picker wheel class. And using this, the picker wheels, I actually identify the picker wheels which is present in the application and it will pick the value which exactly matching with fire attackers. And it will select the value here the same way the same, you know, same set of function for the setters. So let me execute, you will understand more. I'm just running this test by clicking the application here, and my build is succeeded. And my UI tester and our install and it's testing is processed. Well, I will go through the chat. Yeah, sure. Yeah, sure. Then we can take one question if it's going to take time. Sure. So we have one question image shows Android and iOS. I think it was from one of the previous slides. So is X UI. So does X UI support Android as well? No. So this X UI test package is for only supporting the iOS platforms. There are different packages available at APM so that also you can do it with X UI test actually APM which has a X UI. Like we have a UI automator right so those we can use that and you can also use the APM for testing. But in this session will be covering only on X UI test package, which will help us to automate iOS application. How we can cover accessibility testing using X UI testing terms of voice over color contrast and touch target and UI objects. So actually I'm not sure about the voice over and color contrast. Yeah, so actually we'll take this question as in the hangout session. You want to take the next one which is about the BDD framework. Yes, X UI supports the internal BDD framework in it. But it actually not refers to the BDD style like you will be having given when then so it will it will automatically have the BDD flow in it. So you can install the plugin BDD plugin in X UI test and you can do the BDD as well using the X UI test. We have one from Monil Zoshi. Yes, do we have a complete application project Abel opened X code or we can simply automate any application by downloading. No, you have. So actually we are not providing any application path or IPF path to the X UI application. It will automatically did it from the code base. So actually your code base should be present in your X UI test. So what is the process of X UI test over Selenium APM test. So basically X UI test preferable when you have only the iOS application. So it will be very fast when you compare with other, you know, other frameworks. So because it has a native component, so it will directly interact with your application and you will provide a quick feedback. So here my local system have some issues in CPU thing so you can have some delays. So what is buttons more info. So actually the more info is an accessibility modifier that I showed before. Using that accessibility modifier you can actually interact with your elements. Yes, it's more. Yeah, more info is an accessibility element. So in a page if you if you elements are there getting to the page shows of anything is easy. But if the there are more than 15 plus elements, it's a bit difficult. Yeah, so actually we so that's why we are calling the methods. So if you want to print buttons only it will print a button. If you want to print only static text, it will print only the static text elements or else you can use the storyboard to find elements as well. Okay, so apparently my test is running. You can see my screen. So it will click the view schedule now. Sorry, manage team now. Okay, we'll go through the next question. Meanwhile, how we can cover accessibility testing using xy. Okay, let's we'll be taking a separate things. Okay, it's opened the manager team and it selected a fire attackers and one setters. So this is how you can automate the gestures using a methods called the gestures, tap or swipe and everything you can do it. So the next one, the question is how we can do a parallel testing with xy test right. So we don't need extra effort spending on your parallel testing actually xy supports parallel testing in a native way. And so this is a scheme, which I forgot to tell you, you can create a number of screen for the single application. You can create the scheme for UI test and you can create a scheme for into an xy test and you can create a scheme for performances. Likewise, you can create a number of streams and you can point out here. If you want to edit scheme, you can click the scheme. And it will open the dialogue box. And there you can select whether which test you want to run and which test it, you know, whether it needs to be run parallel or. Okay, so here UI test. So this is this is this is my test, which is the thing here if you want if you don't want to run this test you're just clicking the uncheck the boss it would run. So these are you can edit your scheme or parallels right if you click options here, it there will be option execute in parallel. So that is a disclaimer if possible. So there are many constraints. So in your Mac, if you have a very, you know, capacity of Mac, then it will clone your multiple know, for example, 12345 clones and it will run accordingly. So, yes, so you can see execute in parallel. So this, this volleyball one scheme on UI test will execute in parallel mode. So I just try to execute now. I'm not sure. Okay, let's say I will execute this. This is a very simple test like when I execute, you can see in simulator I have only, you know, only one devices. So once it is started, you can see the cloning devices here. So my testing is progress. So, yeah, we will. Yeah, so we'll move on to the next topic. So we'll see once it is opened. And the next one is like, so see integration. So how we can integrate my CI, you know, CI with X, Y tests. So here I'm using Travis CI as my integration tool because we can integrate with any of the, you know, CI integration tools here for the demonstration I choose Travis CI. And there is a between, you know, X, Y test and Travis CI. There is a fast lane, which helps us you to build the X code build in command line. So when you want to run the X, X, Y score in terminal, you have to pass many parameters and many things. So, so for example, if we want to device settings and, you know, output directory, the report everything you need to configure manually when you do export build. But fast lane, it will automatically delete your configuration from the, you know, from your X, Y test, and it will run in a simple, you know, from simple command. So this is the Travis YAML file, which has my Travis CI configurations. And here I am to specify the language shift because I'm using shift here, and I'm providing the OS X image as OS X image which should have X code version as 12.5.1. And the branches which I'm running on the main and before install, I need the fast lane. Every time I need to install because of the Travis V, I open the MacBook instance at each time and a new new image. And in the script, I am mentioning the scheme name. So first it will scan the dependencies. So it's not there. It will install. And the scheme name should be default. So actually here I changed the scheme name as Wally. The scheme name, whatever the you want to run against your excavators, you have mentioned your scheme here and the devices, which the device name you want here. And so this is the Travis CI dashboard. So here I already run in the morning. So, so you can see the results here. So once once the commit is happening, it will automatically trigger my build for my Xeo test. First, it will install the fast lane and it will install the all the dependencies before installing the fast lane. And after that, it will trigger my comment which has which against to run the default scheme and the device called iPhone 11 Pro. And once it is done, it will the I already mentioned, right? It will automatically get the arguments which it's needed. So it will automatically set the values as well. That's what we are using the postline here. And the ones we are building, it will deploy the application into your simulator and it will start the test. So these are the tests has been ran in your Travis CI application, sorry, integration CI. And you can see the results of all test cases run and zero failure. It's very simple and straightforward integration type with Xeo test. And let's see. Yeah. So now my parallel test has triggered. And now you can see clone one of iPhone 11. So now I have a very minimum capacity of my memory and CPU everything so I can see only one clone. If capacity is high for your math, you can see number of clones of your simulator and you can do parallel testing. And the same thing, you can do it with your CI integration also, but you need to provide a matrix, you know, matrix tag in your Travis dot yaml and you can provide your multiple parallel test which with the devices that you can configure with your, you know, CI integration tool. Okay, so this is pretty much that I have hope you have a better understanding about Xeo test and when it can be used and what are the API's. What are the waiting strategies and how you can interact with the API's with your native applications and how you do parallel testing how you can integrate with Xeo test. So I'll go through the Q&A now. Can we use Xeo test in APM or along with the APM in Java? Yes, you can use, but it's especially for only for native application and native frameworks. You can also use this. So it's changing the A11y modifiers, so okay, as easily possible, when Shifty Y is used in iOS project instead of storyboard. Actually, when you declare the accessibility modifiers, I don't think it will be modified frequently. If that is modified also, we'll be having some labels apart from your accessibility modifiers that you can find it in your storyboard as well. So APM user WDA, which talks to Xeo API. Yes, APM actually using a brave agent to talks to Xeo APIs. That's a different part and this is a different part. So here, the Xeo test will actually communicate with application using test runners instead of the braver agent. So Shobhan, I think we can take just one more question now. My app has some APIs to validate. Is it possible to fetch data from APS? Yeah, I already mentioned there is no provisions to talk about HTTP protocols. We soon expect the future again. So thank you Shobhan for that great session. Thank you all. Bye bye.