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
Oct 08, 2020 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.
- Although Selenium supports various programming languages (C#, Java, Perl, PHP, Python & Ruby etc.) but this cheat sheet has exmples using only Java. Loading a web page in current browser window Here is a list of possible ways to load web page.
- Cheat Sheet 6: All Selenium. This cheat sheet uses the most frequently used Selenium and Python. It will give you clear instructions for Auto downloading, locating elements, and reading browser details. It has a list of Python Selenium commands for operations on elements including code snippets so you can if you are doing it right.
Each test needs to be concise (e.g., testing a single feature rather than multiple features) and be capable of being run independently (e.g., sets up its own data rather than relying on a previous test to do it). Learn more in the Sauce Cookbook.
Doing this may require a mental shift, discipline, and more upfront effort, but it will make a dramatic impact on the quality, effectiveness, and maintainability of your tests, especially when you get into parallel test execution.
Image Source: Medium Article
Being Descriptive
A test file should have a high level name that describes what the group of tests within it are doing. Each individual test with the test files should also have an informative name to describe the action each test is taking. In this case, descriptive names are better than concise names. Also, each test or grouping of tests should include some helpful tags or categories, which can provide additional information about the test as well as enable flexible test execution. This way, you can run all or part of your test suite, and the results will inform the tester what is being tested, as well as accurately identify what goes wrong.
This also enables developers to run a subset of tests to exercise functionality they just modified and enable you to use a Continuous Integration (CI) server to run the right groups of tests at the right time for fast and dynamic feedback. It is helpful to be able to identify which tests you run when you only make changes to certain parts of an application. You may also want to have a subset of tests that is run regularly, on a nightly or weekly basis, to verify performance regularly, so using a certain category of tests for a regular test deployment can be helpful.
BDD and TDD
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).
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.
Here you will learn how to control any browser application with a little Python and selenium. You can use this for creating your own Instagram Bot for example. We start with a few basics and end with a cheat sheet summarizing the most important code snippets. Let’s go!
One way to automate the tasks that are performed in the browser is to use a program that “records” your activities on the website and can play them back as often as you like. No coding is needed for this. Correspondingly stupidly the program executes its steps.
You can find a Chrome extension here, that allows you to record and play your tasks. Now this works for logging into Instagram well, but we need some kind of programming to make our automation a bit smarter.
Below I have added an example of how such a login via Selenium might look like. He notes all necessary HTML IDs to be able to access them directly later. If Instagram should change the IDs at a later time, the user will surely not notice it. The bot will still not find the individual parts again and will fail.
First of all. We will not directly control the browser. We will write a script that uses a web driver to control a browser. For example, our Python script will use a ChromeDriver to control the web browser Google Chrome.
So we need Selenium and a Webdriver.
- Selenium: You can install selenium via “pip3 install selenium” inside for example Powershell.
- Webdriver: You can download it from the SeleniumHQ Website for your preferred Browser.
When using the program, you can set the path to the driver like this (Old way):
There is a better way to start. Create a new python Script and let it download and set chromedriver by itself. For that, we need “webdriver manager”:
Is this installed, you can now create a little Python file and run it to open a specific Website. In my case Instagram:
You can see the whole HTML Code right inside the Browser. Just right click and click “inspect”. You can also press “Ctrl + Shift + I”. You can use this to see all the IDs and points we will use to automate.
Selenium Webdriver Python Cheat Sheet
In Python, you now can use the “driver.find_element” to address exactly one spot. By their specific name or class or ID. Whatever suits you the most:
In my case, the Button doesn’t have any ID. So I have to target it via the “XPath” and search for the text inside the button. Each element has its own path. We can either search using the absolute path, which would result in errors if we changed the website structure. Or we search within our specified path for a word. Here the structure of the website can change as much as it wants, our word is always found.
In our case, it’s the word “next”. This way we can make sure that we notice when Instagram changes something as soon as possible because you have to change it so that it is changed for the user.
How to find your XPath and use it inside your Script
Yahoo Fantasy Football Cheat Sheets
You now can find and click the button via the text the user can see, or via the XPath, you have copied above. The following Script will open Instagram, and waits 5 seconds till it clicks the Next Button. Of course, it won’t log in, because there is no data typed in.
xxx will be your variable which contains the XPath or name. In our Example above it would be “python_button”.
Radio Button | xxx.click() |
Click Checkbox | |
Click Button | |
Textfield | xxx.send_keys(“Hello World!”) |
Getting Text | xxx.get_attribute(“text”) |
Dropdown by visible text | xxx.select_by_visible_text(‘Germany’) |
Dropdown by value | xxx.select_by_value(‘1’) |