Skip to main content
Version: 3.25

Web environments Executors

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.

info

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

ToolVersion
Chrome4.1.4
Selenium IDE

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:

  1. Recording the template step by step using Selenium IDE
  2. 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:

  1. In your browser, click the icon to open the Selenium IDE extension.
  2. In the window that opens, click on the option Record a new test in a new project.
  3. Enter a name for your project in the PROJECT NAME field. For example: Reddit.
  4. Click the OK button.
  5. 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/.
  6. 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.
  7. From now on, fill in all the fields that the template should follow. In our example from Reddit, the steps are:
    1. Fill in the username and password fields, and click the log in button.
    2. Navigate to the Change Password page.
    3. Fill in the Previous password, New password, Confirm new password fields and click on the Save button.
      RECOMMENDATION

      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.

  8. 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.
  9. In the upper-right corner, click on the Stop recording icon and fill in the TEST NAME field. For example: Reddit password change.
  10. On the left side, click on the test you created with the right mouse button and choose the Export option.
  11. Among the options presented, select the language Python pytest and click on the Export button.
  12. Save the file to your computer.
IMPORTANT

For the automation to work correctly, the site on which you want to run the template cannot have Dual Factor Authentication enabled.

TIP

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 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:

  1. 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

test_redditpasswordchange.py
# 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\']")))

  1. 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\']")))

  1. 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\']")))

  1. 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:

FunctionDescription
self.driver.*Commands for manipulating browser elements simulating the user. Can be used as diver.* as well.

Usage example: self.driver.get("https://instagram.com")

Learn more: Selenium webdrivers
WebDriverWaitMakes 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
ActionChainsActionChains 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
printPrints a message during template execution. You can use it to make markups during execution.

Usage example: print("Your message here")

Learn more: Python Outputs
timeoutWait for a determined time in seconds before continuing the execution.

Usage example: timeout(15)