Package: pyleniumio
Pylenium: Easy Python Web Test AutomationThe MissionTest ExamplePurposeQuickstart1. Install2. Initialize3. Write a Test4. Run the TestContributeThe mission is simpleBring the best of Selenium, Cypress and Python into one package.This means:Automatic waiting and synchronizationQuick setup to start writing testsEasy to use and clean syntax for amazing readability and maintainabilityAutomatic driver installation so you don't need to manage driversLeverage the awesome Python languageand more!Test ExampleAlthough Pylenium is a thin wrapper of Selenium, let's use this simple scenario to show the difference between usingSeleniumandPylenium:Visitthe QA at the Point website:https://qap.devHoverthe About link to reveal a menuClickthe Leadership link in that menuAssertCarlos Kidman is on the Leadership pagedeftest_carlos_is_on_leadership(py):py.visit('https://qap.dev')py.get('a[href="/about"]').hover()py.get('a[href="/leadership"][class^="Header-nav"]').click()assertpy.contains('Carlos Kidman')fromseleniumimportwebdriverfromselenium.webdriver.common.action_chainsimportActionChainsfromselenium.webdriver.common.byimportByfromselenium.webdriver.supportimportexpected_conditionsasECfromselenium.webdriver.support.waitimportWebDriverWait# define your setup and teardown fixture@pytest.fixturedefdriver():driver=webdriver.Chrome()yielddriverdriver.quit()deftest_carlos_is_on_leadership_page_with_selenium(driver):wait=WebDriverWait(driver,timeout=10)driver.get('https://qap.dev')# hover About linkabout_link=driver.find_element(By.CSS_SELECTOR,"a[href='/about']")actions=ActionChains(driver)actions.move_to_element(about_link).perform()# click Leadership link in About menuwait.until(EC.visibility_of_element_located((By.CSS_SELECTOR,"a[href='/leadership'][class^='Header-nav']"))).click()# check if 'Carlos Kidman' is on the pageassertwait.until(lambda_:driver.find_element(By.XPATH,"//*[contains(text(), 'Carlos Kidman')]"))PurposeI teach courses and do trainings for bothSeleniumandCypress, but Selenium, out of the box,feelsclunky. When you start at a new place, you almost always need to "setup" the framework from scratch all over again. Instead of getting right to creating meaningful tests, you end up spending most of your time building a custom framework, maintaining it, and having to teach others to use it.Also, many people blame Selenium for bad or flaky tests. This usually tells me that they have yet to experience someone that truly knows how to make Selenium amazing! This also tells me that they are not aware of the usual root causes that make Test Automation fail:Poor programming skills, test design and practicesFlaky applicationsComplex frameworksWhat if we tried to get the best from both worlds and combine it with an amazing language?Seleniumhas done an amazing job of providing W3C bindings to many languages and makes scaling a breeze.Cypresshas done an amazing job of making the testing experience more enjoyable - especially for beginners.Pyleniumlooks to bring more Cypress-like bindings and techniques to Selenium (like automatic waits) and still leverage Selenium's power along with the ease-of-use and power ofPython.Quick StartTheOfficial Pylenium Docsare the best place to start, but you can quickly get going with the following steps:1. Installpyleniumiopipinstallpyleniumio---or---pipenvinstallpyleniumio---or---poetryaddpyleniumio2. Initialize Pylenium# execute at your Project RootpyleniuminitThis creates three files:conftest.py- This has the fixtures needed for Pyleniumpylenium.json- This is the config file for Pyleniumpytest.ini- This is the config file for pytestBy default, Pylenium uses the Chrome browser. You have to install Chrome or update thepylenium.jsonfile to use the browser of your choice.3. Write a testCreate a directory calledtestsand then a test file calledtest_google.pyDefine a new test calledtest_google_searchdeftest_google_search(py)Pylenium usespytestas the Test Framework. You only need to pass inpyto the function!Now we can usePylenium Commandsto interact with the browser.deftest_google_search(py):py.visit('https://google.com')py.get("[name='q']").type('puppies')py.get("[name='btnK']").submit()assertpy.should().contain_title('puppies')4. Run the TestThis will depend on your IDE, but you can always run tests from the CLI:python-mpytesttests/test_google.pyYou're all set! You should see the browser open and complete the commands we had in the test :)ContributePylenium usesGitpodto make it easy to work on it from thedesktop or browserwithout having to worry about the setup like having the correct Python version installed after cloning the repo.💡 With a single click, you can open the repo in your browser, make your changes, then submit a pull request!If you're new to Gitpod, check out theirGetting Starteddocs to see how to use itVisitPylenium's repoand click theGitpodbutton to open the repo in a VS Code browser windowWait for Gitpod to set up the project. You'll see things get setup from the various.gitpod*files at the Project RootOnce complete, create a new branch and start making your changesWhen ready, submit a Pull Request!Reviewers will see your CI pipeline and even be able to open your Gitpod instance if needed - making collaboration much easierGitpod instances are ephemeral, so you can create, share, and delete them as needed🧪 By default, UI tests executed in Gitpod are headless. If you'd like to see UI tests run, open port6080from the bottom right corner of VS Code.For more details and other ways to contribute to Pylenium, visit theCONTRIBUTING.mddoc 👀