![]() ![]() ( "Closing Google Chrome (priority = - 1) But this time, I have reassigned the priorities of all the methods. The below-given code is the same as the code we used above. Analyzing Test Sequence with Test Priority In TestNG with Selenium Let's prove this fact with some test code in the next section. It means if we define no priorities, all the test methods will be assigned priority 0, and a similar priority case will apply. The test methods with no priority assigned have a default priority equal to 0. If all the test cases with no priorities run alphabetically and all the test cases with similar priorities also run alphabetically, then there must be some relation between these two situations. Since " A" comes before " C", the method AccountTest ran first.īut let's wait and think at this moment for a second by recollecting the memories of test cases and priorities. A good explanation for this behaviour is that if two or more methods have the same priorities in TestNG, then their running test sequence is alphabetic. Even though the CloseBrowser method was declared first, AccountTest was the one that ran before CloseBrowser. The OpenBrowser ran first, no questions there!! But, an interesting pattern appears in the methods containing similar priorities ( 1). In the above code, I have set the priority of AccountTest and CloseBrowser as one while OpenBrowser retains its priority of 0. ( "Launching Google Chrome (priority = 1) If priority is deciding the sequence of tests in TestNG, then a simple question arises in our minds: what if I declare the same priority to all the tests in TestNG? Let' see this case by observing the following code: import Had I not declared the priority here, it would have run alphabetically, i.e., CloseBrowser first and then OpenBrowser. The priorities set are 0 for OpenBrowser and 1 for CloseBrowser, so I expect the OpenBrowser method to run first.Įxecute the above TestNG test file to check the output.Īs expected, the OpenBrowser method ran first because of a lower priority. In the OpenBrowser method, I am trying to open the browser and enter the URL "The " CloseBrowser" method, however, is used to close the driver. ![]() Observe the following code, which has two methods: OpenBrowser and CloseBrowser. Writing a test case with priority in TestNG is similar to how we write a typical test case in TestNG but with a " priority" attribute. How To Run Prioritized Tests In TestNG Using Selenium? ![]() Keeping these points in mind, we are ready to run our first test with declared priority methods using selenium.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |