Session 42 – Selenium with Java | TestNG Integration & … — Transcript

Introduction to TestNG with Java for Selenium automation, covering setup, features, and benefits like test case management and parallel execution.

Key Takeaways

  • TestNG is essential for structuring and managing Selenium test automation effectively.
  • It supports advanced testing features like parallel execution, parameterization, and grouping.
  • Selenium WebDriver alone is insufficient for comprehensive automation without TestNG integration.
  • TestNG simplifies running tests across multiple browsers and generating reports.
  • Integration of external libraries like Apache POI complements Selenium and TestNG for full automation solutions.

Summary

  • Introduction to TestNG as a Java-based unit testing framework designed for writing, organizing, and executing test cases.
  • Explanation of unit testing and how TestNG helps in testing individual methods at the code level.
  • Comparison of TestNG with other unit testing tools like JUnit, highlighting TestNG's additional features.
  • Steps to configure TestNG in Eclipse and integrate it with Selenium automation for enhanced testing capabilities.
  • Discussion on TestNG features such as grouping, prioritization, parameterization, parallel test execution, and report generation.
  • Emphasis on the limitations of Selenium WebDriver alone and the need for TestNG to achieve full-fledged automation.
  • Use of third-party libraries like Apache POI for handling Excel files, illustrating the need for external tools in automation.
  • Benefits of TestNG including managing test suites, executing tests based on groups or priority, and running tests on multiple browsers simultaneously.
  • Mention of TestNG's built-in reporting capabilities and plans to create more attractive custom reports.
  • Outline of upcoming sessions that will cover TestNG features in detail.

Full Transcript — Download SRT & Markdown

