Modular Driven Framework is the approach where all the test cases are first analyzed to find out the reusable flows. Then while scripting, all these reusable flows are created as functions and stored in external files and called in the test scripts wherever required.
Advantages:
Modular division of scripts leads to easier maintenance and also the scalability of the automated test Scripts are independent to write.
Disadvantages:
Since data is still hard-coded in the script, the same test case cannot be run for multiple data values without changing data after each run.
Additional time is spent in analyzing the test cases to identify with reusable flows.
Good programming knowledge is required to create and maintain function libraries.
Real Time Examples:
Scenario 1 :
Verify the Service Type is available in the HTML table
1. Access the URL and enter Admin/Admin123 as credentials
2. Select the ‘Inpatient Ward’.
3. click on Login.
4. Navigate to Appointment Scheduling->Manage Service Types.
5. verify the Service Type ‘Urology’ available in the html table.
6. Logout
Scenario 2 :
Delete the Service Type from the HTML Table and Verify the Service Type is not available in the HTML Table
1. Access the url and enter Admin/Admin123 as credentials
2. Select the ‘Inpatient Ward’.
3. click on Login.
4. Navigate to Appointment Scheduling->Manage Service Types.
5. Click on Delete icon to perform deletion of Service Type.
6. Verify the Service Type is not available in the HTML Table
7 . Logout
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
package org.totalqa.modulardriven; import java.util.List; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.testng.Assert; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.testng.asserts.SoftAssert; import io.github.bonigarcia.wdm.WebDriverManager; public class ModularDrivenFwkTests { WebDriver driver ; @BeforeClass public void instantiateDriver() { WebDriverManager.chromedriver().setup(); driver = new ChromeDriver(); } @Test(enabled=false,priority=1,description="Scenario1 Verify the Service Type available in the html table") public void validateServiceTypeFunc() { invokeBrowser(); login(); navigateToServiceTypeTable(); boolean result = verifyServiceType("Obstetrics"); Assert.assertTrue(result); } @Test(priority=2,description="Scenario2 Delete the Service Type and Verify the ServiceType is not available in the html table") public void deleteServiceTypeFunc() throws InterruptedException { invokeBrowser(); login(); navigateToServiceTypeTable(); SoftAssert sa = new SoftAssert(); boolean result = deleteServiceType("Oncology"); sa.assertTrue(result); navigateToHomePage(); navigateToServiceTypeTable(); result = verifyServiceType("Oncology"); sa.assertFalse(result); sa.assertAll(); } public void navigateToServiceTypeTable() { //AppointmentScheduling driver.findElement(By.id("appointmentschedulingui-homeAppLink-appointmentschedulingui-homeAppLink-extension")).click(); //ServiceTypes driver.findElement(By.id("appointmentschedulingui-manageAppointmentTypes-app")).click(); } public void navigateToHomePage() { driver.findElement(By.xpath("//body/ul[@id='breadcrumbs']/li[1]/a[1]/i[1]")).click(); } public void invokeBrowser() { driver.get("https://demo.openmrs.org/openmrs/login.htm"); } public void login() { driver.findElement(By.id("username")).sendKeys("Admin"); driver.findElement(By.id("password")).sendKeys("Admin123"); driver.findElement(By.id("Inpatient Ward")).click(); driver.findElement(By.id("loginButton")).click(); } public boolean verifyServiceType(String serviceType) { boolean result = false; List<WebElement> pageList = driver.findElements(By.xpath("//div[@id='appointmentTypesTable_paginate']/span/a")); List<WebElement> serviceTypeList=driver.findElements(By.xpath("//table[@id='appointmentTypesTable']/tbody/tr/td[1]")); outerloop: for(int i =0 ;i<pageList.size();i++) { pageList = driver.findElements(By.xpath("//div[@id='appointmentTypesTable_paginate']/span/a")); pageList.get(i).click(); serviceTypeList=driver.findElements(By.xpath("//table[@id='appointmentTypesTable']/tbody/tr/td[1]")); for(int j=0;j<serviceTypeList.size();j++) { if(serviceTypeList.get(j).getText().equals(serviceType)) { System.out.println("ServiceType Found:::" + serviceTypeList.get(j).getText()); result = true; break outerloop; } } } return result; } public boolean deleteServiceType(String serviceType) throws InterruptedException { boolean result = false; List<WebElement> pageList = driver.findElements(By.xpath("//div[@id='appointmentTypesTable_paginate']/span/a")); List<WebElement> serviceTypeList=driver.findElements(By.xpath("//table[@id='appointmentTypesTable']/tbody/tr/td[1]")); outerloop: for(int i =0 ;i<pageList.size();i++) { pageList = driver.findElements(By.xpath("//div[@id='appointmentTypesTable_paginate']/span/a")); pageList.get(i).click(); serviceTypeList=driver.findElements(By.xpath("//table[@id='appointmentTypesTable']/tbody/tr/td[1]")); for(int j=0;j<serviceTypeList.size();j++) { if(serviceTypeList.get(j).getText().equals(serviceType)) { System.out.println("ServiceType Found:::" + serviceTypeList.get(j).getText()); //Click on delete icon driver.findElement(By.xpath("//table[@id='appointmentTypesTable']/tbody/tr["+(j+1)+"]/td[text()='"+serviceType+"']/following-sibling::td/span/i[@title='Delete']")).click(); //Click on Yes button in the simple modal container driver.findElement(By.xpath("//body/div[@id='simplemodal-container']/div[1]/div[1]/div[2]/button[1]")).click(); result = true; Thread.sleep(2000); break outerloop; } } } return result; } } |
Conclusion:
Using the Logic mentioned above helps to implement the Modular Driven Framework successfully in your projects.
Let us know if you have any queries in implementing this framework.
Drop an email to totalqa9@gmail.com
Thanks for the @Guest Author :
Nithya Kalyani
Email ID : Nithyakalyanigovindarajan@gmail.com