I have develop around 85 automation scripts using python-selenium-robot framework in pycharm. I need to add one piece of code in all the 85 scripts. Is there way to do it without opening every script and adding? Thanks!
CodePudding user response:
If they are the only files in a folder you can use:
import os
path = 'folder/'
files = os.listdir(path)
for i in files:
with open(files_path i, "a") as fw:
fw.write('\n' 'print(42)')
fw.close()
Otherwise apply some filters on the names
CodePudding user response:
I would suggest you investigate the page object model. The idea is that each page is represented as a separate class. That class has methods that correspond to actions that the user would perform on that page and also contains locators for elements on that page.
This won't help your current situation and will require some probably not insignificant reworking but future updates will be simple. For example, a change to the login page would require changes only in the login_page page object instead of having to edit all 85 scripts.
A reference from the Selenium site, Page object models.