0

I'm kinda new in coding and was asked to do a test for the company web login, they want me to implement the module unitestt and playwright test generator tool. This is what I have so far. I had to separate run from test_1 since unittest failed while reading the chromium line but now it only opens the browser so what can I do in order for it to run the whole test?

from playwright.sync_api import Playwright, sync_playwright
from locators import Locators_evou
import unittest

class Test(unittest.TestCase):
    def run(playwright: Playwright) -> None:
        browser = playwright.chromium.launch(channel ="chrome", headless=False,slow_mo=500)
        context = browser.new_context()

        page = context.new_page()
        page.goto("http://localhost:3000/")

    def test_1(page):   
        page.click(Locators_evou.user_Log)
        page.fill(Locators_evou.user_Log, "Liliana")
        page.click(Locators_evou.password_log)
        page.fill(Locators_evou.password_log, "1234")
        page.check(Locators_evou.session_Log)
        page.click(Locators_evou.login_log)

        assert page.is_visible("¡Bienvenido!")
        
    with sync_playwright() as playwright:
        run(playwright)

   
if __name__=="__main__":
    unittest.main()
  • I'd imagine it fails because `Test` has no attribute `chromium`. You need `self` as the first argument for `run`, as well as `playwright`. See the [basic example](https://docs.python.org/3/library/unittest.html#basic-example) from the docs. – C.Nivs Nov 30 '21 at 15:30
  • Tried to add self in def run (self, playwright) but now I have this error Test.run() missing 1 required positional argument: 'playwright' – Liliana González Nov 30 '21 at 19:31
  • I'd recommend to use the official Pytest plugin for Playwright: https://playwright.dev/python/docs/test-runners and create functional tests (function tests vs. class based tests) instead. – Max Schmitt Dec 01 '21 at 14:59

0 Answers0