Advertisement
AndikaWiratana

frontend-ui-testing-artha

Jun 19th, 2024
393
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.68 KB | Source Code | 0 0
  1. import re
  2. from playwright.sync_api import Playwright, sync_playwright, expect
  3.  
  4.  
  5. def run(playwright: Playwright) -> None:
  6.     # setup browser and access the page
  7.     browser = playwright.chromium.launch(headless=False, slow_mo=100) # with slow motion
  8.     context = browser.new_context()
  9.     page = context.new_page()
  10.     page.goto("https://pplfe-production-79c8.up.railway.app/") # access the page
  11.  
  12.     # generate single ipk
  13.     page.get_by_role("row", name="1 8770034002 Teknik Komputer").get_by_role("button").click()
  14.     page.get_by_role("row", name="2 6293338171 Teknik Komputer").get_by_role("button").click()
  15.     page.get_by_role("row", name="3 2422192164 Teknik").get_by_role("button").click()
  16.     page.get_by_role("button", name="Generate All IPK").click()
  17.  
  18.     # validate the output
  19.     expect(page.locator("#app > div > div:nth-child(2) > div > div.v-table__wrapper > table > tbody > tr:nth-child(1) > td:nth-child(7) > span")).to_have_text("1.8333333333333333")
  20.     expect(page.locator("#app > div > div:nth-child(2) > div > div.v-table__wrapper > table > tbody > tr:nth-child(2) > td:nth-child(7) > span")).to_have_text("0")
  21.     expect(page.locator("#app > div > div:nth-child(2) > div > div.v-table__wrapper > table > tbody > tr:nth-child(3) > td:nth-child(7) > span")).to_have_text("0.8")
  22.     expect(page.locator("#app > div > div:nth-child(2) > div > div.v-table__wrapper > table > tbody > tr:nth-child(4) > td:nth-child(7) > span")).to_have_text("2.2222222222222223")
  23.  
  24.     # validate pagination functionality (example 10 page)
  25.     page.get_by_label("Page 1, Current page").click()
  26.     page.get_by_label("Go to page 2").click()
  27.     page.get_by_label("Go to page 3").click()
  28.     page.get_by_label("Go to page 4", exact=True).click()
  29.     page.get_by_label("Go to page 5").click()
  30.     page.get_by_label("Go to page 6").click()
  31.     page.get_by_label("Go to page 7").click()
  32.     page.get_by_label("Go to page 8").click()
  33.     page.get_by_label("Go to page 9").click()
  34.     page.get_by_label("Go to page 10").click()
  35.  
  36.     # validate show specific amount (except 5)
  37.     page.locator("div").filter(has_text=re.compile(r"^10$")).first.click()
  38.     page.get_by_role("option", name="20").click()
  39.     page.locator("div").filter(has_text=re.compile(r"^20$")).first.click()
  40.     page.get_by_role("option", name="50").click()
  41.     page.locator("div").filter(has_text=re.compile(r"^50$")).first.click()
  42.     page.get_by_role("option", name="100").click()
  43.     page.locator("div").filter(has_text=re.compile(r"^100$")).first.click()
  44.     page.get_by_role("option", name="4425").click()
  45.  
  46.     # end process
  47.     context.close()
  48.     browser.close()
  49.  
  50.  
  51. with sync_playwright() as playwright:
  52.     run(playwright)
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement