4
4
Works with Katalon Recorder scripts: http://www.katalon.com/automation-recorder
5
5
6
6
Usage:
7
- seleniumbase convert [MY_TEST.py]
7
+ seleniumbase convert [PYTHON_WEBDRIVER_UNITTEST_FILE].py
8
+ (run from anywhere)
8
9
OR
9
- python convert_ide.py [MY_TEST.py] (from the "selenium_ide/"" folder)
10
+ python convert_ide.py [PYTHON_WEBDRIVER_UNITTEST_FILE].py
11
+ (when run from the "selenium_ide/" folder)
10
12
Output:
11
- [MY_TEST_SB.py] (Adds "_SB" to the file name)
13
+ [NEW_FILE_SB].py (adds "_SB" to the original file name)
14
+ (the original file is kept intact)
12
15
"""
13
16
14
17
import codecs
18
21
19
22
def main ():
20
23
expected_arg = ("[A Katalon/Selenium IDE recording exported as "
21
- "a Python-WebDriver script].py" )
24
+ "a Python-WebDriver unittest script].py" )
22
25
num_args = len (sys .argv )
23
26
if sys .argv [0 ].split ('/' )[- 1 ] == "seleniumbase" or (
24
27
sys .argv [0 ].split ('\\ ' )[- 1 ] == "seleniumbase" ):
@@ -29,9 +32,11 @@ def main():
29
32
if num_args < 2 or num_args > 2 :
30
33
raise Exception ('\n * INVALID RUN COMMAND! * Usage:\n '
31
34
'"python convert_ide.py %s"\n ' % expected_arg )
32
- if not sys .argv [num_args - 1 ].endswith ('.py' ):
33
- raise Exception ("Not a Python file!" )
34
35
webdriver_python_file = sys .argv [num_args - 1 ]
36
+ if not webdriver_python_file .endswith ('.py' ):
37
+ raise Exception ("* `%s` is not a Python file! *\n "
38
+ "Expecting: %s\n "
39
+ % (webdriver_python_file , expected_arg ))
35
40
36
41
seleniumbase_lines = []
37
42
seleniumbase_lines .append ("from seleniumbase import BaseCase" )
@@ -47,7 +52,10 @@ def main():
47
52
all_code = f .read ()
48
53
f .close ()
49
54
if "def test_" not in all_code :
50
- raise Exception ("Not a valid Python unittest.TestCase file!" )
55
+ raise Exception ("* `%s` is not a valid Python unittest.TestCase file! "
56
+ "*\n Expecting: %s\n "
57
+ "Did you properly export your Selenium-IDE recording "
58
+ "as a Python WebDriver unittest file?" % expected_arg )
51
59
code_lines = all_code .split ('\n ' )
52
60
for line in code_lines :
53
61
0 commit comments