Selenium Maven With Eclipse | Maven Selenium Project In Eclipse | Selenium Training | Edureka

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] selenium the most commonly used automation testing tool is a boon to the software industry advancement in this field has made their lives very easy so hi guys this is Vaishnavi from Adi Rekha and in this session let's try to understand what a selenium and how to implement a selenium even project so before proceeding further let's take a look at the agenda of this module we'll start the discussion by understanding what is selenium and water its major features and try to implement a use case of the same and then we'll talk about the automation build tool maven and know its features once we understand what is Navin let's integrate the maven dependencies onto a selenium project and also look into what exactly happens in a selenium maven project and discuss their advantages and finally we'll end this session by implementing a real-time use case of selenium maven so without any further ado let's get straight to the module let's start the session by understanding the first topic what is selenium and what are its features selenium as you all know is an automation tool used to test web applications the major features of selenium includes selenium is open source there is no licensing cost involved which is a major advantage over other testing tools and the other major features behind selenium ever-growing popularity our test scripts can be written in any programming language like Java Python c-sharp and so on and the test can be carried out on any platforms like Windows Mac Linux and so on and it can also be drawn across different browser platforms like Firefox Explorer Chrome and so on selenium can be integrated with the tools such as test n G and J unit for managing the test cases and generating reports but there surely has to be shortcomings right we can use selenium only to test web applications we cannot test desktop applications or any other software selenium does not have any native reporting facility but we can overcome this issue by integrating it with the frameworks like test ng or j-unit ok so this is about selenium and its features guys now let's take a look at the use case of selenium or let's take a look at how to implement a saline in project so these are the basic prerequisites that are required to run the test scripts that is the latest version of Java being installed in your system the latest Eclipse IDE being installed and some selenium plugins like the selenium standalone server and the selenium IDE which are used according to any programming language so let's take a look at the implementation process in this session we'll be automating a web application called Amazon and I think all of you are very familiar with this online application so we'll automate this web application using selenium interested to know how let's take a look guys so to do that you need to have the latest Java installed in your system and latest Eclipse IDE so I have both these tools installed in the system so let's check if it's working properly or not okay so I'm going to the command prompt to check the latest version of Java installed in my system so I am going to write Java version so I'm going to use this version of Java that is Java 1.8 in my session and the latest Eclipse IDE that is Foton okay let's open this as you can see it asks for the directory workplace so this is the directory in which my Eclipse folder will be present so I'm going to just launch this as you can see the workbench is loading here so this is the Eclipse workspace guys so these are the projects that have already created or worked on now in order to write a new test grip we need to create a new Java project so to do that let's click on the file go to new and you can't find the Java project here so we'll go to other and type Java here you can see that the option called Java project exists here so you need to provide a name to the project and I'm going to name this as a Eureka shalini okay and click on finish click on no you can see that the folder is being created here by the name of the project that we provided just now that is edu Rekha selenium so now let's click on the drop down here you can see the JRE system library is present here which is basically the Java libraries that are added to the project and the source field is where we are going to write our piece of code now we need to add the selenium jar files to this project in order to run the test scripts so to do that I'm going to right click on my project go to build path and I'm going to configure build path and you can see that the Java libraries are already present and we need to add the external jar files that is we need to download the selenium jar files and add it here so to do that let's search for the selenium jar files okay and I'm going to search for selenium jar files ok just click on the first link here so this page contains all the charr files that we require to import to our project so first let's start by downloading the selenium standalone server the latest version is available here so just click on the version and it will download and we're writing our code in Java so we require the libraries of the Java here so I'm going to download this as well okay you can see that these are the jar files available in selenium Java okay so let's get back to our project so now let's add the external joists here okay so just select all and click on open click on open so we're done adding the selenium jar files to the project so we are going to click on apply and close you can see that there is another folder by the name reference libraries created here which holds all the selenium libraries here now we need to write our piece of code so to do that I'm going to create a package first and then write the piece of code you guys have a doubt on why do we need to create a package package basically holds the group of classes so for that we require the package first and then we are going to create a class here so right click on the source file here go to new and go create package one thing about the name of the package is it starts from the reverse order so I'm going to write code ah'd ID eureka here for the package name click on finish you can see that the package is being created here now let's write our code so go to new and click on class it asks for the class name so I'm going to provide the name demo class and do select the main function I can click on finish all right so we are done creating the class here now let me make this more visible to you guys okay now we think it's clear to you guys you can see that the package by the name that I provided co dot ed Eureka is being created here under which our class demo class recites and our main function also so we will start writing our code from here okay so let's take this out so like I mentioned earlier we will automate a web application called Amazon in the session and to do that we need to select a browser driver that is a geek or driver for Firefox a chrome driver for Chrome and so on okay so in this session we will be working on Chrome so I will select the chrome driver and download the executable file so to do that let's get back to our selenium web site so you can find all these browse the driver present here I've already downloaded the Google Chrome driver here so I'm just going to write a piece of code to instantiate the driver so let's get back to the project now we need to set the system property so that the system knows that we are using Chrome driver to do that I'm going to write system dot set property where the first argument holds the name of the web driver that is webdriver dot chrome dot driver there as the second argument holds the path of it so in my case it's in C Drive let's see how you can copy the path okay you can see that I also have Kiko driver here so I am going to search for this chrome driver okay so this is the path for chrome driver let's get back to a project and we paste this here now kid done I think you guys have understood how this is done now we need to instantiate the webdriver instance to the throne driver so to do that I am going to create an object of the webdriver and call it a driver and instantiate it with the new chrome driver okay you can see that there is an error being thrown here so just click on the webdriver here so you'll find it quick fixes here just select the first option that is import webdriver what is import mean we need to import the webdriver functionalities which are not there in the project so let's import the webdriver functionalities so you can see that there is a command being automatically generated here ok and the same goes with a chrome driver as well import the chrome driver functionalities to the project after this we need to get the URL of the particular page that we are going to search for so in our case it is Amazon so I'm going to consider the object of the web driver that is driver dot get one thing about Eclipse is you don't have to complete the entire code there are suggestions about the functions present here so just paste the URL or write it down if you know it HTT be : amazon taught in ok so this is the webpage that we are going to search now say if you want the web page to maximize how would you do that using selenium so to do that I am going to consider the object of the web driver that is the driver dot manage dot window and maximize this command helps in maximizing the webpage ok so now let's take a look at the web page once ok now let's search for Amazon dot okay you can see that this is a web page and each element in this web page is called a web element okay so now say for example if you want to search for this particular search box here you can inspect or search this using selenium by right-clicking on it and inspecting the code okay let me tell you one thing about selenium guys selenium use a certain element locators in order to search for an element okay so they are named class ID class name and so on so in this case you can see that the input type is present an ID is also present which is an element locator in selenium so I am going to copy this ID and get back to our project and write a piece of code so I'm going to write the web element and create an object of the web element say search box and find the element using the object of the webdriver dot find element we are going to find the element by ID okay and now we are going to paste the ID here and semi code you can see that it is throwing an error here so just click on the web element and import the web element functionalities to a project now if you want to search for an element say if you want to search for earphones in general or anything you need to send some text to the search box right so to do that I am going to consider the object of the web element search box dot send geese which helps in sending the characters under which I am going to search for JBL earphones okay so now let's get back to our web page now after you're done searching for the text here say if you want to click on this particular search box okay so let's inspect this search box here so you can see the classes present here which is one of the element locators in selenium so I'm going to copy the class and get back to a project okay so I'm going to create another web element by the name search icon and find the element using the element locator that is by the class and I'm going to paste the name of the class in this K and semicolon now if you want to click on the search icon we are going to consider the object of the web element search icon dot click which helps in clicking the search icon ok so let's get back to our web page once and let's enter it manually I'm going to type JBL earphones now say if you want to search for this particular checkbox here off board and I'm going to click on this checkbox here you can see that there are so many results here now say if you want to scroll through this page till the end how would you do that using selenium let's take a look now let's get back to our previous page where we'll inspect the boat checkbox right click inspect it the name is present here okay so which is a element locator in selenium so let's get back to our project by this and write a piece of code so I'm going to create another web element by the name checkbox which helps in finding the element by the name okay and paste the name here and we need to click the check box so I'm going to take the object of the verb element checkbox dot click done I think you guys have understood what is happening till now in order to scroll through a page we are going to use something called the JavaScript executor which is an interface that helps in executing the JavaScript through selenium so now let's try to take a look at how this can be done so I'm going to write a piece of command after the maximizing of the screen take it as JavaScript executor and create an object of the same Jas and Brisas JavaScript executed and linked it to the driver done guys okay now it is throwing an error here so let's import the JavaScript executor to our project done the error doesn't exist and after this we are going to write a command here to scroll that is the object of the JavaScript executor dot execute script where we are going to consider only one argument here that will be window dot scroll by and specify the axis in which you want to scroll say if you want to search for an element on the x-axis so to do that we are going to consider the X plane and if you want to scroll down to a page we are going to consider the y-axis so in my case I am going to scroll down to a page so to do that the x-axis will be 0 and the y axis I am going to take it as 4,000 okay and I'm going to delete this second argument done after this is done let's quit the driver execution or end the driver execution so to do that I'm going to write the quit command your driver dot quit which helps in quitting the driver execution let's save this program now let's run this program just click on run so you can see there is an exception here which says in the main function the executable directory is wrong I think we provided the proper path to the chrome driver guys you need to add the extension of the chrome driver to this this is the folder which has the chrome driver followed by the chrome driver extension that is chromedriver dot exe that is the executable file so without this the chrome driver wouldn't run and let's save this and run the program chrome driver is starting you can see that the chrome is being initialized the links to the webpage amazon maximizes the screen searches for JBL earphones and that was pretty quick let's figure out why that is as you could see there was no pause in execution during clicking of the checkbox and scrolling down a page so we are going to pause the execution for a maximum of three to four seconds in order to see what the execution processes so to do that I am going to use the thread dot sleep command which helps in pausing the execution for a few seconds so this is always in milliseconds so I'm going to consider it as four seconds you can see that the error exists here so just click on this and it provides us with two fixes at throws declaration or surround it with try-catch but we are going to handle the exception by throwing declaration that is it avoids the interrupted execution during the process one after the strolling of the page thread dot sleep command and even this will be for four seconds all right now let's try to execute this program save the program and click on run from driver is starting loads Amazon Web page maximizes the screen searches for JBL earphones searches for the check box and scroll down to a page and quits the web browser so this is about the implementation of a selenium project I think you guys have understood how to automate a web application using selenium now let's move on to our next topic what is Nathan Nathan is an a dish which means accumulator of knowledge it is a build automation tool used primarily for Java projects it addresses the two aspects of building software first it describes how the software is built and second it describes its dependencies maven can dynamically download the Java libraries and maven plugins from one or more repositories and store them in a local cache it can also be used to build and manage projects like c-sharp Ruby Scala and other languages it also offers simple project setup that follows the best practices maven has the ability to work with multiple projects at the same time so this is about the introduction to maven now let's understand the structure of maven so the main advantage of having this structure is it is analogous to adopting a site-wide look and feel so the top level the file descriptors of the projects are present in the palm dot XML file in addition there are textual documents meant for the user to be able to read immediately on receiving the source that is readme dot text file and license dot txt file and so on so there are just two basic sub directories of the structure the source and the target so the other directories that would be expected here are the metadata is like the CVS get file and so on so the target directory is used to house all the output of the build whereas the source directory contains all the source material for building the project its site and so on it contains a subdirectory for each type main for the main build artifact test for the test unit code and resources site and so on within the artifact producing the source directory there is one directory for the language that is Java and the other one for resources if there are other contributing sources to the artifact build they would be under other sub directories so this is about the structure of the maven project now let's take a look at their use case maven dependencies are easily available you don't have to pay for any of the dependencies that are available ok so this makes the build process easy by providing a lot of shielding from the details and it also provides the uniform build system by allowing the project to build using its project object model and it also provides quality project information about the cross-referenced libraries and the list of other project dependency lists so this is about the use case of maven now let's try to understand what is selenium maven I'm sure you guys have understood what a selenium so I'll just walk you through this again selenium is an automation tool used to test web applications and it uses the dependencies of maven and testing G to run the test cases and the maven dependencies can be run across different platforms like Chrome Opera and so on and all these dependency are added to a file called palm dot XML okay that is the project object model file it is in the XML form so all the dependencies are stored into this file and once this is done we are going to integrate it with the selenium project that is the dependencies are added to the selenium project so this is how the selenium maven works now let's take a look at their advantages selenium is an automation tool where maven is a built automation tool both of them combined together will make the build very powerful and it is easy to execute tasks very faster maven allows to build projects using the project object model and it also helps in maintaining records whereas selenium cannot maintain records on its own this selenium maven helps in reducing the duplication of code say the command exists for more than once in a program so these kind of duplications can be reduced using selenium even and it also provides guidelines for better project management practices so these are the advantages of selenium maven now let's take a look at the use case of selenium aving so let's try to test a webpage called neuters where we will try booking a flight and get a confirmation so let's get back to our Eclipse IDE I have already written the code for this project here because it's a little too lengthy and I hope you guys can understand this clearly so I've already created the project by the name at Eureka selenium project I'll just click on the drop down here you can find the structure of maven here the first one is the source main Java source test Java the library functions the maven dependencies the test ng dependencies the screenshots so I will tell you about the screenshot folder during the end of the project and the source folder Target Field and the pom dot XML file which holds all the dependencies so let's understand what are these fields what a source main Java source main Java holds the root level packages it holds the main function as well as the Java programs associated with the source file and source tests Java this folder holds the test cases of the process it holds packages that help in simplifying the projects under test this is the Java libraries and talking about the maven dependencies this field holds the dependencies of the packages that are required to run a specific test case so this is about the maven dependencies and talking about the source and the target field these folders hold the source and the target details of the project the source field holds the main function of the package whereas the target field holds the maven compilation details and the test reports now coming to palm dot XML poun dot XML holds the maven dependencies of a particular package so now let's take a look at the drop-down of each of these let's start with the first folder source May in Java you let me write in this so that you can clearly see the name of the packages so there are three packages here namely carotids eureka rot framework packages test packages and UI packages so like I mentioned packages hold the group of classes so let's take a look at the classes under the first package click on the drop down you can find two classes by the name draws a factory and capture screenshot and go to the next one that is test packages it also holds two classes namely helper class and test case class and coming to the last package this holds the entire process of booking a flight and sorry guys is not in a proper order it is in the alphabetical order but the first one should be the login page where you would first login to the web page and then find the flight according to the specifications provided and then select a flight and book a flight and get a flight confirmation so this is the process that takes place in this UI package now let's take a look at the source test Java folder this basically holds a single package and I have named it as a certification project and it has a class called app test that is the application test class okay so this is about the source test Java folder now talking about the source and target field source field like I mentioned earlier has two fields namely main and test ok so let's click on the drop down here it says Java co-ed Eureka that is the name of the package and these are the frameworks that exist now let's take a look at the test Java certification project and the basic application test that is present so this is about the source field so the target field holds the compilation results and holds the reports of execution okay so this is about it so this is about the structure of selenium even now let's take a look at the first program here that is the browser Factory so first let's take a look at the first program here which is the browser factory program there we specified the browser driver under which we are going to work okay so I've already returned the piece of code here so you can see that the name of the package is here it was under the framework package and I'm going to create a class called browser factory where I'm going to create a static keyword webdriver and create an object of the webdriver that is the driver after that we are going to call this browser factory function here okay this is basically a constructor and after this and after this we are going to get to the main part of this program where we'll call the function called get driver which helps in getting the browser driver details so under this we are going to write the condition if the driver that is the object of the web driver is null so under this I am going to instantiate the chrome driver options to the new chrome options so to do that I am going to write Chrome options and create an object of the Chrome options say options and instantiate it to the new chrome options okay so after this say if you don't want to be disturbed or interrupted during the execution of the program so we are going to write a few commands here which will help in making the process easy so we are going to consider the object of the Chrome options options and we'll add the arguments saying disable the notifications that is you don't want any notifications during the execution of the program after this I am going to set the page load strategy to none that is you don't want the page to load while executing to do that I'm going to consider the object of the chrome options options dot set page load strategy and the page load strategy is none okay so once you're done with this the same process continues here that is we are going to set the system property to the name of the browser driver that is in our case the chrome driver and specify the path in which it is located so in my case it is in the C Drive here so I'm going to write the path here and then I am going to instantiate the web driver object to the new chrome driver objects okay so I'm going to consider the object of the web driver driver and instantiate it with the new chrome driver options options is an instance of the chrome options after this now if you want to maximize the screen of the web page so you can do that using the same command that we used before that is driver dot man eh dot window dot maximize so this helps in maximizing the window and then say if you don't want any unwanted cookies during the execution of the program so we'll delete all the unwanted cookies using this command that is driver dot manage dot delete all cookies okay so once you're done with this let's try to add the implicit weight here that is you want the prom' driver to wait for a few seconds before loading you might ask why do we need implicit weight because that is the new load the Chrome page you won't see the basic Chrome page there that is the default chromedriver page so in order to view the chrome page we are going to add the implicit weight command here okay so driver dot manage the time odds and we add the implicit wait for 45 seconds and the unit of time is in seconds okay I think you guys have understood what this means after this we'll add the page load time out that is it sets a limit under which the page should load to do that I'm going to use this command that is driver dot manage dot timeouts and specified the page load time out for 45 seconds and the unit of time is in seconds hope you guys are clear with this so after this now say if the driver is not to null it will return the driver functions okay so this is about setting a path to the chrome driver guys now let's take a look at the other browser drivers so I'm going to call the gate driver here by passing a command called browser name under string okay so we are going to consider this same if condition here if the driver value is null so we are going to consider another condition here which will compare the two strings and ignores the cases okay so to do that I'm going to write if the browser name equals ignore case Firefox if the browser name is Firefox I'm going to set the property to the Firefox driver that is system dot set property and specify the name of the web driver that is giko driver and then specify the path so after this I'm going to instantiate this web driver to the new Firefox driver and the rest of the process are the same that is we are going to maximize the screen delete all the unwanted cookies at the implicit weight in order to view the Firefox web page and add the page load time out now else if the browser name is chrome say if you want to use Chrome now the same procedure follows here just that the property changes that is the name of the browser driver and the path changes along with the instantiation of the browser driver okay so this is about the chrome driver now if you want to use the Internet Explorer you can do it using these commands so this is about the browser driver guys so before proceeding further with the capture screenshot and the test packages let's take a look at the UI package where we can book a flight let's start with the login page so as you can see that the login page is under the package code or a Eureka dot UI packages under which I'm going to create a class called login page and create an object of the web driver think you guys have understood what this is and after this I am going to pass the argument to the login page class that is the object of the web driver and specify the instance of the web driver that is this driver is equal to driver okay so after this is and we are going to use the annotations in order to find the element in the webpage maven uses the annotation method in order to find an element on a webpage so in this case we are going to use two annotations namely find buy and cache look up so these are the annotations that we are going to use now let's understand what is fine buy annotation fine buy is an annotation used in page object in selenium tests to specify the object location strategy forever bellomont whereas the cash flow cup is a method where some records will be loaded into the memory at startup or when loading the first time so let me tell you how this works so the cache look up specifies the web element or defines the web element and this particular web element can be found on the web page using the fine buy annotation I think it's clear guys the Mazin helps in finding the location of the web element by find buy annotation and it is going to use the selenium element locator to specify the path or the location of the web element so in this case it is the name that is the name specified of the web element and this is the location okay I think you guys have understood this so the same goes with the password and login as well the cash lookup helps in defining the web element and passing the object to the web element using this maven is going to find the element using the element locators in selenium and find the path or the location of the web element to be searched okay this is the same with the login also now we'll create a class called log in WordPress and pass these attributes that a string use and string pass to the function okay so we are going to use the try catch method here to reduce the exceptions that occur during the execution so under this I'm going to specify the user name and send keys to the username that is used okay and we are going to use the sleep command here in order to pause the execution for three seconds and after this I'm going to consider the password and send keys to the password that is pass and once this is done we'll again pause the execution for three seconds and click on the login okay I think this is clear to you guys how to log into of a page and then we'll catch the exceptions that occur during the execution of this process and this command helps in pointing the exceptions or errors that occur during the execution and prints the number of the line in which the error exists so this is about the login page now let's take a look at the flight finder page so this page basically helps in finding the flight in the web application so even this program comes under the package UI package and we are going to create a class called flight finder page under which I am going to declare the web driver and create an object of the web driver and I'm going to pass the argument to this function flight finder page that is the object of the web driver which holds the instance of the driver and we are going to follow the same procedure here that is we are going to use the cache look up method to specify the web element and create an object of the same and this particular web element is found using the element locators of selenium and in this case it is the XPath XPath is an element locator in selenium which is used to navigate through the elements and attributes in an XML document so we are going to search the element using the XPath and specify the XML location of this web element so you can see that the web element is roundtrip first which specifies the type of trip which you want to go on and it is a one-way trip the next one and pass the count that is the number of passengers count from port specifies the departure port from month specifies the month from which you want to start your traveling and from day specifies the day from which you want to start to port specifies the arrival port and two months specifies the month in which you want to end this trip and two days specifies the day in which you want to end the trip an airline specifies the name of the airline that you want to board into and find flights which help in finding the flight according to your specifications ok now after this if you want to set the class of the flight that you want to board in to say it is a service class or a business class or an economy class now I am going to consider this web element called service class and I'm going to provide the location of the business class so I'm going to select the business class flight and after this I'm going to create a function called continue WordPress under which I'm going to pass these many attributes that is the P count from port F month F day and so on so so to start the process I'm going to use the try-catch method which helps in reducing the errors or exceptions occurring during the execution first I'm going to pause the execution for say two seconds and then we'll pause the execution for two seconds and then we'll pass the count of the passengers and we'll send the keys to the pass count saying P count and we'll pause the execution for two seconds and from Port we are going to send keys to this front port function f 4 so we'll understand what is this P count and F port in the test case class which is the last main class of this project so till then just bear with this and we are going to pause the execution for two seconds after this and from month we are going to send keys called F month to this and again pause the execution same goes to the F day that is from day as well and to port to month to date that is the arrival date in the service class flight which specifies the business class flight that I want to select and the airline and will click on the find fly and after this will pause the execution for two seconds and we'll catch the exceptions that occur during the process using the catch there we are going to print the line in which the error occurs during this command okay so this is about the flight finder page guys now let's try to select the flight even this program comes under the package the UI package under which I'm going to create a class select flight page and I'm going to declare the web driver and create an object of the same and and I'm going to pass the attribute to the Select flight page that is the web driver driver under which I'm going to specify the instance of the driver so the same procedure continues here guys that is we are going to use the cache look up to define the web element and find it using the fine bye annotation and the selenium element locators and specify the path or the location in which the element is present so we are going to search for the blue skies Airlines and the blue skies Airlines 361 Pangea Airlines unified Airlines blue skies Airlines this is for return ticket guys there are two tickets basically because we have selected the roundtrip we need to book tickets for both the sides that is the departing tickets and the return tickets so we are going to specify both these using the particular tagline here that is underscored e is for departing and P is for return ok so I'm going to search for the blue skies Airlines 361 underscore D and specify the path and search it using the X path which is an element locator in selenium and specify the path or the location of the element so this is carried out for Pangea lines as well and the unified Airlines as well and after this we are going to click on the continue button to continue the process ok so the X path of this is also specified here ok so this is about the find by iron cache look up annotations let's create a function called depart Airlines WordPress and pass the string function here that is depart airline and again we are going to use the try catch method to reduce the errors and exceptions occurring during the execution of the process under this I'm going to write a condition if the depart Airlines equals ignores case the blue skies Airlines 360 that is by comparing both these strings and ignoring the cases that is even if it has an uppercase or lowercase ignoring the cases we are going to click this particular airline that is blue skies airline 360 underscore D so we are going to click this particular airline and pause the execution for two seconds and the same goes with the other airlines as well we'll compare the name of the depart airline with the other airline that we are going to provide compare these two ignoring their cases and click on the blue skies airline 361 underscore D for departing okay the same goes with the Pangaea Airlines and the unified Airlines as well and after this the catch is executed where the errors are pointed out and printed using this command okay so we're done with the depart Airlines part so now let's come to the return Airlines we are going to create a function called return Airlines wordpress and pass the string return airline okay so under this we are going to use the same try-catch method to reduce errors and consider the condition if the return Airlines equals ignore case the name of the flight specified by the user and click the name of the return flight and we'll pause the execution for two seconds and then they'll move on to the next name that exists that is the blue skies Airlines 361 so this name is compared with the return airline names that we provide ignoring the cases if these two texts match we are going to click the blue skies Airlines 361 underscore T which is a return ticket and will again pause the execution for two seconds and then move on the same goes with the Pangea Airlines and the unified Airlines as well and we'll catch the exceptions that occur during the execution using this command and after this we need to click the continue button that is present so we'll create a function called continue and we are going to consider the object of the web element con dot click and we'll pause the execution for two seconds and catch the exceptions that occurred during this execution so this is about selecting a flight guys now let's take a look at booking a flight so even this program comes under the UI packages where I'm going to create a class called book flight page under which I am going to declare the web driver and create an object of the same and after this I am going to consider the book flight page class and pass the argument web driver and the object of the web driver driver under which the instance of the web driver is present ok so we are going to use the same annotations here that is defined by I am the cache look up where the cache look up helps in specifying or defining the web element and it is found using the meant locators in selenium and defined by annotations so the web element I'm going to specify is the first name which can be found using the element locators in selenium that is name and the path or the location of this first name okay so this is the location of the first name next we will find the last name in the page so the last name can be found using the name which is an element located in selenium and using the location of the last name that is passed last zero okay so the same goes with the meal as well meal specifies which type of meal does you want to eat and gets the location of the card type the card number the expiring month of the card the ER specified and the name according to the card that is the first name middle name and the last name and then we are going to click on purchase because we need to purchase the tickets right okay so to do that I'm going to click on purchase this particular web element can be found using the XPath so this is the location in which the purchase web element exists and after this I am going to create a function called purchase press under which I'm going to pass these particular attributes as name L name meal card type and so on and after this I'm going to use the try-catch method to reduce the errors first I'm going to pause the execution for two seconds and then we'll send keys to the first name that is f name the name that we are going to specify and then pause the execution for two seconds and past the last name and then meal what type of meal I want to eat cart type is it a MasterCard or a Visa card or so on the card number the expiring month of the card the expiring or of the card the first name according to the card the middle name and the last name and then we'll finally click on the purchase button and after this we are going to catch the exceptions that occurred during the execution using this command okay so we're done with booking a flight now let's take a look at the flight confirmation this page basically helps in logging out of a web application even this program comes under the package ui packages under which I'm going to create a class called flight confirmation page where I'm going to declare the web driver and create an object of the same and I'm going to call the same flight confirmation page and pass the argument webdriver driver under which the instance of the web driver is specified and we are going to find the location of the logout web element and after this we are going to search for the web element log out in the web page and we are going to search the element using the XPath and this is the location of the logout and then I am going to call a logout press function under which I am going to click on the button logout this helps in logging out of the web page so this is about the UI package guys now let's take a look at the helper class here so this program is under the test package and we are going to create a class called the helper class under which we are going to declare the web driver and create an object of the web driver and we are going to call the browser factory function here and create an object of that class say browser factory and name the object as object one and after that we are going to call the helper class function here that is basically a constructor and what is before suit have you guys ever heard of this before suit is an annotated method which will run before all the tests in the suit has run so we are going to create a function of this the for suit and we are going to call a constructor and after this we are going to call the before class here so what is before class before class is an annotated method used to setup trone properties initialize the driver and so on so under this before class I am going to create a function called before class and print this particular text okay so this prints before the execution of the process and after this I am going to call the before method annotation before method checks for the database connection before executing the test scripts under this I am going to create a class called before method class and I'm going to print n before method that is this text will be printed before the execution of the program and I am going to link the helper class to the webdriver object that the driver and we'll call the browser factory function that is browser Factory dot get driver and Chrome because we are going to work on Chrome we are going to specify this using the browser factory program okay after this we have after method after method is used to close the database connection okay so we are going to call close here this closes the driver connection and after that we are going to execute the after class then after class helps in stopping the driver execution okay in this I am going to create a class called object class and create a constructor of the same and after that I'm going to call after suit after suit is a method which will run after all the tests in the suit have run under this I am going to call the after suit function under which I am going to end the driver execution using driver dot quit command okay so this is how the helper class works now let's take a look at the capture screenshot class you guys will understand what exactly is this screenshot field present here okay let's take a look at this program so this program comes into the package framework package and we are going to create a class called capture screenshot under which I'm going to call the constructor of the same name that is capture screenshot and we'll call the function get screenshot and pass these attributes that is the web driver and the string function where I'm going to specify the path of the file and the object of the driver okay so under this I am going to use the try catch method to reduce the errors and I am printing this particular text in get screenshot method so once this is printed I'm going to take this function called take screenshot and create an object called PS so I'm going to consider the function take screenshot and specify the object name that is TS which will be linked to the webdriver object that is driver take screenshot linked to the driver okay and after this I'm going to print this particular text that is before get screenshot as so we need to save these screenshots in the file so to do that I'm going to take file source the source file and take the object of the take screenshot and consider the function get screenshot as and specify the output type as file okay I think you guys have understood this and after this I'm going to print another text after get screenshot as we create a new folder for this so we are going to copy the file from the source and send it to the new file and specify the file path okay so these are the functions that takes place in this particular program and after this we are going to catch the exceptions or error that occurred during the execution using the catch command okay and after this we are going to specify the date that is we need to specify the date in which this particular screenshot was taken so to do that I am going to call this particular function string get dead pine stamp under which I am going to specify the date and create an object of the string type that is s date part and s date stamp which holds this string command and now we are going to instantiate the date that is the object of the date command is equal to new date ok this specifies the current date and after this I am going to print o date dot to string now what is the to string to string is automatically called when the date is represented as a text value so I'm going to print this in the form of this and after that I am going to split this particular date into date month and year so to do that I'm going to consider the date part which is in the form of array string and specify the current date and split okay so the date stamp which is of the form string holds the date in a form of date month and year ok so the date part specifies the array string which holds the array and the string functions which specifies the position in which the element is present say in the fifth element you want the year to be present so it specifies the year in the fifth position and specifies the date in the first position month and the time okay so these can be done using the date part which is of the form string and these are separated using underscore okay so all of these are separated or split using the underscore operator rather than the colon so this is the command to replace the colon with the underscore that is s date-stamp is equal to the S state stamp and replace the colon with the underscore and after this will print the S state stamp which is of the form string and after that we'll return the date stamp value so this is about capturing the screenshot on the webpage guys now let's take a look at the master class of this project that is the test case class this is a program under the test packages where I'm going to create a class called test case class which extends the helper class by extends I mean it inherits some properties from the helper class and I'm going to create a constructor of the same class that is the test case class and called the annotation at test what do you mean by a test the test annotation tells the j-unit that the public void method which is attached can be run as a test case okay so this is the function of the annotation test and after this I'm going to create a function called return ticket and I'm going to again consider the try-catch method to reduce the errors and exceptions so in this I am going to first print the text in return ticket after this we are going to try to get the URL of the webpage that we want to search for that is driver dot get URL the same as we used in selenium ok so this is the URL of the webpage that we are going to search we need to log in to a page after we get the URL of the web page so to do that I'm going to create an object of the login page and name it login page under which I'm going to initialize the driver and the login page classes I think you guys remember what we did in the login page class ok so I'm going to call the function of login page in this particular program that's the reason why I said it is a master class of this entire project and after this I'm going to pass the commands here and I'm going to consider the function of the login page that is the login wordpress and pass the name and the password ok so this is the name and that is a password so this is the name and the password used to login to a web page and after that we need to find a flight according to our specifications so to do that I'm going to consider the object of the flight finder and name it the flight finder page and initialize the page factory to the driver and the finder page class ok let me zoom out first hope you guys find it easy now and once you're done initializing the driver and the finder page class we are going to send values to the flight finder page classes that is the object of flight finder page and the class of the flight finder page that is the continued wordpress where the number of passengers are present that is i'm going to specify it as one from port is Zurich and from month is July from date is 12 and the to port is Frankfurt to month is September and to day is 15 and the class is also specified which is a business class flight and the name of the Airlines is also present I am going to send in the Airlines name as the unified Airlines so once you're done sending values to the flight finder page let's select the flight ok so I'm going to create an objet of the Select flight page and name it select flight page and initialize the driver and the Select flight page classes so in this case we need to send values to both depart Airlines as well as the return Airlines so I'm going to call the function of the Select flight page that is the depart Airlines WordPress and provide a name Pangea Airlines 362 so this is the airline that I want to choose for departing Airlines and for the return Airlines I would consider the function of the Select flight page that is the return Airlines WordPress and provide this a name unified Airlines 363 and then we'll click on continue button ok so with this we end the select flight page and after that we need to book a flight so to do that I'm going to create an object of the book flight page and name it book flight page where I'm going to initialize the driver and the book flight page classes and we need to send in details to this particular function purchase press where we specify the first name the last name the meal the card type that is the MasterCard or not I'm going to specify it as a MasterCard the card number the expiring month and then the name according to the card that does the first name middle name and the last name so with this we are done booking a flight now we need a flight confirmation so to do that we are going to consider the object of the flight confirmation page a name it flight confirmation page where we are going to initialize the driver and the flight confirmation page classes and after this we need to get the screenshot of the flight confirmation so to do that I am going to use the function of the capture screenshot page that is booking details file where I am going to set the system property to the user directory and specify the location in which the screenshot should be saved so I'm going to write screenshots followed by flight confirmation details where it needs to capture the screenshot and get the tape timestamp ok and it should be in the form of a PNG file that is an image file ok so this is how you get the screenshot and after this we are going to execute this piece of code using the try-catch method again in order to reduce the errors so I'm going to consider the capture screenshot class here and also the function get screenshot where I am going to add in these attributes here that is browser Factory dot get driver which helps in specifying the browser details and booking details file which helps in capturing the screenshot ok and after this we are going to execute the catch command where the exceptions are printed so the log out press is a function of the flight confirmation page and we are going to call it using the object of the flight confirmation page that is the flight confirmation page dot logout press this helps in logging out of the execution process so this is all about the programs that we require to run the test scripts now let's try to run this program ok so it is in the form of the text ng file so just right click on test ng and run as a test ng suit ok like I mentioned before class before method is being printed you can see that the chrome is initialized maximizes the screen username and password is being provided and it also specifies the date and it signs in okay this is the flight finder page selects the round-trip the number of passengers is one departing from Zurich on July 12th arriving and Frankfurt returning on September 15 okay and the service class will be the business class and Airlines is the unified Airlines that we specified and clicks on continue and this selects the Pangea Airlines and the blue sky Airlines ok so this is the passenger details first name last name the me preference is vegetarian the card type is MasterCard and the number of the card the expiry Asian 12 mm honey route that is the name according to the card middle name and the last name so this is the flight confirmation page and it logs out now let's refresh this page ok and take a look at the screenshots here so you can see the format here which is of the form your month date specifies the time and the PNG which is of the form of an image so let's click on one of them ok so you can see that the screenshot is being captured here so that's it about selenium even with eclipse guys if you want to learn more about selenium webdriver don't forget to take a look at the ed Eureka's youtube channel and check out the selenium playlist thank you for watching this video happy learning I hope you have enjoyed listening to this video please be kind enough to like it and you can comment any of your doubts and queries and we will reply them at the earliest do look out for more videos in our playlist and subscribe to any rekha channel to learn more happy learning
Info
Channel: edureka!
Views: 53,707
Rating: undefined out of 5
Keywords: yt:cc=on, selenium maven eclipse, maven selenium testng eclipse, maven selenium project in eclipse, selenium tutorial, selenium maven with eclipse, selenium eclipse, selenium eclipse example, eclipse installation for selenium, eclipse for selenium download, selenium, selenium webdriver, selenium ide, selenium testing, selenium download, eclipse 2017, eclipse download, eclipse ide, maven download, maven project, maven tutorial, selenium training, edureka
Id: iA2iasRTMd4
Channel Id: undefined
Length: 62min 11sec (3731 seconds)
Published: Wed Mar 20 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.