Modifying the recorded script exported from Selenium IDE


The Pytest framework is required to execute a Python script recorded in a Selenium IDE. Modify your script to remove this dependency so that the script executes without the Pytest framework.

Before you begin

Make sure that you have the Python script file that you have recorded from the Selenium Integrated Development Environment (IDE).

To modify the recorded script

The following video (1:26) illustrates how you modify a script exported from a Selenium IDE to use in BMC PATROL for Synthetic Monitoring.

icon_play.pngWatch this video to learn how to modify a script exported from a Selenium IDE to use in BMC PATROL for Synthetic Monitoring.

  1. Open the recorded Python script file in an editor.
  2. Remove the import pytest statement.
  3. Create an object of the generated class.
    For example:
    doc_object = TestDoctest();
  4. Use the object to call the methods of the generated class inside the try and finally statements.
    For example:
    try:
        doc_object.setup_method('')
        doc_object.test_doctest()
    finally:
        doc_object.teardown_method('')
  5. Save the changes that you made to the script file and it is ready to use in PATROL for Synthetic Monitoring.

    We suggest you run the modified script file by using the Command Prompt before configuring it in PATROL for Synthetic Monitoring.

The following table shows a recorded script before and after modification:

Before modifying a recorded script

After modifying a recorded script

# 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 TestDoctest():
  def setup_method(self, method):
    self.driver = webdriver.Chrome()    self.vars = {}
  def teardown_method(self, method):
    self.driver.quit()
  def test_doctest(self):
    self.driver.get("
https://docs.bmc.com/docs/")
    self.driver.set_window_size(1146, 634)
    self.driver.find_element(By.CSS_SELECTOR, ".filter").click()
    self.driver.find_element(By.CSS_SELECTOR, ".filter").send_keys("IMrepo")
    self.driver.find_element(By.LINK_TEXT, "Infrastructure Management-PATROL Repository").click()
    self.driver.execute_script("window.scrollTo(0,0)")
    self.driver.execute_script("window.scrollTo(0,0)")

# Generated by Selenium IDE
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 TestDoctest():
  def setup_method(self, method):
    self.driver = webdriver.Chrome()    self.vars = {}
  def teardown_method(self, method):
    self.driver.quit()
  def test_doctest(self):
    self.driver.get("
https://docs.bmc.com/docs/")
    self.driver.set_window_size(1146, 634)
    self.driver.find_element(By.CSS_SELECTOR, ".filter").click()
    self.driver.find_element(By.CSS_SELECTOR, ".filter").send_keys("IMrepo")
    self.driver.find_element(By.LINK_TEXT, "Infrastructure Management-PATROL Repository").click()
    self.driver.execute_script("window.scrollTo(0,0)")
    self.driver.execute_script("window.scrollTo(0,0)")
doc_object = TestDoctest();
try:
    doc_object.setup_method('')
    doc_object.test_doctest()
finally:
    doc_object.teardown_method('')

 

Tip: For faster searching, add an asterisk to the end of your partial query. Example: cert*