00:02
Speaker A
So from today, we're going to start TestNG. First of all, we'll see the introduction: what is TestNG, and what are the different features we have in TestNG and how we can use it in our automation. So we'll see that, and then we'll see configuration, how we can configure TestNG in our Eclipse. Then we will start writing test cases in TestNG.
00:15
Speaker A
it in our automation so we'll see that and then we'll see configuration how we can configure test NG in our eclipse and uh then we will start writing test cases in testing okay so first thing what is uh test NG so testng is basically a unit testing tool we can simply say unit testing
00:37
Speaker A
Okay, so first thing, what is TestNG? TestNG is basically a unit testing tool. We can simply say unit testing framework. Basically, it is designed for unit testing, and also it is designed using Java itself. So TestNG always works with Java itself; it is not for any other tools. So TestNG is nothing but a test new generation, and it is a Java-based unit testing tool. It is a Java-based unit testing tool.
01:02
Speaker A
testing tool so what is unit testing means what so normally the developers will create a code right so they develop the code and they develop the code in the form of different methods and they want to test those methods they want to test those methods they can create a unit test case means what they
01:19
Speaker A
So what is unit testing? Normally, the developers will create code, right? So they develop the code in the form of different methods, and they want to test those methods. They want to test those methods; they can create a unit test case. What does that mean? They will call those methods with different parameters, and the methods are properly returning the output or not, they will verify. So they will do testing at the code level. For that, they write unit test cases.
01:36
Speaker A
junit we have testing or many more tools are in the market but most popular is U unit and after that test NG so test NG is basically unit testing tool which we can use it for writing the test cases organizing the test cases executing the test cases generating the report
01:52
Speaker A
For that, they normally use unit testing tools. We have JUnit, we have TestNG, and many more tools are in the market, but the most popular is JUnit, and after that TestNG. So TestNG is basically a unit testing tool which we can use for writing the test cases, organizing the test cases, executing the test cases, generating the report, parallel testing. There are many more features.
02:08
Speaker A
we created a Java program so similarly we created a Java program and we have executed okay but we are not writing the test we are not writing the code in the form of test case right so we have
02:20
Speaker A
Because of that reason, we are also going to integrate TestNG into our Selenium automation, so we can incorporate those features in our automation. So far, we are just creating the code in Java style, just like how we created a Java program. Similarly, we created a Java program and executed it. But we are not writing the test in the form of test cases, right? So we have to create a test case and manage it in test suites. We can create and execute the test cases in the form of groups. Whichever group of tests we want to execute, we should be able to execute.
02:31
Speaker A
execute and we can generate the reports parallel testing parameterization prioritization there are many more things are there in our testing but selenium selenium web driver is just support only web automation means what we can just interact with the web elements and we can do certain
02:49
Speaker A
We can generate reports, do parallel testing, parameterization, prioritization. There are many more things in our testing. But Selenium WebDriver supports only web automation. What does that mean? We can just interact with the web elements and do certain validations on those web elements. That's the only scope of Selenium WebDriver.
03:01
Speaker A
our automation we have to do lot many things only interacting with elements adding verifications are not enough that is not full-fledged automation so we need to add some more features in automation so for example I have a 10 test cases and based on the priority I want to execute and what are
03:20
Speaker A
But beyond that, we have to do a lot of things in TestNG. Even if you're not only using TestNG, still in our automation, we have to do many things. Only interacting with elements and adding verifications is not enough. That is not full-fledged automation. So we need to add some more features in automation.
03:36
Speaker A
that's called a grouping concept and suppose I want to generate the reports and suppose I want to execute test cases parall suppose I have a few test cases and I want to execute them parallely instead of running one after another I want to execute parallely and also at the same time I
03:53
Speaker A
For example, I have 10 test cases, and based on priority, I want to execute them. What test cases I want to execute, based on the order I want to execute. Sometimes, we create different groups of test cases, like sanity test cases, regression test cases, UI test cases, like that. Whichever group of tests I want to execute, I should be able to execute. That's called the grouping concept.
04:11
Speaker A
last class Excel sheet is not supported in s web driver so what we have done we have added external third party Library Apache POI then we are able to overcome that challenge similarly to achieve all other features in automation we will integrate test NG so test NG is a a two tool a framework a
04:31
Speaker A
Suppose I want to generate reports, and suppose I want to execute test cases in parallel. Suppose I have a few test cases, and I want to execute them parallelly instead of running one after another. I want to execute parallelly, and also at the same time, I want to execute on multiple browsers so that I can reduce a lot of time. These are all possible only through TestNG.
04:51
Speaker A
the advantages or some of the features and which we are going to discuss in the multiple sections in the coming sessions so first first thing we can manage test cases and test suits using test NG and we can achieve the grouping grouping of test cases we can do like we can divide our test
05:09
Speaker A
Because Selenium WebDriver will just automate the web application, but beyond that, it cannot do anything. We need to integrate some third-party tools. Like in the last class, Excel sheet is not supported in Selenium WebDriver, so what we have done is we have added an external third-party library, Apache POI, then we were able to overcome that challenge.
05:21
Speaker A
have to execute at the first second level third level fourth level like this we can prioritize parameterization is also possible suppose at the run time I want to pass parameters to the test case for example I Creed one test case I want to execute in the Chrome browser or I want to
05:37
Speaker A
Similarly, to achieve all other features in automation, we will integrate TestNG. So TestNG is a tool, a framework, a built-in framework, we can simply say. If you integrate TestNG in automation, we can use many more features from TestNG.
05:52
Speaker A
parameterization concept and parallel testing so we can run our test cases on multiple browsers parall that is also possible and Report generation is the most important thing so test nges provided their own reports buil-in reports but they are not much attractive so we will also create another
06:11
Speaker A
Okay, so what are the advantages? What are the benefits you will get when you install TestNG? Using TestNG, we can do a lot of things. Here I provided some of the advantages or some of the features which we are going to discuss in multiple sections in the coming sessions.
06:27
Speaker A
features one by one okay so from today we're going to see one by one the coming sessions uh fourth one is a parameterization parameterization is nothing but we can pass parameters to the test case at the run time okay so for example I have created one test case and on which browser you
06:48
Speaker A
So first thing, we can manage test cases and test suites using TestNG. We can achieve grouping of test cases. We can divide our test cases into multiple groups, and whichever group you want to execute or whenever you want, you can execute.
07:05
Speaker A
can pass at the run time like application URL version number browser these are all things are environment details on which operating system we want to execute so all these things we can pass through XML F there is a parameter that's called parameterization concept okay so we'll
07:21
Speaker A
We can prioritize a test. Suppose I have 10 or 20 tests, and what test cases I have to execute at the first, second, third, fourth level, like this, we can prioritize.
07:39
Speaker A
cases are totally different so far how we have written the test cases just we created one class and which contains a main method inside the main method we put everything and then we have run the test case in the Java as a Java application okay actually that is not the way to create and
07:56
Speaker A
Parameterization is also possible. Suppose at runtime, I want to pass parameters to the test case. For example, I created one test case, and I want to execute it in the Chrome browser, or I want to execute in the Edge browser, or I want to execute in the Firefox browser. So the browser name I will pass at runtime, and accordingly, my test case should execute on the particular browser.
08:14
Speaker A
write the test cases in test style okay and this is the approach we are going to follow even in the projects also and so far whatever we learn that is just for learning purpose because as a beginner we will start with the creating a Java class Main method and create all the script in
08:31
Speaker A
We can also pass some test data at runtime. That's called the parameterization concept.
08:44
Speaker A
step so before that we will start installing the test NG how we can install test NG on your eclipse is the first thing test NG configuration we don't need to install any third party external J file or anything so we can easily install the test NG within your Eclipse I'll show you test NG
09:07
Speaker A
Parallel testing: we can run our test cases on multiple browsers in parallel. That is also possible.
09:34
Speaker A
plugin in our eclipse from the marketplace that is a very popular one second thing is we can add test dependency in form. examl okay so better to have both because sometimes when you run your test cases outside of the eclipse uh then you may face some errors so better to add dependency
09:54
Speaker A
Report generation is the most important thing. TestNG provides their own built-in reports, but they are not very attractive. So we will also create another type of report called Extent Reports, which are very popular with Selenium automation. We will also discuss those types of reports in the coming sessions.
10:06
Speaker A
provide a small documentation also just four to five screenshots are there by seeing the screenshot you can install it so now let me show you how we can install So currently this is the project which we created and all the test cases we have created like this on top of this project
10:21
Speaker A
So these are the main features which we get from TestNG. Once you integrate TestNG with your automation, we can use all those features one by one.
10:35
Speaker A
installing you can cross check whether the test is already installed or not so how we can check it just go to window and then preferences if you go to window and preferences here in this particular list uh you should able to see test NG if you already installed earlier you can see test
10:54
Speaker A
Okay, so from today, we're going to see one by one in the coming sessions. Fourth one is parameterization. Parameterization is nothing but we can pass parameters to the test case at runtime.
11:14
Speaker A
to install it to install test engine first of all we need to go to help menu if you want to install any third part extensions or plugins anything we can do only through Eclipse Marketplace so just go to Eclipse Marketplace so what is this Clips Marketplace suppose for example on your mobile
11:33
Speaker A
Okay, for example, I have created one test case, and on which browser you want to execute? Let's say I want to execute on Chrome browser. So that is a parameter I can pass at runtime.
11:55
Speaker A
is also having their own Eclipse Marketplace and if you want to add any external plugins or third party plugins we can install through Eclipse marketplace now can simply click on Eclipse Marketplace and this will open a window like this so once the window is open we need to search for
12:14
Speaker A
Similarly, suppose I want to execute on a particular application. I want to execute my test case on a particular application, and that application-related information we can pass at runtime, like application URL, version number, browser. These are all environment details.
12:30
Speaker A
have to install so you can see one button called install just click on install so once you click on install it is started installing the latest version by default it will take latest version so it is installing latest version of testing it will take few seconds so let it complete the
12:49
Speaker A
On which operating system we want to execute, so all these things we can pass through XML file. There is a parameter. That's called the parameterization concept.
13:10
Speaker A
of license agreement and here you need to accept the terms and license agreement the first radio button you can select and then click on finish so once you click on finish it will take a few seconds few more seconds and in the bottom right corner you can see installing software 60 16%
13:30
Speaker A
Okay, so we'll discuss that in detail in the coming sessions. You will understand this fine.
14:07
Speaker A
will show you one more window like this so in this uh we need to select all of them so if you already install you can continue with this you don't need to install anything new okay so now we got this window so in this window what you need to do is uh you need to select all
14:29
Speaker A
So these are the main topics which we are going to discuss in TestNG in the next five to six sessions. We will spend a good amount of time in TestNG itself.
14:45
Speaker A
related stuff and simply click on press selected press selected so once you click on again it will proceed installation and one more time it will show you another window in this also you need to select all the check boxes like this individually or else you can click on select all one more time
15:06
Speaker A
From now onwards, the way of writing the test cases is totally different. So far, how we have written the test cases, we just created one class which contains a main method. Inside the main method, we put everything, and then we have run the test case as a Java application.
15:26
Speaker A
to apply software update so we need to restart Eclipse just by clicking on restart button that's it so once you restart it is restarted my eclipse and then test Eng will be ready so it is starting my Eclipse yeah now it is started restarted my eclipse and this is my project everything
15:48
Speaker A
Okay, actually, that is not the way to create and run the test case. Normally, developers do like that; they just implement the code or develop the code in the main method and then execute as a Java application.
16:05
Speaker A
option so previously it was not there but once you have installed testng you will able to see this testng plugin inside your Eclipse preferences so this is a way we can install test NG okay so I will give you the clear document also and if you forgot to do it you can repeat this video or else
16:26
Speaker A
But from now onwards, the way of writing the test case style will be different. Okay, so we are going to write the test cases in test style.
16:44
Speaker A
this is a small document I will share later we can install if you or not all right so it is same process in the Mac also in the Mac also we have a Marketplace Eclipse Marketplace go there find out test in option and proceed with with the installation same process no change at all
17:03
Speaker A
Okay, and this is the approach we are going to follow.
17:25
Speaker A
but in the in Eclipse there are many projects we can create right but currently this is a a project which is still not configured with the testng testng just we have installed it but we need to add the testng library to the current project so then only we can use all testng features
17:45
Speaker A
okay so in the Mac I will show you later if you could not find that option at the end of the session let me know I will show you that okay all right so uh this is the project and we
17:59
Speaker A
have installed test NG option but the test NG is available in Eclipse but still that is not configured with this current project so now we need to add test library to this project so we just added test Library which is already there in our Eclipse now but this project is still
18:17
Speaker A
not configured with tting so we need to add that library to this particular project so how we can add currently this project is configured with the Mayan and along with the Java it is there JRE and Mayan is there but now we need to add testng additionally so how we can add test NG to
18:34
Speaker A
this project is simply right click on the project and uh go to properties just as usual go to right click properties and here go to Java build path same process here earlier we have added all the Java libraries and everything so in this Library section you can just click on ADD library because
18:57
Speaker A
test NG is also Library so click on ADD library in this list you can find testng option select the test NG simply click on the next and then finish so along with the J Java Mayan you can also the see third Library called test NG Library so previously our project is associated with the
19:17
Speaker A
JRE which is your Java and then Mayan dependencies now additionally we have added test NG Library so once you added click on apply and close so now we can see along with the JRE you can also see test
19:32
Speaker A
option here so like this we can add a new library to this current project so I'll show you one more time just listen right click on the project go to properties and here you can find Java build path option and there are multiple tabs here go to libraries tab previously it was not there I'm
19:53
Speaker A
again I'm removing So currently you are having this kind of thing along with the Jr May one dependencies you need to click on ADD library and select the test NG click on the next and finish okay so once you added test NG then apply and close that's it so once you have done it you
20:14
Speaker A
can see the test option which is available under the project so this is how we can configure your project with test okay so this is the one approach we have to install test Ng and then we added test
20:30
Speaker A
NG to this particular project and another way is we can simply add dependency in p. XM so can just go to pal. XML and we will find the test engine dependency in Mayan repository go to mvn repository MN repository search for testng so once search for testng you can find test NG here click
20:55
Speaker A
on this and 7101 is the latest version click on it copy the dis dependency go back to your pet XML just add here along with other dependencies just add another dependency so this is how we can just add one more dependency in test change now save it this is another way okay so installation of test
21:20
Speaker A
CH plugin is mandatory we have to install it that we cannot skip it but associating testng with your project how we have Associated by just adding the library that is one approach and the second one is you can add dependency okay so adding library to the current project or adding dependency to
21:41
Speaker A
the current project so either way we can do it either that one or this one both are correct but before doing these two you have to install test NG through Marketplace we have installed that is mandatory step but after that how we can configure your project with the testng either by adding
21:59
Speaker A
testng library or by adding testng dependency so you can do either one and better to have both the things because sometimes what happens is tomorrow if you want to run this entire project outside of the eclipse so this Library may not work so in that case the dependency whatever we have added
22:19
Speaker A
this will work so better to have both okay so this is how we need to configure our project with test Ng okay so first way is sufficient you can just add library to the current project that is enough
22:34
Speaker A
so you can just right click on the project go to properties Java build path go to libraries then add library and select T Change option here click on the next and finish that's it so test is added so this is enough for now okay so adding dependency is optional if you want to add the test
22:52
Speaker A
dependency you can add it or else optional okay so so far everything is clear everyone can you do it installation and configuration of test NG everyone please confirm in the chart box is it clear how to install test on top of uh existing project first we have to install through Marketplace then we
23:14
Speaker A
have Associated testng library to the current project so from now onwards we can create our test cases in testng style and also we can use all test NG features in our current project okay we can use all test related features in our current project right so now let us discuss some about
23:37
Speaker A
test engine so we have done configuration and one more important so far uh whatever okay let me put these two points install testng in Eclipse using Marketplace adding test libr to the build path and we added dependence in P so either go with this one or this one but before before doing these
23:59
Speaker A
two we need to install test NG plugin okay so now how we can write the test cases in test NG style so from now onwards we are going to write test cases in different way so normally previously how we have done we have created the class inside this we have a main method and we have written all
24:18
Speaker A
the code and execution is happen because the main method is present inside the class we're able to execute the class and also we know if you do not have a main method in the class we cannot execute the class CL as per Java if you have only main method in the class then only we can execute
24:33
Speaker A
the class if you do not have a main method in the class we cannot execute the class that we already know that previously but in test NG also we will create a class but it doesn't have a main method
24:46
Speaker A
in test NG also we will create a class but we do not have a main method instead of that we have to use something called at theate test annotation we have something called annotations I'll discuss all the points slowly you will understand in multiple sessions in one session itself is not possible to
25:05
Speaker A
explain each and everything but slowly you will understand so whatever I'm explaining now so just stick to that don't go beyond that so at theate test annotation is one of The annotation which is available in test NG so we can simply say it is a replacement of main method so if you create a
25:22
Speaker A
normal class we should have a main method until unless the main method we cannot execute but in test Ng we do not use main method so from now onwards we do not see the main method in the class so instead of that we will create a test methods in the class and every method is created
25:43
Speaker A
with at theate test annotation okay so I will show you how we can do this at theate test is basically called as annotation this is a test NG terminology remember this there are multiple annotations are there but atate test is one of the most important annotation and another type of annotations I will
26:02
Speaker A
discuss in the coming sessions but initially we will start with the test annotation okay now let us see how we can create a test case in test NG styling basic test I'm going to take so let's go to eclipse and let's create a new package for today just everything is same process only thing
26:22
Speaker A
is we will create a test case in different style so I'm creating a new package and today is day 42 now in this I'm going to create a new test case just like a normal class we will create if I
26:38
Speaker A
create a normal class can just put the class name here so this is my first test case everything is normal test case my first test case so provide the class name and should not take this main method should not select any any main method and simply say finish so once you created it is just created
27:05
Speaker A
a simple class normal class it doesn't have any main method now in this we have to write a test case so let us say I have a small test case here I'm not writing the code and everything I'm just
27:16
Speaker A
going to show you how exactly we have to write the test case and how exactly we have to execute it so for example I have a small test case like this only three steps first I need to log into
27:27
Speaker A
application log to my application or we can first open our application and second step I need to log to my application third step is I want to log up from application three steps okay now first I will open application we can consider as one test login is another test after successfully
27:47
Speaker A
login I will log out from application we can consider that is another test now have a three steps and three steps are there open application login and log now we need to automate this using test Eng style so how we can do this first we will create a normal class and in this for every step
28:08
Speaker A
we will create a method okay so normally you have only three steps here but once you converted this into automation we have to write many steps for opening application at least we have to write two steps for login at least we have to write three steps for log out we have to write one
28:25
Speaker A
step so sometimes you may have only one step some sometimes you have to write multiple statements for one step right so now we need to understand the test case and accordingly we have to divide this into multiple methods so for example here I'm writing a method void okay let's say uh open app
28:48
Speaker A
this is one method I'm going to create and this is responsible for what opening the application now another method I will create void login and this method is responsible for what log application and then I'll create one more method called void log out and this is the responsible for log out from
29:11
Speaker A
application like it doesn't mean like each and every step we have to create one method no depends upon the complexity of the step okay so open app and log out I have created separate methods and login is an actual test method where you want to do validations so whatever steps we have in
29:29
Speaker A
the test case we will divide that into multiple methods that's the first now every method is wi these methods won't return return anything test engine methods won't return return anything so now these are the methods we created for these three steps so whatever automation code you want
29:48
Speaker A
to write you can keep them inside this method so for now I'm not writing any web driver code in the next example I will show you how we can write the web driver code for now I'm just writing
29:58
Speaker A
a simple method print statement let's say here this is let's say I can simply write opening application and here I'll Implement login steps and here I simply I'm writing log to application and in the log out you need to implement the log out code but here I'm writing
30:27
Speaker A
simply log out from application right so we need to implement this method by writing web driver code so in the last classes how we have written system. set property like web driver driver equal to Chrome driver so how we have created how we have interacted with web elements the process
30:46
Speaker A
is everything is same here instead of writing everything in one shot we will def divide them into multiple methods and these methods are implemented using web driver concept for now I'm just putting print statements okay so this is the first step so as soon as I have done this
31:05
Speaker A
still you cannot execute this class why because we haven't put main method and also we haven't used at theate test annotation right so if you try to run this as you won't see anything option here you don't see any run options previously we were getting run as a Java application okay but
31:25
Speaker A
this time we won't get anything so what we need to do is is in test NG every method we Define with the sum annotation here I will specify at the rate test so before writing the method you need to specify something called at the rate test annotation and then only the test NG will try to
31:46
Speaker A
execute this method otherwise it cannot execute directly same thing we do for other Methods at theate test annotation we have to keep in every method and when you keep this method we have to import this test annotation from test NG you can just save this and we have to import this when you
32:04
Speaker A
put the cursor on this it will show you different packages you need to import this from org. test.
32:12
Speaker A
annotations this is the package which we need to import okay now we have imported so as soon as you imported you'll get some more options here this run and dbug is a links actually test atate test is annotation below that it will by default added few links run and debug later we will see
32:31
Speaker A
so every test method we defined with at theate test annotation now if you look at here run as you can see one new Option called test NG test so earlier we haven't get this option why because we haven't specified the test annotation for the methods so now we are able to run this test
32:51
Speaker A
you can say test NG test option we have to use so from a now onwards you don't get as a Java application we have to run the test as a test test so now let me run this so once you run it
33:05
Speaker A
so you can see my test is got executed now in the console window we can see some output okay just okay so this is a console output yeah you can see this so you can see different type of outputs this is first console output
33:37
Speaker A
you can see these are the print messages we got it from the methods and by default test NG will pass every test method by default because we haven't still added any validation points so by default test is executed all the methods successfully executed so it is getting passed
33:53
Speaker A
and here you can see how many tests we have run how many failures how many skips it will show you and you can see three we have run three passes no failures no skips so this is called console
34:04
Speaker A
output and apart from this if you go back to the second tab here results of running class first test case here you can see these are the test methods we have executed all of them are got passed by default so in the two different ways we can see the output either in console
34:21
Speaker A
output second one is in hierarchy mode we can see the output here this is another view of output okay now let me close this so this is the way we have to create your test case test NG style
34:36
Speaker A
so now let me show you few important points listen very carefully because these are the fundamentals if you understand this coming sessions will be very very easy for you so I have created these three steps first open a application login and log out I created these three methods and added
34:53
Speaker A
test annotation if you do not add test annotations you cannot execute the class we have to add test anotation so we haven't put any main method okay now just observe the output I'm running one more time run as test NG test okay now go to console window and these are the three statements we
35:13
Speaker A
got from the print statements and these are the output so by seeing the output have you noticed anything did You observe something in this output we have created your test executed and we got some output in the output did you notice something any mismatch or any Gap did we did we just
35:35
Speaker A
observe here yes order of execution see in which order I have created this method first open app then I have to log in then I have to log out but in which order they have executed first it is executed login log out and then opening application is it the right way to execute the
35:55
Speaker A
test no if you really write your web driver code in these methods definitely they will fail right but why because without opening application it is trying to log in and log out is it possible no your test case definitely will fail if you create a web driver code so how it is executed actually
36:18
Speaker A
in which manner it is executed we have created all these methods in the proper way first method is open up second method is loging thirdd method is log out so the writing the methods are properly in sequence but test is executed these methods in alphabetical order test is executed these methods
36:38
Speaker A
in alphabetical order means by using this name of the method it will check which letter comes first so if you consider the W and l l comes first again in these two login is executed first and log out
36:52
Speaker A
executed and then opening application is executed that means test NG will execute the test methods in alphabetical order by default it will execute test cases in alphabetical order that is the first point test NG execute the test methods in alphabetical order I'll discuss more points here
37:17
Speaker A
listen this that the first point test NG execute the test methods based on alphabetical order now so if the test is executed in alphabetical order it won't work for me right it won't work for us because first we need to open application then only the login screen will appear then I can
37:38
Speaker A
login after successfully login then I can get the log out button so the we must follow the sequence if it is executed in alphabetical order no use for us right but how we can control the order of execution so that we can do by using priority we should add some option in the test annotation
38:01
Speaker A
that is called priority option so let me show you in the test we need to add one parameter in the bracket this is all syntax okay you need to follow the same thing at theate test in the bracket we use one keyword called priority equal to one means I want to execute this method first
38:21
Speaker A
and in the test login I want to execute this a second method so priority two I'm giving and then log out I want to execute after the login so then I can say priority equal to three so by adding the
38:38
Speaker A
priority option in every test annotation we can control the execution order now execute one more time yes so now you can see the console window now you got exactly same order first opening application then login and then log out okay and this order will be different so this we don't need
39:01
Speaker A
to consider this is a test NG just randomly giving the P or failed messages we have to consider this one and also if you look at the tree structure first open up executed then login executed then log out is executed so two points we have to understand first point by default test NG will
39:19
Speaker A
execute all the test methods in alphabetical order and if you want to control the order of execu we need to add one parameter called priority at theate test annotation priority we should give some number which will controls the order of execution which
39:41
Speaker A
will controls the order of execution this is the second point now we'll discuss a few more points okay suppose we provided the priority to the test methods so once you provided the priority based on the priority only the test methods will be executed based on the priority
40:10
Speaker A
the test methods will be executed it will not consider the alphabetical order so third point is once you provide the priority to the test methods then order of methods is not considered that means what very important point so I have provided the priority now what I will do is is I will write
40:29
Speaker A
these methods in the different order so I will put this log out in the first place okay I will put this open app in the last place can we change like this yes so once you provide the priority to the
40:46
Speaker A
every test method and these methods we can write in whichever order you want because the order will not be considered okay so in initial step all methods are executed in alphab iCal order then we have added priority then test methods are executed based on the priority so now what I have done
41:05
Speaker A
is I have changed the place of method so I have interchanged the location of these methods first I put log out then I put login then I put open up so even though you change the order of these
41:18
Speaker A
methods still it will consider the priority only So based on the priority only the test methods will execute even though if you change the order of these methods so that is the third point so once you provide the priority to the test methods then order of methods is not considered that means
41:38
Speaker A
in whichever order you created you can do that so you can randomly create a method first I will create a login then I create a open up then log out still it is fine so first I created log out
41:51
Speaker A
then log in and open up still it is fine so you can create this method whichever order you want because the priority will consider at the run time based on the priority only the methods will execute so that is a third point so once you provided priority to the methods then order
42:10
Speaker A
of methods is not not consider order of methods in the sense the way of the writing the methods in whichever order you have written the methods that order will not be considered that is the third Point next Point priorities numbers can be anything so first let me execute run as test test
42:32
Speaker A
see even though I have changed the order of the method still it is executed based on the priority only that is the third point now come to the next Point priority numbers can be anything no need to provide consecutive numbers let's say I provided 1 2 3 right you can provide 5 10 20 you can provide
42:54
Speaker A
50 100 100 200 so some random numbers also you can provide there no need to be have a consecutive number sequential numbers are not needed so for example here I'll say 10 okay here I can say 50 random numbers you can give and here I can say 200 so whatever number you want you can give it
43:15
Speaker A
but how it will consider execution whichever number comes first or whichever number is the lowest number that method will execute first and after 10 which one is higher 50 is higher so then login method will execute next after 50 200 is a higher one so the log out method will execute
43:34
Speaker A
next or we can make it as 100 so 100 method will execute first so even if you executed this all methods are successfully executed in whichever order you want so the order number the priority numbers no need to be sequential no need to be consecutive numbers consecutive number means one
43:56
Speaker A
after another one after after two two after three three after four no need you can give some random numbers also as a priority that's a fourth point so priorities can be random numbers no need to follow the consecutive numbers so interview prospective these are all very
44:15
Speaker A
very important points you'll get more questions during interview so remember each and every Point priorities can be random numbers so no need to have a consecutive numbers you can put any numbers suppose if you do not provide any priority so for example for open app I'm removing the priority I
44:37
Speaker A
don't put any priority so then what is the default priority of this method can anyone guess what is the default priority of the test method yeah the priority order you have to decide based on the test case steps see what in how you have created your test case T same thing reflect
45:01
Speaker A
here okay if you do not specify the priority to the test what is the default priority it will capture zero as a default priority zero it will consider as a zero okay suppose I say here I haven't put anything and login I will put one let's say login I will put One login I will
45:21
Speaker A
put two priority and open app I have not given any priority by default if I don't specify any priority to this method it will consider as a zero let's ex let's execute and see because it's a zero that should execute first right go to the console now we can see open application is executed so we
45:42
Speaker A
have not provided any priority to this but still it is executed first why because the default priority of this method is what zero so the default priority of test method is z Z or if you do not provide any priority if you do not provide priority then the default value is
46:07
Speaker A
zero okay suppose if two methods are having same priority then what will happen see this is a zero okay let's give priority is equal to one this is one and this is two and this is also I will give to login I will give to log out also I will give to then what will
46:33
Speaker A
happen if I give same priority to multiple methods then what will happen so according to the priority which one will execute first open app will execute first and then second level these two methods come into picture because both are having same priority so in those cases it will
46:57
Speaker A
again consider alphabetical order okay if the priority of these two methods are same then these methods will be executed in alphabetical order so let me execute again so the first priority open up is got executed then login and log out is got executed so after
47:17
Speaker A
login after that log out will come so login and log out is executed in alphabetical order so if the priority is the same those methods again will be exec Ed in alphabetical order that is a sixth point if the priorities are the same then again execute methods in alphabetical order
47:42
Speaker A
okay this is another point now suppose I don't put okay so I just I don't want to put uh okay another option suppose can we provide negative numbers in priority can we provide negative numbers in the priority can anyone guess negative
48:05
Speaker A
numbers so we can also provide negative numbers in priorities we can also provide negative numbers in priority okay for example here I'm writing some numbers now you tell me which one first which one last so zero is a middle number after that 1 2 3 4 5 will start right so before that
48:27
Speaker A
I can say min-1 -2 -3 -4 and -1 so this is a range of numbers right so now just observe for open up application I'm giving minus one as a priority for login I will give you zero as a priority for
48:49
Speaker A
log out I will give you one as a priority okay now tell me which order it will execute which one first will execute which method we execute first first method in three methods minus one I have given 0 also have given one is also given so which method will execute first according to this
49:10
Speaker A
particular sequence so if you look at these three numbers 0 1 and minus one which one is the lowest number which one is the lowest number minus one right after that zero comes after that one comes so minus one comes first so open up will execute and zero comes next so login will
49:32
Speaker A
execute then one comes next so then log out will execute so execute now run as test NG test so we can also provide negative numbers you can see open application is executed first then login and then log out so not only positive numbers you can also provide negative numbers to the priority
49:58
Speaker A
this is the another Point negative values also allowed in priorities negative values also allowed in priorities now the last Point seventh point now suppose I just remove this test annotation for open up I completely removed it can we execute the test can we execute this class can we execute it
50:30
Speaker A
or we'll see right click run as we are still getting test NG test option even though we removed the test annotation for this open up method still we are getting the test Eng option you can see right click run as a test engine so let's run it and see what will happen yeah now
50:55
Speaker A
I executed see in the console output only two methods are got executed login and log out is executed but open app is not executed why is it so because the open up is not associated with any annotation there is no annotation is associated with open app that is the reason test NG is not
51:18
Speaker A
executed this particular method in the run time so what we need to understand based on this test NG will execute the test methods only only if they are having annotation only if they are having test annotation test NG will execute those methods otherwise those methods will not be considered
51:38
Speaker A
by the test ngng this is the point so only two methods are having test annotation so only two methods got executed okay suppose I don't put test annotation for any of these methods so I just commented this test annotation I can make it as a priority equal to minus one so I just
52:03
Speaker A
commented this also now I have not provided test annotation for any of these methods so now what will happen can we run the class can we run it no because we don't have any method which is having test annotation right so in that case you don't even get the test test option let me save it just
52:24
Speaker A
I commented okay so now can say run as test test but you won't execute so it is giving some error what is an error so no runs nothing because all test is annotations are commented so no test found
52:42
Speaker A
nothing was run means no method is associated with the test annotation if you have a test annotation to this method we can call it as a test method so it is clearly saying no test were found so first of all you won't get this option actually run test you will not get run as option because we
53:02
Speaker A
already run multiple times so we got this option now because after commenting but initially first time when you don't put any annotations try to run you will not get this option okay so if you do not have test annotation test NG cannot execute that method test NG is always look for the test
53:22
Speaker A
annotation method in the Java program our Java is always looking for jvm is always looking for what main method should be there in the class similarly test NG is also always looking for some annotation should be associated with this method here we are added test annotation but other than test
53:43
Speaker A
annotation there are other type of annotations are there like before method after method before class after class there are multiple types of annotations are there at least one annotation should be associated with this method any type of annotation then only the test NG will execute
53:59
Speaker A
that method otherwise it cannot be executed okay so remember this point so the last point is what test NG will execute the test methods only if they're having at theate test annotation this is the point test NG will execute the test methods only if they're having test annotation otherwise
54:22
Speaker A
test NG cannot execute the test method so these are the eight points very very important you need to remember so everybody's clear please confirm in the chat box all these eight points are clear so far so very very basic stuff in the next example actually we will write the web driver code and see
54:45
Speaker A
how exactly it will work so when you're creating a test methods in the test NG when you adding the priorities and when you're adding the test annotation you need to keep remember these points right now so let me create some other example so this time we will try to
55:05
Speaker A
write a web driver script so we understood about test annotation priorities and how exactly it will work all these things right so now let's go on to the next one new class and here I'm creating one more test I say orange HRM
55:23
Speaker A
test and uh click click on the Finish okay so in test NG we can also create this uh in different way I can show you that also let me remove this one now we can create the test class in the
55:43
Speaker A
different way what you can do is you can just right click on the package okay and you can say new just a second you here you can find something called test in option so not here okay go down
56:06
Speaker A
yeah here you can see test NG option so I'll show you one more time it is not visible properly when you right click on the package and if you scroll down in this box you can see test Change option
56:17
Speaker A
in the bottom in the test CH you can see one option called create a test NG class create test NG class you can click on it so it will show you another type of window so in which package it
56:30
Speaker A
will create and here we can provide the class name so here I'm providing or HRM test this is my class name and you can see there are so many types of annotations are there so we are not going to use
56:41
Speaker A
this annotations for now in the next sessions I will discuss about this and you can leave this XML suit file all these things empty simply you can create finish now it is automatically created a new class RM test and by default it is is given one test method by default it is given one test
57:00
Speaker A
method you can see that see public void F bracket and opening bracket here we need to implement the code so by default the template it is provided so we can create one few more methods later okay now I'll try to remove this part for now so now we will create uh a test case let me take one new
57:24
Speaker A
test case in Orange applic Orange HRM application uh I'm going to create this particular test so first we need to open the application and once you open the application I want to test the logo presence or not then I will log application and then finally I'll close my application so these
57:43
Speaker A
are the steps I want to automate so we need to First identify the multiple test open application okay and then uh test logo login and close let's create four different meth methods first method wi open app this is one method and also I will add test annotation along with priority equal to one
58:12
Speaker A
and next One login logo presence or not I want to verify then I will do login so I can say void test logo okay and in this I will write implement the code later so specify test annotation priority
58:33
Speaker A
equal to 2 so once you're opening your application then I will verify the logo is displayed or not and after that login so void test login some method name and this is also I'll put test annotation of priority equal to three and after that I want to log out from application void test
59:01
Speaker A
log out so normally for login and logot we will consider them as a entry and exit criteria so we will use a different type of annotations that you can understand later but for now everything follow test annotation so test log out I I said test annotation and priority equal to
59:20
Speaker A
four right now I have just created the skeleton of all the methods according to my test case so first open application execute first then login I will execute logos second login is third log out is fourth now we will implement the web driver code so let's go to orang HRM login application
59:41
Speaker A
so this is our application which we need to launch first so this is the application which we are going to launch copy this URL now we need to write a web driver script right so in the open application what we need to do we need to launch our browser opening your URL in the browser so
59:59
Speaker A
let's create web driver driver equal to new Chrome driver new Chrome driver and then once you created this web driver let's import this web driver and after that I launch my application so driver dot get specify the URL that's it so open app method is got implemented that is the only scope of open
60:27
Speaker A
up right you just creating the driver launching your application if you want you can maximize it driver do manage. window. maximize and if you want to put implicit we you can put so driver dot manage dot timeouts dot implicitly wait duration dot of seconds set 10 that it so whatever code
60:58
Speaker A
is required for opening application we have done everything in the open app now come to the logo so as soon as you launch my page I want to verify this logo is present or not this is another test
61:10
Speaker A
now inspect this element and uh go to selector Hub and get this element image go back and now I want to verify is displayed or not so driver dot find a element see here I I'm not getting any auto sus
61:30
Speaker A
driver dot see I'm not getting anything first of all I'm not able to access the driver from this method can anyone tell me what is the reason behind that I'm not able to access the driver here here we have already created and used but in when you come to another method the same driver we have
61:48
Speaker A
to use it right but I'm not able to access it why is it so why we are not able to access the driver yeah it is not recognizing why why it is not recognizing so we already created the driver
62:05
Speaker A
in the previous method I'm trying to use same driver here it is not recognizing why it is not recognizing because we created this driver as a local object of open app method it is a local this is applicable only with this method so this driver is accessible only within this method because this
62:25
Speaker A
is a locally we created local means within this method we created local means within the method we created so this driver can be accessed only within this method if you want to access this in outside of the methods not possible but how we can access but we need this driver right so we need to
62:46
Speaker A
make this as a class level copy this and keep that variable in the class level like this and here you remove this point okay now this variable becomes a class variable so class variable we can access in every method or not yes but driver we have to create inside this method we cannot create this
63:09
Speaker A
driver outside of the method so the variable we have to create outside of the method but instantiation we have to do inside this me so now this driver becomes the common variable across all the methods because this is a instance variable or class variable or class object we can access
63:29
Speaker A
it in every method so now you can see but don't specify web driver in both the places many of people will do the same mistake they will create web driver driver here but again one more time they do web driver driver equal to so this will give you an error okay so you should not specify
63:47
Speaker A
here remember this point only one time you have to create a variable that you can refer multiple times now in the logo we will try to access driver dot now you can see you're getting all the methods find element by do XPath and here we need to pass X paath of the logo element so this is a x
64:13
Speaker A
PA and what is the method we can use is visible or not how we can verify is displayed and we can collect the status in the status variable Boolean variable and that I can print system do print and
64:33
Speaker A
Logo displayed I'm writing a simple message or if you want to put some if conditions uh you can put the condition also no problem okay so image displayed I'll print status code so later we will make it as complicated but initially we will try to understand is the big basic stuff okay so
64:56
Speaker A
now I have implemented open app and Logo now come to the login so we already launch our application right in the first method so we only thing is we need to interact with these elements so inspect this username get this element so can we access the driver
65:14
Speaker A
here in the test login yes we can still access driver. find element by dot xath dot send keys of dot send keys of admin and password driver. findind element by. xath specify the password of this element Dot send the keys of admin 1 2 3 next step we have to click on
66:02
Speaker A
the button so login button we have to click double quote is missing login so driver. findind element by. xar specify dot click done so with these three statements login is completed so after that if you want to put some validation points so you can put
66:38
Speaker A
some validation points right so now test log out so we need to log out from application or we can close your application so what is the last step close our application so you can simply make it as a close app because we already created open app so we are using close app
66:56
Speaker A
so here simply say driver. close or driver. bit command so like this we have to implement all the methods in different methods all the statements in different methods and Driver should be commonly available for all the method so we have created test methods provided
67:14
Speaker A
test annotation given the priority everything is perfect now let us execute run as test NG test so maximized entered username password and successfully executed now can see logo is displayed false it is giving okay so we'll cross check once again and uh so all
67:42
Speaker A
test methods are successfully executed based upon the priority okay but somehow this image is displayed false let's put some wait time might be it is taking time to load the page so now you understood guys how we can integrate web driver code
68:08
Speaker A
in test NG methods so that's the main important thing okay so now you can see logo displayed is so this is how we can create a test cases in test NG style so this is our test NG style now so let me show you something else in the test NG uh we
68:43
Speaker A
have run the test case directly like this right let's run as test NG test so there is another way to run our test cases suppose I have one one test case you can directly go and run like this suppose I have a group of test cases let's I have five 10 test cases I want to execute all of
69:03
Speaker A
them so implicit weight is not getting that logo actually so implicit is weight is only waiting for the element but somehow it is not getting that element so I have just added Additionally the sometimes it is needed even though if you put implicit weight okay so sometimes this will
69:20
Speaker A
not get for the element so that is the reason I just put three seconds very rare cases it is required okay now let me show you something else so if you have one single test case you can directly run like this run as run as test CH test and suppose if you have a group of test
69:47
Speaker A
cases let's say I have five test cases or 10 test cases I want to execute all of them in one shot so how we can do that so in test NG we have an option that we can execute the test cases using
70:04
Speaker A
XML file very very important can execute the test cases even single test case also you can execute through XML file execute test case using XML file so what is this XML file which is also called as a test XML file test NG XML file so throughout the test Ng XML file will play very
70:27
Speaker A
very important role very very important role means whatever features we have on discussed earlier grouping parameterization parallel testing report Generation all these things are possible only through XML file you have to run the test cases using XML file then only we will able to achieve
70:48
Speaker A
all these features so that much important is is from the beginning to end of the test NG test NG will play very very important Ro okay in today's session we will see how we can use the test NG
71:00
Speaker A
file to execute our test cases one test case and multiple test cases and not only that when you run your test cases in using XML file we will able to see tester report test enger report also we can generate through XML file so in one shot two benefits one is when you run your test case using
71:23
Speaker A
XML file we will able to run multiple test cases at one shot second is we can also see the report after execution we'll see how we can create an XML file how we can run our test cases using XML
71:42
Speaker A
file and again this XML file we can create in two different ways one is we can automatically generate by using existing options or we can create our own XML file manually okay I I'll show you it's very very simple very easy let me show you how to create how to run your test cases
72:01
Speaker A
using XML file so let me take the second test case I want to run this using XML file so we have to create our own XML file or we can automatically create an XML file so how we can do that so first
72:15
Speaker A
of all we need to select the test case and here in the test NG you have an option called convert to test NG convert to test Ng when you click on this option you can see it automatically that XML code
72:30
Speaker A
is generated and where it is generated in the suit test name suit name if you want you can change it suit name and test name you can change it and where it is generating location is in the web
72:43
Speaker A
driver project directly in the project level the XML is storing but I don't want to store in the project level I want to save this XML file inside the project day 42 simply you can just browse it and select the project go to SRC go to the test Java and select the package day 42 say okay and
73:07
Speaker A
after that simply say finish no need to go next just finish now you can see that XML file is got generated automatically this is called testng.xml file this is called test.xml file okay now it is having some errors uh you need to get this URL first so when you put this cursor on this URL it
73:31
Speaker A
is saying Force download so downloading external resources is disabled so we need to just click on this link it will solve the problem so once you click on the link then problem is got solved now you got the XML file so in this XML file you can see which class this XML is running I will
73:50
Speaker A
explain other options also but the main XML is from here this is the part we need to understand and first two statements these are all common it will says like XML version document type and everything these two steps are mandatory for every XML and these are the tags which we
74:06
Speaker A
need to understand okay so before understanding this XML let me run this XML file first how to run this XML file can run as you can see test enges suit so previously what is an option we got test NG test because we are running only one single test but but through XML we can run
74:27
Speaker A
single test or multiple test or group of test so normally the group of test is called test suit right so that's the reason we are getting test suit option so when I click on the test suit our test NG XML file is executed our test case see our testng.xml file is executing our test case
74:49
Speaker A
see in the console output we got some output here and if you go back to the results of running suit all four methods are successfully executed so our XML file is executed our test case now where we can see the test engine report here we see console output here we can see hierarchy
75:10
Speaker A
mode but where is the report so you need to just refresh the project once and go to test Ty output so this is a new folder you will get once you run test using XML file you will get
75:25
Speaker A
this folder newly and sometimes you may not see this folder you need to refresh your file refresh your project once so once you refreshed then you can see this test Typhon output right if you expand this test Typhon output you can see so many files in this again two files are important
75:45
Speaker A
one is emailable report second one is index.html okay first of all let me open emailable report so right click on this HTML open with system editor now this is a test engine report see this is a test four got executed four are pass no scripts no return no fil nothing how much time it is taken it
76:10
Speaker A
will show you and green color is representing past so everything is got passed suppose if anything is got failed it will come in the red color and along with the failure messages exceptions everything will display in this report this is very very basic report of test NG test Ng report
76:26
Speaker A
and this is emailable report there is another report will be generated we go back to Eclipse index.html you open this one open with system editor this is index. HTML if you look at this report uh this is the XML file we have executed and uh four methods are executed four are passed
76:53
Speaker A
if you click on this show it will show you water R methods are executed and passed if it is a failure that also it will report here in the red color marks and if you click on this chronological view this will show you in which order the test methods are got executed and how
77:10
Speaker A
many milliseconds it takes each method execution it will also show you so some more options are showing here so this is these are these two are the test engine reports one is emailable report the other one is index.html so these reports will be created only when you run your test cases
77:31
Speaker A
through XML file okay now let us try to understand few things about this XML file very very simple very very easy so how to create this XML file I will show you simple way of creating your own XML
77:46
Speaker A
we can also create our own XML file but you need to know the tags which is most important so that XML file will start with the so to tag tag this a higher uh the root parent tag and the soo tag
78:01
Speaker A
is having some attribute called name and this name you can change if you want you can you can change like my suit or whatever you want you can put in the suit test suit contains the number of tests so this is the test tag and every test tag is also having name attribute and thread
78:19
Speaker A
count is optional so this we can use when you do parallel testing so for now I can remove this right so to tag is having a name attribute test is also having name attribute inside the test we have another tag called classes closing and ending tag inside the classes we have actual class tag
78:38
Speaker A
here we have to specify name attribute that is package name do your class and uh this class tag is already closed here this classes tag is closed here test tag is closed here suit tag is closed here so this is the same temp template we have to use to write an XML file so we can create our own
79:00
Speaker A
XML file if you know these templates very very easy so now when I execute it this will execute your test case this is a simple way of creating your own XML file I will show you how to create
79:13
Speaker A
our own XML file this is autogenerated XML file let me close it we will create our own XML file so again go back to the same package this time I will create my own XML file I already shown
79:25
Speaker A
you how to create automated XML file how we can create automated XML file right click on the test here go to test NG and convert to test NG so just location you can browse and click on finish XML
79:41
Speaker A
file will be generated now if you want to create our own XML file then how we can create and also in XML file I can run multiple test cases here only one test I mentioned I can add more tests
79:53
Speaker A
so how we can do that let let me show you so to create your own XML file very simple where you want to create package day 42 so I'm just right click on on it here go to the new select
80:08
Speaker A
the file and here give the file name so here I'm giving my file. XML so my file. XML this is my own XML file I'm going to create click on finish now it is empty nothing is there in this so first
80:28
Speaker A
two lines you need to copy these somewhere and paste it over here first two lines you can have somewhere you can paste it here now from this we need to create our own tags so what is the first
80:41
Speaker A
tag suit it will automatically come here suit and the name attribute we have to specify here we can put any name I can call it as a my suit opening and tag and closing tag opening tag and closing tag I say press enter it will go to the next line now inside the suit what's the next tag
81:02
Speaker A
is test tag so test is having name attribute so name equal to I say my test and close this opening and and closing tag so inside the test tag we have a classes tag inside the test tag we have a classes tag inside the classes classes tag doesn't have any attributes
81:25
Speaker A
but inside this we have a class this is having attribute class name equal to we have to specify from which package we want to execute the test day 42 so here you can say day 42 package name must be
81:39
Speaker A
specified Dot and what is the name of the test orange HRM test orange HRM test and close this tag that's it so this is we can create our own XML suppose I want to add a few more test let's
81:59
Speaker A
say um first test case that also I want to add so you can just copy this entry one more take one more entry and just add that also so group of test cases also we can execute so here I'll say first
82:13
Speaker A
test case that's it so now this XML will able to run two test cases as a group let me execute now run as see as soon as you save it if you don't save this you will not get the Run option okay
82:30
Speaker A
you need to carefully save it I'll tell you if I if you are able to create automatically why we have to create manually so very good question I will clarify that so let me execute this first so I'm able to run test so this my first test is running and then
82:55
Speaker A
after that it will go to the next Des case now if you look at the output so two classes have run right now go to the console window totally four it giving so you see the results of running so still it is executing only four uh something is wrong uh first test case is
83:13
Speaker A
correct on sorry sorry yeah both are there in the day 42 okay let me run one more time so test enged XML should able to execute both the glasses okay let's run one more time yes we are running multiple test cases in one
83:35
Speaker A
shot still not executed let me do some change you should be Pi both the test cases in the first test case I yeah sorry so we commented all the test annotations right so that's the reason it is not executed anything so let me
84:04
Speaker A
remove this okay now go back and execute the XML file one more time so make sure when you're writing your XML file save this so then you will get this option run as test in so in XML file in whichever order we mentioned all the tests it will follow the same order so now
84:31
Speaker A
you can see all sevens are executed we go back to this here you will know that first orange HRM test is got executed all four methods are got executed then first test case three methods are executed so we'll see the report so refresh test Typhon output folder once you refresh
84:48
Speaker A
you need to refresh every time otherwise it will not be updated so go to index.html open with system editor now we can see from first test case these three methods got executed from Orange HRM test four methods got executed and this is the XML file which we have executed and
85:10
Speaker A
chronological view if I click see this is the order first these four are executed then first T is called executed so this is one type of report and this is emailable report see this is the first test case this is RRM test so everything is got executed successfully so
85:30
Speaker A
this is how we can simply execute group of test using one single H XML file so the XML file we can automatically generate or we can create our own XML file okay sometimes suppose I'm able to create XML file all the tags and everything it is able to identify okay by
85:52
Speaker A
because I already installed XML plugin so if you want to install XML plug-in then it is able to rec go to Marketplace and in the search box you can just search for XML just type XML uh editor because if you install this everything will XML files can easily
86:18
Speaker A
recognize okay so you can install any uh XML editors see first of all whether you're able to identify the XML or not then you try this XML okay I think yeah this is the one Eclipse XML editors and tools eclipse XML editors and
86:55
Speaker A
tools you can just try to install it and you will able to recognize XML but before installing just try if you're not able to recognize all the tags and everything so then you can install otherwise no need okay so what is an XML file is basically is XML file is also called as a suit test to suit
87:14
Speaker A
what is a test suit normally uh if you look at normal test cases we have what test suit is what first main thing what is a test suit Su contains what is the test suit contains the manual testing what is the test suit means group of test cases is called test suit so test suit
87:36
Speaker A
contains what multiple test cases multiple test cases and what is the test case means what is a test case contains test case contains a test steps right the group of steps is called one test case same hierarchy we follow in test NG so test suit is nothing but what XML file XML file is
88:01
Speaker A
considered as a test suit so what is a test case means classes so whatever classes we created here each class is consider as one test case now what is the test case contains test case contains the test steps so these test steps we will Implement in test methods test test method so this is the
88:26
Speaker A
correlation test methods okay now you can map it so normally we have a test suit which contains a group of test cases each test case again contains a test steps now if you come to the test NG test
88:39
Speaker A
suit is nothing but an XML file so that we can run all the classes all the test cases through XML file and class contains a test method so in the test methods we will Implement all the test methods so this is a hierarchy so XML is also called as a XML suit we can run one single test
88:59
Speaker A
case or we can run group of test cases using XML file okay now two advantages we have seen using XML file one is we can execute group of test cases and second is once you executed through XML file we able to see the reports under test Typhon output so in the test NG we don't need to write a
89:20
Speaker A
separate code for reporting so it is automatically generated it's a built-in mechanism which we have in test NG the only thing is we have to make sure the test cases are executed only through test NG that's it okay now if you are able to create XML file automatically why we should generated
89:41
Speaker A
why we should Al so if you automatically we able to generate why we need to create manually means suppose when you create your XML file template by default you will get only the basic tax let's say only suit test classes and test is CL suit is only the basic tags you will get
90:01
Speaker A
but later on we will we need to add so many other tags like grouping listener parameters there are n number of tags are there so we need to add them so whatever features we understood before as I told you in the test NG we can do so many features we can achieve right grouping
90:21
Speaker A
parameterization parallel testing so so to achieve these features we need to add some more additional tags in XML file okay some more additional tags we need to add and that is possible only through manually but when you create an XML file only the default structure will be created the basic
90:42
Speaker A
suit test classes will be there but apart from this if you want to add some additional TXS that is possible only through manual process but initial XML file we can create automatically and then we can add some additional tags grouping parallel parameterization so the different tags
91:01
Speaker A
are there so in the coming sessions I will introduce you other tags but this is the basic XML file will be generated right so if you want to additionally add some more TX we can add manually we cannot generate them automatically so that is a reason the second approach will be useful
91:21
Speaker A
so we can create XML file manual the basic structure you can automatically generate but on top of this if you want to add any additional tag so we should add them manually so we have to know the tag names which is very very important and very easy to remember also suit opening and
91:39
Speaker A
closing tag suit contains a test test contains a classes classes contains a class very easy to remember same structure we follow for every type of XML file all XML files in test NG only thing is we will just add some additional TXS that's it otherwise everything is same okay so we can
91:59
Speaker A
create our own XML file we can also automatically generate our own XML file okay so through XML file what we have done two things we have achieved two things we have achieved through XML file so what is the first thing executed group of test actually the grouping concept is different so sanity group
92:28
Speaker A
regression group you have to make all the test cases the different groups then we can execute those groups separately that's a different concept so we should not call it is a grouping actually we can call it as executing the test cases as a test suit one suit executed group of test
92:44
Speaker A
cases as a one suit and the second is we can generate we generated the report we can generate TNG reports and these reports are default so we no need to write any additional code for generating the reports when you run test cases using XML file reports will be automatically
93:12
Speaker A
created inside the test Typhon for output and we need to refresh the project after execution then only you will see these files otherwise you cannot okay okay so this is a basic understanding what is an what is test NG what are the advantages how to configure how to create a basic test case in test
93:36
Speaker A
NG and how can we execute how can we execute of different test testing smoke sanity that is part of the grouping I already told you that grouping concept we will discuss in the coming sessions so this is not the grouping we just executed the multiple test cases in a suit but this is
93:58
Speaker A
not actual grouping okay we will do grouping part separately once you separate all the test if you have multiple test cases then we can achieve the grouping concept so in the coming sessions we will discuss that concept just stick to the concept whatever we discussed today don't go beyond that
94:15
Speaker A
if you have any queries related to this one you can ask me now so how can we create automatic XML file for mult multiple test cases yes very good question let me show you so this is my old XML
94:29
Speaker A
file let me remove this so now I want to create an XML file automatically which contains multiple test cases so in that case what you have to do is you have to select the package so in which package
94:43
Speaker A
these two test cases are present in the day 42 package now you need to select this package go to test NG and convert to test Ng now you can see both the classes here and you can create click on
94:58
Speaker A
finish okay it is created in the project level I'm just copying into the day 42 remove from here okay now we can see test XML which contains the two classes so like this we can create automatically by adding multiple cases this is the
95:24
Speaker A
process so in the realtime project will there be a single test change XML file which will contains all the s no we will maintain multiple XML file for grouping we will have one XML file for parallel testing we will maintain another XML file and all the test cases contains one single test
95:47
Speaker A
and master XML file we will maintain up to two to three XML files we will maintain in our project and depends upon the requirement you will choose right XML file to run suppose if you want to execute your test cases parall then you will choose XML for parallel execution
96:06
Speaker A
and if you want to execute the groups then you will choose group grouping XML file suppose if you want to execute all the test cases based on the groups in all the browsers parallely then you can maintain one master suit XML file that that you
96:21
Speaker A
can execute so depends upon our requirement and different scenarios we will create multiple XML files so clear everyone so please confirm in the chat box all the topics whatever we discussed today so just try this for today's session just try to configure test NG and once
96:46
Speaker A
you configure try to explore these points eight points related to priority and try to create XML file automatically and manually try to understand the tags which we created okay and then see how the report is going to generate so get familiar with this basic stuff and uh
97:06
Speaker A
tomorrow I will introduce next class I will introduce some more annotations today we will mainly discuss only at theate test annotation there are some more annotations are there so we will discuss that in the next session so if you miss something here if you not understood
97:20
Speaker A
something just try to watch the recorded Session One More Time so that it will be more clear for you okay so that's all for today's session and I'll stop here and we'll see in the next session
Topics:TestNGSeleniumJavaTest automationUnit testingParallel testingTest case managementParameterizationReport generationEclipse setup

Frequently Asked Questions

What is TestNG and why is it used in Selenium automation?

TestNG is a Java-based unit testing framework used to write, organize, and execute test cases. It enhances Selenium automation by enabling features like test grouping, parallel execution, parameterization, and report generation.

How does TestNG improve the testing process compared to using Selenium WebDriver alone?

While Selenium WebDriver automates web interactions, TestNG adds capabilities such as managing test suites, prioritizing tests, running tests in parallel on multiple browsers, and generating detailed reports, making automation more efficient and comprehensive.

Can TestNG tests be configured to run on different browsers and in parallel?

Yes, TestNG supports parallel test execution and parameterization, allowing tests to run simultaneously on multiple browsers, which helps reduce overall testing time.

Get More with the Söz AI App

Transcribe recordings, audio files, and YouTube videos — with AI summaries, speaker detection, and unlimited transcriptions.

Or transcribe another YouTube video here →