Consider using the Selenium DSL in a script driven test. Selenium provides support for Java, Python, Ruby, Groovy, PHP, and C#. Selenium IDE helps get a script-driven test started by exporting to a unit test format. For example, consider the following test in the Selenese table format: Use the Selenium IDE File menu, Export, Python Selenium RC. The list here contains mostly used python selenium commands but not exhaustive. Please feel free to add in comments if you feel something is missing and should be here. Cheat sheet python selenium. Download a Printable PDF of this Cheat Sheet. This would be all for the Selenium cheat sheet. In case you are looking to learn Selenium in-depth then you should definitely check out the Selenium training provided by Intellipaat. In this online training, you will get to learn the automation testing framework for web applications, TDD, selenium.
For Python version the link is here
Install Java
To install Java go to this link
IDE
You can use any text editor. I recommend Eclipse as it is free and have extensive support. For list of popular editors , this are the links
Download Selenium
Download selenium webdriver in this link
Dirty our hands !
Import Selenium
Browsers support (Firefox , Chrome , Internet Explorer, Edge , Opera)
Driver setup:
Chrome:
System.setProperty('webdriver.chrome.driver', “'Path To chromedriver');
To download: Visit Here
Firefox:
System.setProperty('webdriver.gecko.driver', 'Path To geckodriver');
To download: Visit GitHub
Internet Explorer:
System.setProperty('webdriver.ie.driver', 'Path To IEDriverServer.exe');
To download: Visit Here
Edge:
System.setProperty('webdriver.edge.driver', 'Path To MicrosoftWebDriver.exe');
To download: Visit Here
Opera:
System.setProperty('webdriver.opera.driver', 'Path To operadriver');
To download: visit GitHub
Browser Arguments:
–headless
To open browser in headless mode. Works in both Chrome and Firefox browser
–start-maximized
To start browser maximized to screen. Requires only for Chrome browser. Firefox by default starts maximized
–incognito
To open private chrome browser
–disable-notifications
To disable notifications, works Only in Chrome browser
Example:
Alternative
Launch URL
Retrieve Browser Details:
Navigation
Locating Elements
By id
<input id=”login” type=”text” />
By Class Name
<input class=”gLFyf” type=”text” />
By Name
<input name=”z” type=”text” />
By Tag Name
<div id=”login” >…</div>
By Link Text
<a href=”#”>News</a>
By XPath
<form id=”login” action=”submit” method=”get”>
Username: <input type=”text” />
Password: <input type=”password” />
</form>
By CSS Selector
<form id=”login” action=”submit” method=”get”>
Username: <input type=”text” />
Password: <input type=”password” />
</form>
Clicking / Input text
Clicking button
Send Text
Waits
Implicit Waits
An implicit wait instructs Selenium WebDriver to poll DOM for a certain amount of time, this time can be specified, when trying to find an element or elements that are not available immediately.
Explicit Waits
Explicit wait make the webdriver wait until certain conditions are fulfilled . Example of a wait
List of explicit waits
- alertIsPresent()
- elementSelectionStateToBe()
- elementToBeClickable()
- elementToBeSelected()
- frameToBeAvaliableAndSwitchToIt()
- invisibilityOfTheElementLocated()
- invisibilityOfElementWithText()
- presenceOfAllElementsLocatedBy()
- presenceOfElementLocated()
- textToBePresentInElement()
- textToBePresentInElementLocated()
- textToBePresentInElementValue()
- titleIs()
- titleContains()
- visibilityOf()
- visibilityOfAllElements()
- visibilityOfAllElementsLocatedBy()
- visibilityOfElementLocated()
Loading a list of elements like li and selecting one of the element
Read Attribute
Get CSS
CSS values varies on different browser, you may not get same values for all the browser.
Selenium Cheat Sheet Python Tutorial
Capture Screenshot
This will saved the file as in the path of destFile.
isSelected()
isSelected() method in selenium verifies if an element (such as checkbox) is selected or not. isSelected() method returns a boolean.
isDisplayed()
isDisplayed() method in selenium webdriver verifies and returns a boolean based on the state of the element (such as button) whether it is displayed or not.
isEnabled()
is_enabled() method in selenium python verifies and returns a boolean based on the state of the element (such as button) whether it is enabled or not.
Minimum modules to import
Created : 17 December 2019
Acceptance tests are an important final step to take when releasing anything you may have designed, to make sure that the software you have created meets the requirements and specifications laid out when you designed and planned your application or platform. Automated testing is an integral tool to use to efficiently and accurately test your product for release.
In order to write automated web tests that are easy to maintain, perform well, and are ultimately resilient, there are some simple guidelines to follow:
- Write atomic and autonomous tests
- Group like tests together in small batches
- Be descriptive
- Use a Test Runner
- Store tests in a Version Control System
Grouping Tests
As your test suite grows, you will have numerous test files. Each file contains a group of tests that have similar functions. For example, you would have one directory for the files that are designed to locate and interact with the page, and another directory for files that perform tests (test to check if something does or does not happen when you interact).
Test Runners
At the heart of every test suite is some kind of a test runner like Mocha that does a lot of the heavy lifting such as test execution, centralized configuration, and test output. In this course, we will be using the Mocha test runner. Rather than reinvent the wheel, you can use one of the many test runners that exist today. With it you can bolt on third party libraries to extend its functionality if there's something missing.
BDD and TDD
Selenium Cheat Sheet Python 2
Behavior Driven Development and Test Driven Development are two important strategies to help you understand how to write effective tests. BDD is a collaborative process that focuses on starting with a business value or need. It's a feature and epic-centric approach to create a requirements analysis. With both BDD and TDD, you plan to write the code for the test first (application code comes later).
Selenium Cheat Sheet Python Pdf
TDD is a more granular step that should be taken after a BDD plan is created. The general process involves writing a failing test for particular features (determined previously with the BDD process), then the developer writes the code to lead to a successful run of this test. The goal is to be able to write failing tests that can be turned into a passing test with minimal code modification, and no change to dependencies, base pages, or configuration files.