On python 3.11, I'm trying to use a method from another class, like this:
folder name: anyfunctions
script name: basicactions.py
from seleniumbase import BaseCase
class Firstfunction(BaseCase):
def login(self):
self.open("https://randomsite/authentication/signin")
self.wait_for_element("#username")
self.click(".d-grid")
Then, I'm trying to create a test using Selenium with the following code:
folder name: tests
script name: test_home.py
from seleniumbase import BaseCase
from anyfunctions import basicactions
class AnyTestName(BaseCase, basicactions):
def test_login(self):
basicactions.Firstfunction.login()
That, I was expecting to run the login method, but the following error appears:
TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases
Am I forgetting to add something to call the class correctly? Thanks
CodePudding user response:
Here's an example of the classic Page Object Model with BaseCase
inheritance using SeleniumBase:
from seleniumbase import BaseCase
class LoginPage:
def login_to_swag_labs(self, sb, username):
sb.open("https://www.saucedemo.com")
sb.type("#user-name", username)
sb.type("#password", "secret_sauce")
sb.click('input[type="submit"]')
class MyTests(BaseCase):
def test_swag_labs_login(self):
LoginPage().login_to_swag_labs(self, "standard_user")
self.assert_element("div.inventory_list")
self.assert_element('div:contains("Sauce Labs Backpack")')
self.js_click("a#logout_sidebar_link")
self.assert_element("div#login_button_container")
(Runs with pytest
)
CodePudding user response:
You don't need to (nor can you) subclass basicactions
in order to use it in the definition of the class.
You also need to create an instance of Firstfunction
in order to call the login
method.
class AnyTestName(BaseCase):
def test_login(self):
f = basicactions.Firstfunction()
f.login()