Package: uitestcore
UiTestCoreThis package helps with writing UI tests by providing a wrapper around Selenium and other useful functions. UiTestCore was designed with Page Object Model in mind, and makes it easy to create an acceptance test pack without the need to write any Selenium code.The repository for this project can be found on GitHub:https://github.com/nhsuk/ui-test-coreExampleThe below example shows how you can create a class representing a web page, in this case a login page.fromuitestcore.pageimportBasePagefromuitestcore.page_elementimportPageElementfromselenium.webdriver.common.byimportByclassMyLoginPage(BasePage):# Define elements to interact withheader_logo=PageElement(By.ID,"company-logo")username_field=PageElement(By.ID,"input-user")password_field=PageElement(By.CLASS_NAME,"field-password")login_button=PageElement(By.XPATH,"//button[text()='Login']")defopen_login_page(self):self.interact.open_url("https://mysite.com/login")self.wait.for_page_to_load()deflogo_visible(self):returnself.interrogate.is_element_visible(self.header_logo)defenter_username(self,username):self.interact.enter_text(self.username_field,username)defenter_password(self,password):self.interact.enter_text(self.password_field,password)defclick_login_button(self):self.interact.click_element(self.login_button)The "BasePage" class is provided so that any page classes in the test pack can inherit from it, giving access to many useful functions which are separated into "find", "interrogate", "interact" and "wait". The "PageElement" class is used to define any elements which your tests need to interact with, so they can be reused without needing to remember whether you're looking for a class, ID etc (all Selenium selector types are supported).The above page class could then be used in the test steps to perform any required actions and assertions.
You must supply aselenium.webdriverdriver object when instantiating the pagelogin_page=MyLoginPage(driver)login_page.open_login_page()InstallationThis package is located on PyPI:https://pypi.org/project/uitestcore/- it can be installed in the usual way i.e.pip install uitestcoreThe easiest way to include this package in your project is by adding it to your requirements.txt.
Here is an example of the line which should be added to this file, we recommend using a specific version but it's your call:uitestcore==10.4.0Using 10.4.0 in Linux and with ChromiumPlease note, that due to a change in Selenium manager between versions 4.10 and 4.11.2, it is now necessary to set a local environment variable which points to the browser installation location.
Failure to do so will result in the browser failing to initialise when running your tests. This is caused by Selenium Manager expecting a 'Chrome' installation; it does not currently
fall back to check for Chromium.Set:ENV SE_BROWSER_PATH=/usr/bin/chromium-browserDeployment to PyPIPyPI deployment is configured in the release pipeline of the NHS.UK Azure Devops project. Any changes merged into master will be automatically deployed to PyPI, and any changes pushed to a branch starting with "test/" will be automatically deployed to TestPyPI.LicenseThis project is licensed under the MIT License - see the LICENSE.md file for detailsDependenciesThe package dependencies along with links to their licenses are as follows:certifi -http://mozilla.org/MPL/2.0/chardet -https://github.com/chardet/chardet/blob/master/LICENSEidna -https://github.com/kjd/idna/blob/master/LICENSE.rstpyhamcrest -https://github.com/hamcrest/PyHamcrest/blob/master/LICENSE.txtpython-dateutil -https://github.com/pganssle/dateutil/blob/master/LICENSErequests -https://github.com/psf/requests/blob/master/LICENSEselenium -https://github.com/SeleniumHQ/selenium/blob/master/LICENSEsix -https://github.com/benjaminp/six/blob/master/LICENSEurllib3 -https://github.com/urllib3/urllib3/blob/master/LICENSE.txtContributeRead ourcontributing guidelinesto contribute to UiTestCore.