Appium Beginner Tutorial 7 | First Appium Project with Java

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello and welcome I'm Zagreb and today we will learn how to run our first test on a real mobile device and we will start coding in Java this is going to be very easy and very interesting and you can follow this on Windows or a Mac operating system and the steps we are going to do is we will open our IDE for Java so in this case I am going to use Eclipse and you can use any other Java IDE so that we can write our java code we will create a Java project we will add the selenium and appium libraries into our project then we will connect a mobile device and this I have already covered in a different session on how to connect a real mobile device both on a Windows and a Mac operating system we will then start the appium server we will write the code to start mobile application and then we will also see how we can locate the elements using the appium desktop mind so let's get started and step number one is we have to get a Java IDE like eclipse in this case I am going to use Eclipse and you can use any other Java IDE now in case you do not have Eclipse or you do not have any other Java IDE you can go to my channel on YouTube which is automation step by step and if you go to the playlists and you scroll down you will find a playlist for Java here go to the playlist and here you will find a video on getting started with eclipse ID so you can watch this I will also copy this link and make it available in the notes and all these nodes will be available along with this video so you should have a ID for writing java code and then we will create our java project so you will open your eclipse or your java ide so for example if you are on windows you will go to the location where is your eclipse and just press the Eclipse dot exe click here and it will start eclipse and you will have your Eclipse running here and in case you are on Mac once you have Eclipse you can just go to spotlight so I pressed command and spacebar on my keyboard to bring up the spotlight and I will start by picking at lips and I will open the eclipse app and as of now I already have it opened here so this is my Eclipse and then we will create a new project so I will go to file and this is the same menu in Windows as well go to new and then I can create a Java project but I want to create a maven project so I will go to others and search for maven now the reason we are creating a maven project is with a maven project it becomes very easy to manage all your dependencies all your libraries in the project you do not have to manually download it you do not have to manually manage it and also when you take your project into a different location or a different system all the dependencies and libraries will be taken care by maven and you do not have to do that manually so create a maven project say next and I will say create a simple project and let us say use default location and also I will just add to a working set I have a working set called appium and do not worry on this this is just I am doing so that you do not see all my other projects on the package Explorer here and it is very clean and then I will say next and I will say p.m. tests IBM tests and you can give some description and you can give any group ID and artifact ID and say finish and you can see the project here so this has come here if you expand this you will find all these folders here so here as of now we have done step number two which is creating a Java project and now we have to add the selenium and APM libraries now because this is an IBM project I can just go to the form dot XML file here and here you can see this is the file and I can add my dependencies here so here I will just create a tag called dependencies and you can see this gets auto completed the half-closed dead and inside this I will add all the dependencies so for that I will go to maven central or maven repository and then this is the link so let me also copy this and make it available in the notes so I am getting all these libraries from here for maven and here I will search for selenium Java and this is selenium Java and I will take the latest stable version which is this one and I will click here this is for maven and it is copied I will go to my project and between the dependencies tab I will just place it like this and you can see it is here and similarly I will then search for opium Java client and it is here and again I will take the latest stable version and copy this and add it here so I have added both of these here and once I save and clean my project you will find our maven dependencies folder here so I will just save my project and sometimes just by saving you will get your maven dependencies and everything is here in case you do not get all the libraries downloaded you can go to your project and say clean and then you can just clean and build your project and you will get everything and now you can see how easy it is I am getting everything here all the libraries are downloaded and whenever I make any change for example if I make the changes to the version here I just have to make change here and just save and build my project and everything will be taken care by maven I do not have to worry on anything on the dependencies now so I have added the libraries and now fourth step is we have to connect our mobile device so at this step you can connect your mobile device with a USB cable or any cable that you use to your laptop or to your computer system and then go to your command line or terminal and then say adb devices it should show you your device attached with your device ID now in case you face any issue in this particular step I have a separate session on how to connect a reel-to-reel device on Windows as well as on a Mac operating system you can watch that if you are facing an issue here and assuming that you have connected and you are able to get the device ID we will go to the next step which is starting appium server and this can be done from command line or from the happy M desktop client so if you have a IBM desktop client you can just search for a PM desktop client on Mac and you can see it is here or you can go to Windows and here as well you can just open your APM desktop client and it is here so you can start it from here or you can start it from command line from command line you will just say a PM and say enter and it will start similarly if you are on Windows as well you will go to your command line and say IBM and hit enter and it will start the appium server and you can see it has started on this IP and for seven two three port which is the default port similarly on my Mac it has started so we have started the appium server and now we will go to our project and do the coding so I will go inside my Eclipse Java project and I will go to this folder SRC test Java do a right-click new and I will create a class and I can name this as a PM test or I'm going to start a calculator application so I will say this is calculator test and for now I will also have our main method later on we will learn how to have our test ng framework and then have testing G tests for now I am just using a very simple Java class having a main method and I will create a method public static void and I will say open calculator so this function I am writing to open calculator on the mobile device I will also increase the font so that you can see it properly I am pressing command + + on my keyboard and command - to decrease the font in case of Windows you can press ctrl + + ctrl - so I hope you can see this now okay so now the first thing is we have to add desired capabilities and desired capabilities is a key value combination which tells our APM server the information about our device and about our application so we send device name the UD ID which is the ID of our device this one and then the platform name like Android and the version of the platform and then about the application like we are going to open calculator about its a package and app activity I will tell you about all this so for now I will say desired capabilities and if I press ctrl spacebar on my keyboard it is getting auto completed and I will say use a variable called cap and say new desired capabilities and you can see it has imported it from this orz open queue selenium remote desired capabilities in case you are getting any error you can just hover over it and then import it from here and that's it and now I will say cap dot set capabilities if I press ctrl spacebar it is water completing and I have to give a capability name and its value here so we have to say device name and device name you can find from your mobile device so if you go to your mobile device you can see this is my real mobile device attached to my system I will go to settings and you know I will scroll down and about phone and you can see your device name here Micromax hs2 now you can actually use any random name as well I have checked that it works with any name but it's better to give some meaningful name here so this is my device name and then again cap dot set capabilities and a key and a value I will just copy this statement and paste it multiple times so that I do not have to add it again and then the next thing is the UDID and UDID is the device ID that you get from adb devices so if i go to a new tab i am pressing command D on my keyboard and again I will say adb devices so this is my device ID I will copy it from here and provide it here the next thing is platform name and platform name is Android because I'm using an Android mobile and then the platform version so this is the version of the Android so again if you go to your mobile device and you can go to settings and again you can go to about phone and you can see the Android version is seven one two here so I will say here platform version is 7.1.2 so this was about the device or the mobile phone now we also have to set the capability for the application and for that we have to give her a package and app activity so every application on your mobile device including browsers calculator camera or any application that you have will have our app package and an app activity and for that you can get some applications on your mobile so you can go to your Play Store and you can search for applications like APK info and then there are other applications as well like my APK app info and so on so I'm using a pecan for you can install it in my case it is already installed and I will just show you so you can see this is a pecan four and when you go here it will give you a list of all your applications on your mobile so you can see Chrome camera calculator calendar everything and then you can click on application you want so for example I want calculator and you will see this is the ad package comm dot my OS dot calculator - so I will say a package here calm dot my waist dot calculator - and then I also have to give an app activity and that you will find here so if you scroll down you will find this activities and go here and this is the activity comrade my OS dot del theta 2 dot calculator so this is the same thing like until here and then dot calculator ok so we have also given the capability for our application and now we have to use the selenium driver or the appium driver so for that I will just declare it at the top I am declaring it a head at the top so that can be used by all the functions so I will say I can use a webdriver I can use the webdriver like this or I can use our happy emdrive err or I can also use an android driver and in case of iOS I can use a iOS driver now what is the difference so this is the our selenium webdriver and then appium driver has features more specific for a p.m. mobile testing and then Android driver has features more specific for our Android device testing so you can use actually any of these and for this so you have to download the this from vaji open queue selenium so for this I will just show you with IBM driver so of course if you are using some if you are testing some application that has to be tested on a web browser or desktop browser as well as on mobile then you will use a webdriver otherwise you can use like a p.m. driver and I will say a p.m. driver driver and I have to import it from IO OMG our client and then here I have to now send this desired capabilities to the appium server so I will say driver equals mu I can say appium driver or i can also say android driver here IBM driver and I will see a mobile element and then the desired capabilities which is cap and here it is showing me some error it is asking me to import and I can in fact give it here directly I will say mobile element and that's it and yes and here it is saying change driver to static so because we are using it in a static method so I will say static fpm driver mobile driver so here I am passing capabilities but I also have to pass the URL of our appium server so for that I will say URL I will use the URL class and I can give any variable URL equals new URL and press ctrl spacebar on my keyboard and I have to give the string here and for that you can see because we have started our appium server on the IP one two seven zero zero one and four four seven two three I will just copy this this is what we give and provide it here so if you go to your hell p.m. you can see the host by default is 0 0 0 0 which is equivalent to 1 to 7 0 0 1 IP on the system and the port is 4 7 to 3 so if you have not changed the port it will be 4 7 2 3 here as well and then WT and hub so this is what we use here and then we also have to pass this URL so I will say URL here no now you can actually put this entire thing directly here in place of URL but it is more easy and handy if you just do it separately so that it is more clean to view and here whenever we use this URL will be connect to this URL we have to either surround with trycatch or add through so I will select add throws declaration and I will throw the exception so you can see on the function declaration it has added throws exception and that is why it is now not showing the error and at the end I will just print out the application started so that I know it is working fine and I will save everything and then I have to call this function from main method because it is it will start from mean so I will say open calculator and again it is showing me an error because I have to either add throws or surround with try-catch so I can actually this time surround with trycatch I will just say here try and this will come inside try and then I will say catch so this is to catch exception so in case there will be any exception it will be cached and I will give the name exp and I will say exp dot get caused exp dot get message and exp dot print stretches and this I can also print out I will say as PI a so press control space bar on my keyboard for auto completion and here as well and that's it so I do not have any errors and now if I go to my mobile device you can see my mobile device here let me just open the device here so this is my mobile device and this is my code to start my mobile device to start calculator application on mobile device using the appium code so this is my code here and I will just start this I will do a right click run as java application and let us just see now it should start calculator on this mobile device so let's just wait so it should be connecting to the APM server now and yes you can see it has started calculator on the mobile device and it is saying application started so we have done this step start calculator application and read and validate now if you want to do any actions on this application like click on this buttons or do some calculation for that you have to find the locators of these buttons and then you will have to say here something like a web element or because we have already used mobile elements you can say mobile element and you can give any name for example this is the one button equals driver dot find element by a dot you can use ID name XPath anything and then give the ID here and then I will say 1 dot click or something so this is something we will learn how to do this in the next video we have a APM desktop inspector using that we can actually get locators for all the elements and it will be very easy and very handy and that is exactly what we are going to learn in the next video for now I will just stop here and we are able to start our application with our appium code I hope the session was very useful for you thank you for watching
Info
Channel: Automation Step by Step
Views: 136,832
Rating: undefined out of 5
Keywords: how to run first appium test, first appium test with java, how to create appium automation framework, appium automation test, how to code for appium with java, appium with eclipse, how to add appium java client libraries, how to setup appium java project, how to find app id, how to find appPackage on mobile device, how to find appActivity on mobile, how to automate mobile applications using appium
Id: N7vY3cPSo8g
Channel Id: undefined
Length: 21min 42sec (1302 seconds)
Published: Mon May 06 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.