|
| 1 | +From 40a8b5fea85f09477c632a052198d15a4ec1bb23 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Chirag Mangukia < [email protected]> |
| 3 | +Date: Sat, 4 Jun 2022 22:15:12 +0530 |
| 4 | +Subject: [PATCH] Added more Test Classes and Functionalities |
| 5 | + |
| 6 | +--- |
| 7 | + .../java/com/qa/chirag/pages/BrandPage.java | 30 ++++++++++++++++ |
| 8 | + .../com/qa/chirag/pages/DesktopsPage.java | 32 +++++++++++++---- |
| 9 | + .../java/com/qa/chirag/pages/ProductPage.java | 35 +++++++++++++++++++ |
| 10 | + .../java/com/qa/chirag/utils/ElementUtil.java | 34 ++++++++++++++++-- |
| 11 | + .../java/com/qa/chirag/base/BaseTest.java | 4 +++ |
| 12 | + .../qa/chirag/testcases/BrandPageTest.java | 28 +++++++++++++++ |
| 13 | + .../qa/chirag/testcases/DesktopsPageTest.java | 15 ++++++-- |
| 14 | + .../qa/chirag/testcases/ProductPageTest.java | 22 ++++++++++++ |
| 15 | + src/test/resources/testrunners/testng.xml | 2 ++ |
| 16 | + 9 files changed, 189 insertions(+), 13 deletions(-) |
| 17 | + create mode 100644 src/main/java/com/qa/chirag/pages/BrandPage.java |
| 18 | + create mode 100644 src/main/java/com/qa/chirag/pages/ProductPage.java |
| 19 | + create mode 100644 src/test/java/com/qa/chirag/testcases/BrandPageTest.java |
| 20 | + create mode 100644 src/test/java/com/qa/chirag/testcases/ProductPageTest.java |
| 21 | + |
| 22 | +diff --git a/src/main/java/com/qa/chirag/pages/BrandPage.java b/src/main/java/com/qa/chirag/pages/BrandPage.java |
| 23 | +new file mode 100644 |
| 24 | +index 0000000..20234bd |
| 25 | +--- /dev/null |
| 26 | ++++ b/src/main/java/com/qa/chirag/pages/BrandPage.java |
| 27 | +@@ -0,0 +1,30 @@ |
| 28 | ++package com.qa.chirag.pages; |
| 29 | ++ |
| 30 | ++import org.openqa.selenium.By; |
| 31 | ++import org.openqa.selenium.WebDriver; |
| 32 | ++ |
| 33 | ++import com.qa.chirag.utils.ElementUtil; |
| 34 | ++ |
| 35 | ++public class BrandPage { |
| 36 | ++ |
| 37 | ++ WebDriver driver; |
| 38 | ++ ElementUtil elementUtil; |
| 39 | ++ |
| 40 | ++ private By breadcrumb = By.cssSelector("ul.breadcrumb"); |
| 41 | ++ private By brandName = By.cssSelector("div#content h2"); |
| 42 | ++ |
| 43 | ++ public BrandPage(WebDriver driver) { |
| 44 | ++ this.driver = driver; |
| 45 | ++ elementUtil = new ElementUtil(driver); |
| 46 | ++ elementUtil.doScroll(breadcrumb); |
| 47 | ++ } |
| 48 | ++ |
| 49 | ++ public String getTitle() { |
| 50 | ++ return elementUtil.doGetTitle(); |
| 51 | ++ } |
| 52 | ++ |
| 53 | ++ public String getBrandName() { |
| 54 | ++ return elementUtil.doGetText(brandName); |
| 55 | ++ } |
| 56 | ++ |
| 57 | ++} |
| 58 | +diff --git a/src/main/java/com/qa/chirag/pages/DesktopsPage.java b/src/main/java/com/qa/chirag/pages/DesktopsPage.java |
| 59 | +index ef9428b..0bbb146 100644 |
| 60 | +--- a/src/main/java/com/qa/chirag/pages/DesktopsPage.java |
| 61 | ++++ b/src/main/java/com/qa/chirag/pages/DesktopsPage.java |
| 62 | +@@ -1,12 +1,9 @@ |
| 63 | + package com.qa.chirag.pages; |
| 64 | + |
| 65 | +-import java.util.ArrayList; |
| 66 | + import java.util.List; |
| 67 | + |
| 68 | + import org.openqa.selenium.By; |
| 69 | + import org.openqa.selenium.WebDriver; |
| 70 | +-import org.openqa.selenium.WebElement; |
| 71 | +- |
| 72 | + import com.qa.chirag.utils.ElementUtil; |
| 73 | + |
| 74 | + public class DesktopsPage { |
| 75 | +@@ -15,6 +12,8 @@ public class DesktopsPage { |
| 76 | + |
| 77 | + private ElementUtil elementUtil; |
| 78 | + |
| 79 | ++ private By labelRefineSearch = By.cssSelector("div#content h3"); |
| 80 | ++ private By dropdownShow = By.cssSelector("select#input-limit"); |
| 81 | + private By listedProducts = By.xpath("//div[@id='content']/div[4]/div"); |
| 82 | + |
| 83 | + public DesktopsPage(WebDriver driver) { |
| 84 | +@@ -22,6 +21,10 @@ public class DesktopsPage { |
| 85 | + elementUtil = new ElementUtil(driver); |
| 86 | + } |
| 87 | + |
| 88 | ++ private By getProductLink(String product) { |
| 89 | ++ return By.partialLinkText(product); |
| 90 | ++ } |
| 91 | ++ |
| 92 | + public String getPageTitle() { |
| 93 | + return elementUtil.doGetTitle(); |
| 94 | + } |
| 95 | +@@ -31,11 +34,26 @@ public class DesktopsPage { |
| 96 | + } |
| 97 | + |
| 98 | + public List<String> getProductsList() { |
| 99 | +- List<String> products = new ArrayList<String>(); |
| 100 | +- for (WebElement e : elementUtil.doGetElements(listedProducts)) { |
| 101 | +- products.add(e.getText()); |
| 102 | ++ return elementUtil.doGetTextListFromWebElements(listedProducts); |
| 103 | ++ } |
| 104 | ++ |
| 105 | ++ public void selectFromShowDropdown(int numberOfProductsToDisplay) { |
| 106 | ++ elementUtil.doScroll(labelRefineSearch); |
| 107 | ++ elementUtil.doSelectDropdownByVisibleText(dropdownShow, Integer.toString(numberOfProductsToDisplay)); |
| 108 | ++ } |
| 109 | ++ |
| 110 | ++ public ProductPage selectProduct(String product) { |
| 111 | ++ if (elementUtil.checkIfElementIsPresent(getProductLink(product))) { |
| 112 | ++ elementUtil.doClick(getProductLink(product)); |
| 113 | + } |
| 114 | +- return products; |
| 115 | ++ return new ProductPage(driver); |
| 116 | + } |
| 117 | + |
| 118 | ++ public ProductPage selectProduct(String product, int productCountFromDropdown) { |
| 119 | ++ selectFromShowDropdown(productCountFromDropdown); |
| 120 | ++ if (elementUtil.checkIfElementIsPresent(getProductLink(product))) { |
| 121 | ++ elementUtil.doClick(getProductLink(product)); |
| 122 | ++ } |
| 123 | ++ return new ProductPage(driver); |
| 124 | ++ } |
| 125 | + } |
| 126 | +diff --git a/src/main/java/com/qa/chirag/pages/ProductPage.java b/src/main/java/com/qa/chirag/pages/ProductPage.java |
| 127 | +new file mode 100644 |
| 128 | +index 0000000..6067902 |
| 129 | +--- /dev/null |
| 130 | ++++ b/src/main/java/com/qa/chirag/pages/ProductPage.java |
| 131 | +@@ -0,0 +1,35 @@ |
| 132 | ++package com.qa.chirag.pages; |
| 133 | ++ |
| 134 | ++import org.openqa.selenium.By; |
| 135 | ++import org.openqa.selenium.WebDriver; |
| 136 | ++ |
| 137 | ++import com.qa.chirag.utils.ElementUtil; |
| 138 | ++ |
| 139 | ++public class ProductPage { |
| 140 | ++ |
| 141 | ++ WebDriver driver; |
| 142 | ++ ElementUtil elementUtil; |
| 143 | ++ |
| 144 | ++ private By breadcrumb = By.cssSelector("ul.breadcrumb"); |
| 145 | ++ private By productName = By.cssSelector("div#content h1"); |
| 146 | ++ private By brandName = By.cssSelector("div#content ul.list-unstyled a"); |
| 147 | ++ |
| 148 | ++ public ProductPage(WebDriver driver) { |
| 149 | ++ this.driver = driver; |
| 150 | ++ elementUtil = new ElementUtil(driver); |
| 151 | ++ scrollToContents(); |
| 152 | ++ } |
| 153 | ++ |
| 154 | ++ private void scrollToContents() { |
| 155 | ++ elementUtil.doScroll(breadcrumb); |
| 156 | ++ } |
| 157 | ++ |
| 158 | ++ public String getProductName() { |
| 159 | ++ return elementUtil.doGetText(productName); |
| 160 | ++ } |
| 161 | ++ |
| 162 | ++ public BrandPage clickBrandName() { |
| 163 | ++ elementUtil.doClick(brandName); |
| 164 | ++ return new BrandPage(driver); |
| 165 | ++ } |
| 166 | ++} |
| 167 | +diff --git a/src/main/java/com/qa/chirag/utils/ElementUtil.java b/src/main/java/com/qa/chirag/utils/ElementUtil.java |
| 168 | +index 34625bc..f0dd06c 100644 |
| 169 | +--- a/src/main/java/com/qa/chirag/utils/ElementUtil.java |
| 170 | ++++ b/src/main/java/com/qa/chirag/utils/ElementUtil.java |
| 171 | +@@ -1,6 +1,7 @@ |
| 172 | + package com.qa.chirag.utils; |
| 173 | + |
| 174 | + import java.time.Duration; |
| 175 | ++import java.util.ArrayList; |
| 176 | + import java.util.List; |
| 177 | + |
| 178 | + import org.openqa.selenium.By; |
| 179 | +@@ -8,6 +9,7 @@ import org.openqa.selenium.JavascriptExecutor; |
| 180 | + import org.openqa.selenium.WebDriver; |
| 181 | + import org.openqa.selenium.WebElement; |
| 182 | + import org.openqa.selenium.support.ui.ExpectedConditions; |
| 183 | ++import org.openqa.selenium.support.ui.Select; |
| 184 | + import org.openqa.selenium.support.ui.WebDriverWait; |
| 185 | + |
| 186 | + public class ElementUtil { |
| 187 | +@@ -31,7 +33,7 @@ public class ElementUtil { |
| 188 | + } |
| 189 | + |
| 190 | + public String doGetTitle() { |
| 191 | +- return driver.getTitle(); |
| 192 | ++ return driver.getTitle().trim(); |
| 193 | + } |
| 194 | + |
| 195 | + public String doGetCurrentURL() { |
| 196 | +@@ -52,7 +54,15 @@ public class ElementUtil { |
| 197 | + } |
| 198 | + |
| 199 | + public String doGetText(By by) { |
| 200 | +- return doGetElement(by).getText(); |
| 201 | ++ return doGetElement(by).getText().trim(); |
| 202 | ++ } |
| 203 | ++ |
| 204 | ++ public List<String> doGetTextListFromWebElements(By by) { |
| 205 | ++ List<String> list = new ArrayList<String>(); |
| 206 | ++ for (WebElement e : doGetElements(by)) { |
| 207 | ++ list.add(e.getText().trim()); |
| 208 | ++ } |
| 209 | ++ return list; |
| 210 | + } |
| 211 | + |
| 212 | + public void doRefreshPage() { |
| 213 | +@@ -93,5 +103,23 @@ public class ElementUtil { |
| 214 | + return false; |
| 215 | + } |
| 216 | + } |
| 217 | +- |
| 218 | ++ |
| 219 | ++ public void doSelectDropdownByVisibleText(By by, String textToSelect) { |
| 220 | ++ Select select = new Select(doGetElement(by)); |
| 221 | ++ try { |
| 222 | ++ select.selectByVisibleText(textToSelect); |
| 223 | ++ } catch (Exception e) { |
| 224 | ++ } |
| 225 | ++ } |
| 226 | ++ |
| 227 | ++ public List<String> getListOfDropdownTexts(By by) { |
| 228 | ++ List<String> list = new ArrayList<String>(); |
| 229 | ++ Select select = new Select(doGetElement(by)); |
| 230 | ++ List<WebElement> options = select.getOptions(); |
| 231 | ++ int size = options.size(); |
| 232 | ++ for(int i = 0; i < size; i++) { |
| 233 | ++ list.add(options.get(i).getText()); |
| 234 | ++ } |
| 235 | ++ return list; |
| 236 | ++ } |
| 237 | + } |
| 238 | +diff --git a/src/test/java/com/qa/chirag/base/BaseTest.java b/src/test/java/com/qa/chirag/base/BaseTest.java |
| 239 | +index 769d810..4770f40 100644 |
| 240 | +--- a/src/test/java/com/qa/chirag/base/BaseTest.java |
| 241 | ++++ b/src/test/java/com/qa/chirag/base/BaseTest.java |
| 242 | +@@ -7,11 +7,13 @@ import org.testng.annotations.AfterTest; |
| 243 | + |
| 244 | + import com.qa.chirag.factory.DriverFactory; |
| 245 | + import com.qa.chirag.pages.AccountPage; |
| 246 | ++import com.qa.chirag.pages.BrandPage; |
| 247 | + import com.qa.chirag.pages.CommonsPage; |
| 248 | + import com.qa.chirag.pages.DesktopsPage; |
| 249 | + import com.qa.chirag.pages.EditAccountInfoPage; |
| 250 | + import com.qa.chirag.pages.HomePage; |
| 251 | + import com.qa.chirag.pages.LoginPage; |
| 252 | ++import com.qa.chirag.pages.ProductPage; |
| 253 | + import com.qa.chirag.utils.Utilities; |
| 254 | + |
| 255 | + public class BaseTest { |
| 256 | +@@ -28,6 +30,8 @@ public class BaseTest { |
| 257 | + protected AccountPage accountPage; |
| 258 | + protected DesktopsPage desktopsPage; |
| 259 | + protected EditAccountInfoPage editAccountInfoPage; |
| 260 | ++ protected ProductPage productPage; |
| 261 | ++ protected BrandPage brandPage; |
| 262 | + |
| 263 | + public BaseTest() { |
| 264 | + df = new DriverFactory(); |
| 265 | +diff --git a/src/test/java/com/qa/chirag/testcases/BrandPageTest.java b/src/test/java/com/qa/chirag/testcases/BrandPageTest.java |
| 266 | +new file mode 100644 |
| 267 | +index 0000000..1b647cb |
| 268 | +--- /dev/null |
| 269 | ++++ b/src/test/java/com/qa/chirag/testcases/BrandPageTest.java |
| 270 | +@@ -0,0 +1,28 @@ |
| 271 | ++package com.qa.chirag.testcases; |
| 272 | ++ |
| 273 | ++import org.testng.Assert; |
| 274 | ++import org.testng.annotations.BeforeClass; |
| 275 | ++import org.testng.annotations.Test; |
| 276 | ++ |
| 277 | ++import com.qa.chirag.base.BaseTest; |
| 278 | ++ |
| 279 | ++public class BrandPageTest extends BaseTest { |
| 280 | ++ |
| 281 | ++ @BeforeClass |
| 282 | ++ public void brandPageSetup() { |
| 283 | ++ loginPage.doLogin(prop.getProperty("username").trim(), prop.getProperty("password").trim()); |
| 284 | ++ desktopsPage = commonsPage.goToDesktopsPage(); |
| 285 | ++ productPage = desktopsPage.selectProduct("Canon EOS 5D"); |
| 286 | ++ brandPage = productPage.clickBrandName(); |
| 287 | ++ } |
| 288 | ++ |
| 289 | ++ @Test(priority = 1) |
| 290 | ++ public void verifyTitleTest() { |
| 291 | ++ Assert.assertEquals(brandPage.getTitle(), "Canon"); |
| 292 | ++ } |
| 293 | ++ |
| 294 | ++ @Test(priority = 2) |
| 295 | ++ public void verifyBrandNameTest() { |
| 296 | ++ Assert.assertEquals(brandPage.getBrandName(), "Canon"); |
| 297 | ++ } |
| 298 | ++} |
| 299 | +\ No newline at end of file |
| 300 | +diff --git a/src/test/java/com/qa/chirag/testcases/DesktopsPageTest.java b/src/test/java/com/qa/chirag/testcases/DesktopsPageTest.java |
| 301 | +index aabd847..8f13c10 100644 |
| 302 | +--- a/src/test/java/com/qa/chirag/testcases/DesktopsPageTest.java |
| 303 | ++++ b/src/test/java/com/qa/chirag/testcases/DesktopsPageTest.java |
| 304 | +@@ -11,13 +11,22 @@ public class DesktopsPageTest extends BaseTest { |
| 305 | + |
| 306 | + @BeforeClass |
| 307 | + public void desktopsPageSetup() { |
| 308 | +- accountPage = loginPage.doLogin(prop.getProperty("username").trim(), prop.getProperty("password").trim()); |
| 309 | ++ loginPage.doLogin(prop.getProperty("username").trim(), prop.getProperty("password").trim()); |
| 310 | + desktopsPage = commonsPage.goToDesktopsPage(); |
| 311 | + } |
| 312 | + |
| 313 | +- @Test |
| 314 | ++ @Test(priority = 1) |
| 315 | + public void titleTest() { |
| 316 | + Assert.assertEquals(desktopsPage.getPageTitle(), Constants.DESKTOPS_PAGE_TITLE); |
| 317 | + } |
| 318 | +- |
| 319 | ++ |
| 320 | ++ @Test(priority = 2) |
| 321 | ++ public void productLimitDropdownTest() { |
| 322 | ++ desktopsPage.selectFromShowDropdown(100); |
| 323 | ++ } |
| 324 | ++ |
| 325 | ++ @Test(priority = 3) |
| 326 | ++ public void selectProductTest() { |
| 327 | ++ desktopsPage.selectProduct("Samsung SyncMaster"); |
| 328 | ++ } |
| 329 | + } |
| 330 | +diff --git a/src/test/java/com/qa/chirag/testcases/ProductPageTest.java b/src/test/java/com/qa/chirag/testcases/ProductPageTest.java |
| 331 | +new file mode 100644 |
| 332 | +index 0000000..83bcf69 |
| 333 | +--- /dev/null |
| 334 | ++++ b/src/test/java/com/qa/chirag/testcases/ProductPageTest.java |
| 335 | +@@ -0,0 +1,22 @@ |
| 336 | ++package com.qa.chirag.testcases; |
| 337 | ++ |
| 338 | ++import org.testng.Assert; |
| 339 | ++import org.testng.annotations.BeforeClass; |
| 340 | ++import org.testng.annotations.Test; |
| 341 | ++ |
| 342 | ++import com.qa.chirag.base.BaseTest; |
| 343 | ++ |
| 344 | ++public class ProductPageTest extends BaseTest { |
| 345 | ++ |
| 346 | ++ @BeforeClass |
| 347 | ++ public void productPageSetup() { |
| 348 | ++ loginPage.doLogin(prop.getProperty("username").trim(), prop.getProperty("password").trim()); |
| 349 | ++ desktopsPage = commonsPage.goToDesktopsPage(); |
| 350 | ++ productPage = desktopsPage.selectProduct("Canon EOS 5D"); |
| 351 | ++ } |
| 352 | ++ |
| 353 | ++ @Test |
| 354 | ++ public void verifyProductNameTest() { |
| 355 | ++ Assert.assertEquals(productPage.getProductName(), "Canon EOS 5D"); |
| 356 | ++ } |
| 357 | ++} |
| 358 | +diff --git a/src/test/resources/testrunners/testng.xml b/src/test/resources/testrunners/testng.xml |
| 359 | +index 0f67c23..7350dd2 100644 |
| 360 | +--- a/src/test/resources/testrunners/testng.xml |
| 361 | ++++ b/src/test/resources/testrunners/testng.xml |
| 362 | +@@ -10,6 +10,8 @@ |
| 363 | + <class name="com.qa.chirag.testcases.LoginPageTest"/> |
| 364 | + <class name="com.qa.chirag.testcases.DesktopsPageTest"/> |
| 365 | + <class name="com.qa.chirag.testcases.AccountPageTest"/> |
| 366 | ++ <class name="com.qa.chirag.testcases.ProductPageTest"/> |
| 367 | ++ <class name="com.qa.chirag.testcases.BrandPageTest"/> |
| 368 | + </classes> |
| 369 | + </test> <!-- Test --> |
| 370 | + </suite> <!-- Suite --> |
| 371 | +\ No newline at end of file |
| 372 | +-- |
| 373 | +2.36.1.windows.1 |
| 374 | + |
0 commit comments