Advertisement
Guest User

Untitled

a guest
Apr 5th, 2020
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.19 KB | None | 0 0
  1. import re
  2.  
  3. def tab_code(txt):
  4.     txt = txt.replace('  ', '    ')
  5.     return txt
  6.  
  7.  
  8. def mod_code(txt):
  9.     test = ''
  10.     for line in txt.splitlines():
  11.         if 'def test_steam(self):' in line:
  12.             test += '    @retry(tries=3, delay=10)' + '\n'
  13.     if 'self.driver.find_element' in line:
  14.           object_type = re.search(r'By\.\w*', line)[0]
  15.           object_name = re.search(r'(, \"#?)([\w|\s]*)', line)[2]
  16.           test += '        ' + f'WebDriverWait(self.driver, 30).until(EC.presence_of_element_located(({object_type}, {object_name}))' + '\n'
  17.     test += line + '\n'
  18.     if line == 'import json':
  19.         test += 'import os' + '\n'
  20.         test += 'from retry import retry' + '\n'
  21.     if 'def setup_method(self, method):' in line:
  22.         test += '        self.path = os.path.join(executable_path=r"C:\\Program Files (x86)\\Webdrivers\\chromedriver.exe")' + '\n'
  23.     test = test.replace('self.driver = webdriver.Chrome()', 'self.driver = webdriver.Chrome(executable_path=self.path)')
  24.     test = test.replace('from selenium.webdriver.support import expected_conditions',
  25.                       'from selenium.webdriver.support import expected_conditions as EC')
  26.     return test
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement