Modifying 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.
To modify the recorded script
- Open the recorded Python script file in an editor.
- Remove the import pytest statement.
- Create an object of the generated class.
For example:
doc_object = TestDoctest(); - 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('') Save the changes that you made to the script file and it is ready to use 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 DesiredCapabilitiesclass 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 DesiredCapabilitiesclass 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('')