Created
July 8, 2021 15:33
-
-
Save y-young/b753b2d2ea1bab21d3d673aabc53da75 to your computer and use it in GitHub Desktop.
Selenium script converter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Selenium IDE Installation: | |
https://www.seleniumhq.org/selenium-ide/docs/en/introduction/getting-started/#installation | |
Usage: | |
python convert.py External_Links_Editor.json5 | |
Output: | |
A Selenium IDE project file External_Links_Editor.side | |
Unsupported commands that need to be converted to alternatives: | |
assertEval | |
clickAndWait | |
''' | |
import json | |
import json5 | |
import sys | |
import uuid | |
def uniqueId() -> str: | |
id = uuid.uuid4() | |
return str(id) | |
def convertCommand(id: str, command: dict) -> dict: | |
command['value'] = command['value'].replace(r'${KEY_BKSP}', r'${KEY_BACKSPACE}') | |
return { | |
'id': id, | |
'comment': '', | |
'command': command['command'], | |
'target': command['target'], | |
'targets': [], | |
'value': command['value'] | |
} | |
def json2Project(data: dict) -> dict: | |
title = data['title'] | |
commands = data['commands'] | |
project = { | |
'id': uniqueId(), | |
'version': '2.0', | |
'name': title, | |
'url': 'http://localhost:5000', | |
'urls': ['http://localhost:5000/'], | |
'plugins': [] | |
} | |
commandResult = list() | |
for command in commands: | |
id = uniqueId() | |
commandResult.append(convertCommand(id, command)) | |
testId = uniqueId() | |
test = { | |
'id': testId, | |
'name': title, | |
'commands': commandResult | |
} | |
project['tests'] = [test] | |
project['suites'] = { | |
'id': uniqueId(), | |
'name': 'Default Suite', | |
'persistSession': False, | |
'parallel': False, | |
'timeout': 900, | |
'tests': [testId] | |
} | |
return project | |
def main(): | |
for filename in sys.argv[1:]: | |
fin = open(filename, 'r', encoding='utf-8') | |
data = fin.read() | |
data = json5.loads(data) | |
fin.close() | |
fout = open(filename.replace('.json5', '.side'), 'w') | |
fout.write(json.dumps(json2Project(data), indent=2)) | |
fout.close() | |
pass | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment