-
-
Save rahulmr/fbeba81b0ed814a306b767ffb36cd5e9 to your computer and use it in GitHub Desktop.
Playwright Python Tutorial: Getting Started With Python End To End Testing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from playwright.sync_api import sync_playwright | |
| import sys | |
| sys.path.append(sys.path[0] + "/..") | |
| from elementSelectors.loginAndBuySelectors import elementSelector | |
| from testCapabilities.testCaps import testCapabilities | |
| select = elementSelector() | |
| capability = testCapabilities() | |
| # Setting grid status to failed or passed | |
| def set_test_status(page, status, remark): | |
| page.evaluate("_ => {}", | |
| "lambdatest_action: {\"action\": \"setTestStatus\", \"arguments\": {\"status\":\"" + status + "\", \"remark\": \"" + remark + "\"}}") | |
| class LoginAndBuy: | |
| def __init__(self, playwright) -> None: | |
| self.browser = playwright.chromium.connect(capability.Chrome()) | |
| page = self.browser.new_page() | |
| self.page = page | |
| def launchWeb(self): | |
| self.page.goto(select.webPage()) | |
| title = self.page.title() | |
| print(title) | |
| def fillEmail(self, data): | |
| self.page.locator(select.eMail()).fill(data) | |
| def fillPassword(self, data): | |
| self.page.locator(select.Password()).fill(data) | |
| def clickLogin(self): | |
| self.page.locator(select.loginAccount()).click() | |
| def fillSearchBox(self, data): | |
| self.page.locator(select.searchProduct()).fill(data) | |
| def clickSearchButton(self): | |
| self.page.locator(select.searchButton()).click() | |
| def clickProduct(self): | |
| self.page.locator(select.Product()).click() | |
| def clickAddToCart(self): | |
| self.page.locator(select.addCart()).click() | |
| def clickCheckOutModal(self): | |
| self.page.locator(select.checkOut()).click() | |
| def hoverMenuBox(self): | |
| self.page.locator(select.hoverBox()).hover() | |
| def clickLogout(self): | |
| self.page.locator(select.logoutUser()).click() | |
| def getSuccessStatus(self): | |
| set_test_status(self.page, "passed", "Success") | |
| def getFailedStatus(self): | |
| set_test_status(self.page, "failed", "Test failed") | |
| def closeBrowser(self): | |
| self.browser.close() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment