- 5 minutes to read
- Print
- DarkLight
- PDF
Web environments executors
- 5 minutes to read
- Print
- DarkLight
- PDF
cURL
Executor for requests to simple web pages. Pages without JavaScript environment or HTML events. You can use this executor for legacy systems based on pure HTML4 architecture;
HTTP
Executor for requests to complex web pages where more interactivity using JavaScript elements and event triggers are required;
Selenium
Selenium is a web application automation solution created with the objective of supporting teams during automated tests, simulating a user.
For information, access the official documentation of Selenium.
Through this executor it is possible to create templates using Python scripts to automate password changes in web applications such as Instagram, Facebook, Gmail etc.
For users who are not familiar with the Python language, it is possible to use the Selenium IDE extension for Google Chrome or Firefox. While the user browses the web application, all steps and information entered are captured and converted into a script that can be used as a template in senhasegura.
Embedded browser version
Tool | Version |
---|---|
Chrome | 4.1.4 |
To learn more about Selenium IDE, see the official page at Selenium IDE.
Create template for Selenium executor
Creating templates for the Selenium executor is divided into two steps:
- Recording the template step by step using Selenium IDE
- Creation of the template in senhasegura
Record step by step with Selenium IDE
To create the template, we will use the Selenium IDE extension for browsers. It automates the creation of the template by recording all clicks and filling of fields as the user browses the site.
After installing the extension in your browser, follow the steps below:
- In your browser, click the icon to open the Selenium IDE extension.
- In the window that opens, click on the option Record a new test in a new project.
- Enter a name for your project in the PROJECT NAME field. For example: Reddit.
- Click the OK button.
- In the BASE URL field, enter the URL of the login page of the website for which you want to create the template. For example: https://www.reddit.com/account/login/.
- Click the START RECORDING button. This will use the address entered in the BASE URL to open in a new window. From this point on, all clicks and information entered in the fields will be captured by the Selenium IDE.
- From now on, fill in all the fields that the template should follow. In our example from Reddit, the steps are:
- Fill in the username and password fields, and click the log in button.
- Navigate to the Change Password page.
- Fill in the Previous password, New password, Confirm new password fields and click on the Save button.
We recommend that, as a way of validating the new password, after changing it, you log out and log in again with it to ensure that the change was successful.
- After following all the steps to change the password on the site for which you want to create the template, return to the Selenium IDE window.
- In the upper-right corner, click on the Stop recording icon and fill in the TEST NAME field. For example, Reddit password change.
- On the left side, click on the test you created with the right mouse button and choose the Export option.
- Among the options presented, select the language Python pytest and click on the Export button.
- Save the file to your computer.
For the automation to work correctly, the site you want to run the template cannot have Dual Factor Authentication enabled.
You can validate your script by clicking the Run current test action in Selenium IDE before exporting it. For this, you will need to change the Value column of the passwords, as they were changed in the script creation process.
Create a template in senhasegura
Now that we have the file with the steps that the template should have, let's add it to senhasegura. To do this, follow the steps below:
- Open the
.py
file that you saved in the previous step in any text editor. It could even be Notepad. In our Reddit example, the content will look like this:
Open Code
# Generated by Selenium IDE
import pytest
import time
import json
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
class TestRedditpasswordchange():
def setup_method(self, method):
self.driver = webdriver.Chrome()
self.vars = {}
def teardown_method(self, method):
self.driver.quit()
def test_redditpasswordchange(self):
self.driver.get("https://www.reddit.com/account/login/")
self.driver.set_window_size(1920, 1030)
self.driver.find_element(By.ID, "loginUsername").click()
self.driver.find_element(By.ID, "loginUsername").send_keys("username")
self.driver.find_element(By.ID, "loginPassword").click()
self.driver.find_element(By.ID, "loginPassword").send_keys("OldPassword")
self.driver.find_element(By.ID, "loginPassword").send_keys(Keys.ENTER)
self.driver.get("https://reddit.com/change_password")
self.driver.find_element(By.ID, "old_password").click()
self.driver.find_element(By.ID, "old_password").send_keys("OldPassword")
self.driver.find_element(By.ID, "password").click()
self.driver.find_element(By.ID, "password").send_keys("NewPassword")
self.driver.find_element(By.ID, "password2").click()
self.driver.find_element(By.ID, "password2").send_keys("NewPassword")
self.driver.find_element(By.ID, "password2").send_keys(Keys.ENTER)
WebDriverWait(driver, 30).until(expected_conditions.presence_of_element_located((By.XPATH, "//button[@id=\'USER_DROPDOWN_ID\']")))
- Copy the content from the line where the address entered in BASE URL is. In our example, it will be from line 22:
Open Code
self.driver.get("https://www.reddit.com/account/login/")
self.driver.set_window_size(1920, 1030)
self.driver.find_element(By.ID, "loginUsername").click()
self.driver.find_element(By.ID, "loginUsername").send_keys("username")
self.driver.find_element(By.ID, "loginPassword").click()
self.driver.find_element(By.ID, "loginPassword").send_keys("OldPassword")
self.driver.find_element(By.ID, "loginPassword").send_keys(Keys.ENTER)
self.driver.get("https://reddit.com/change_password")
self.driver.find_element(By.ID, "old_password").click()
self.driver.find_element(By.ID, "old_password").send_keys("OldPassword")
self.driver.find_element(By.ID, "password").click()
self.driver.find_element(By.ID, "password").send_keys("NewPassword")
self.driver.find_element(By.ID, "password2").click()
self.driver.find_element(By.ID, "password2").send_keys("NewPassword")
self.driver.find_element(By.ID, "password2").send_keys(Keys.ENTER)
WebDriverWait(driver, 30).until(expected_conditions.presence_of_element_located((By.XPATH, "//button[@id=\'USER_DROPDOWN_ID\']")))
- To be able to use this template in senhasegura, simply replace the fields with the variables that must be filled in automatically during the password change process. See an example:
Open Code
self.driver.get("https://www.reddit.com/account/login/")
self.driver.set_window_size(1920, 1030)
self.driver.find_element(By.ID, "loginUsername").click()
self.driver.find_element(By.ID, "loginUsername").send_keys("[#USERNAME#]")
self.driver.find_element(By.ID, "loginPassword").click()
self.driver.find_element(By.ID, "loginPassword").send_keys("[#CURRENT_PASSWORD#]")
self.driver.find_element(By.ID, "loginPassword").send_keys(Keys.ENTER)
self.driver.get("https://reddit.com/change_password")
self.driver.find_element(By.ID, "old_password").click()
self.driver.find_element(By.ID, "old_password").send_keys("[#CURRENT_PASSWORD#]")
self.driver.find_element(By.ID, "password").click()
self.driver.find_element(By.ID, "password").send_keys("[#NEW_PASSWORD#]")
self.driver.find_element(By.ID, "password2").click()
self.driver.find_element(By.ID, "password2").send_keys("[#NEW_PASSWORD#]")
self.driver.find_element(By.ID, "password2").send_keys(Keys.ENTER)
WebDriverWait(driver, 30).until(expected_conditions.presence_of_element_located((By.XPATH, "//button[@id=\'USER_DROPDOWN_ID\']")))
- Now, your code is ready to be used in your password change template. Select Selenium executor when Creating your template
Functions you can use in the templates
You can use in your template all the commands available for the driver.*
(or self.driver.*
) class. Check the list of available commands in Official Selenium documentation.
Check the list of functions that can be used in your template:
Function | Description |
---|---|
self.driver.* | Commands for manipulating browser elements simulating the user. It can be used as diver.* as well.Usage example: self.driver.get("https://instagram.com") Learn more: Selenium webdrivers |
WebDriverWait | Makes the Driver wait until a condition is true. You can use it to check if any page element has already been loaded, such as, for example, a login form field. Usage example: WebDriverWait(self.driver, 30).until(expected_conditions.presence_of_element_located((By.ID, "username"))) Learn more: Selenium Waits |
ActionChains | ActionChains are a way to automate low-level interactions such as mouse movements, mouse button actions, keystrokes, and context menu interactions. This is useful for performing more complex actions such as hovering and dragging and dropping. Usage example: ActionChains(driver).move_to_element(menu).click(hidden_submenu).perform() Learn more: Selenium Action Chains |
Prints a message during template execution. You can use it to make markups during execution. Usage example: print("Your message here") Learn more: Python Outputs | |
timeout | Wait for a determined time in seconds before continuing the execution. Usage example: timeout(15) |