FrameworkPart3-TestConfig - Create new Test methods with Dependency Attirbute-Automation-MrBeatCoder

In this lesson, we will learn how to create new Test methods with Dependency attribute based on Test Strategy Design
Steps: How to create new Test methods with Dependency attribute based on Test Strategy Design
1. In the SubmitOrderTest Class, let’s create a 2nd Test case, to verify the product, ZARA COAT 3 is displaying in the Orders Page, after we have added it into the Cart
a. We could add the code to do this in the existing 1st test case. But, it is helpful and more clear to breakdown test cases without multiple verifications in one single test case. But, this will depend on our Test Strategy
b. But, for our lesson, let’s create a new Test case (method) to verify the product, ZARA COAT 3 is displaying in the Orders Page, after we have added it into the Cart
c. And, our new Test case (method) will have a dependency on the first test case (method). So the test we are now writing is about the verification of the previous test case’s test result. So, now, let’s learn how to connect them both
2. Let’s now create the new Test case (method) and call it OrderHistory
a. The first thing we need to do, is that we have clearly say that we run this new test, only after the previous test case has been executed, submitOrder
- Because the previous test case has added the product, ZARA COAT 3, so our new test case is dependent on that action, as that is what we are trying to verify in the Orders Page
3. So, here we use a new annotation dependsonMethod and input the test method it depends on, in the argument. In our Example, it is the test method, submitOrder
a. Please Note: We cannot run this test individually. So that's why we’re calling this a dependent test.
b. So, if we run this new test case OrderHistory, the previous test case, submitOrder will run first. And, this will work because the previous test case submitOrder has added the product, ZARA COAT 3, so our new test case OrderHistory is dependent on that action, as that is what we are trying to verify in the Orders Page
// New Test Case to verify ZARA COAT 3 is displayed in the Order page
@Test(dependsOnMethods = {"submitOrder"})
public void OrderHistoryTest()
{
}
4. Now, let’s add the code in the new test case OrderHistory.
a. So, first we need to login from the Landing Page. We can use the same line of code to login. Remember, the BeforeMethod and AfterMethod will still execute :slight_smile:
b. Then, let’s find the locator for clicking on “ORDERS” button. And, because this button is in the headers page, which is common throughout the E-Commerce website, we will place it’s locator in the AbstractComponent Class
//CSS Locator for ORDERS Page
@FindBy(css="[routerlink*='myorders']")
WebElement ordersHeader;
c. Now, create a new method in the AbstractComponent Class to click on the ORDERS button. We can copy the method for clicking on the CART button, goToCartPage and rename it goToOrdersPage
For the object, we need to create a new object, ordersPage in a new class, OrdersPage Class. So, we also need to create a new page objects class for OrdersPage Class. As we know from our previous Design Object Model lessons, we need to create a new page objects class for every web page! It’s all coming together now, right Team?
public OrdersPage goToOrdersPage()
{
ordersHeader.click();
OrdersPage ordersPage = new OrdersPage(driver);
return ordersPage;
}
d. In the OrdersPage Class, remove all the code we no longer need. We can use the existing test method, verifyProductsTitles and change the method name to verifyOrdersDisplay
- We can actually use the same line of code inside the method, but we need to use a different locator. And, we need to store them into a list of Web Elements
- Replace the previous List of WebElement, with the new list of WebElement productOrderNames and use it to apply stream
- Remember to import the new OrdersPage Class in the goToOrdersPage method in the AbstractComponents Class
5. Go back to the SubmitOrderTest Class and in the new method OrderHistory. After we logged in. Add the code to click on the Orders Page and to verify our order in the Orders Page as below code
a. In the argument of verifyOrdersDisplay we need to input the String productName. And, we need to remove the declaration of the String productName from the first test method, to the global call level. So, that it can be accessed everywhere in the class level
b. Then, use the Assertion, assert.AssertTrue to validate our condition is true, and our test will Pass
6. Run the SubmitOrderTest Class to check our dependency attribute works!

Пікірлер