1
# coding=utf-8
2

3 1
import ast
4 1
import astunparse
5 1
import os
6

7 1
from bzt import TaurusConfigError
8 1
from tests.unit import RESOURCES_DIR
9 1
from tests.unit.modules.selenium import SeleniumTestCase
10

11

12 1
class TestSeleniumScriptGeneration(SeleniumTestCase):
13

14 1
    def test_modern_actions_generator(self):
15 1
        self.configure({
16
            "execution": [{
17
                "executor": "apiritif",
18
                "hold-for": "4m",
19
                "ramp-up": "3m",
20
                "scenario": "loc_sc"}],
21
            "scenarios": {
22
                "loc_sc": {
23
                    "default-address": "http://blazedemo.com",
24
                    "variables": {
25
                        "red_pill": "take_it",
26
                        "name": "Name"
27
                    },
28
                    "timeout": "3.5s",
29
                    "requests": [{
30
                        "label": "la-la",
31
                        "assert": [{
32
                            "contains": ['contained_text'],
33
                            "not": True
34
                        }],
35
                        "actions": [
36
                            # windows
37
                            "switchWindow(0)",
38
                            "openWindow(some.url)",
39
                            "resizeWindow(750, 750)",
40
                            "maximizeWindow()",
41
                            "closeWindow()",
42
                            "closeWindow('win_ser_local')",
43

44
                            # frames
45
                            "switchFrameByIdx(1)",
46
                            "switchFrame(relative=parent)",
47
                            "switchFrameByName('my_frame')",
48

49
                            # chains
50
                            "mouseDownByXPath(/html/body/div[3]/form/select[1])",
51
                            "mouseOutById(id_abc)",
52
                            "mouseOverByName(name_abc)",
53

54
                            # drag, select, assert, store
55
                            {"dragByID(address)": "elementByName(toPort)"},
56
                            {"selectByName(my_frame)": "London"},
57
                            "assertTitle(BlazeDemo)",
58
                            {"storeTitle()": "hEaDeR"},
59
                            {"storeString(Title_Basic_By)": "Final"},
60
                            {"assertValueByID(address)": "123 Beautiful st."},
61
                            {"storeTextByID(address)": "Basic"},
62

63
                            # click, type, keys, submit
64
                            {"typeByName(\"toPort\")": "B"},
65

66
                            # exec, rawcode, go, edit
67
                            "scriptEval(\"alert('This is Sparta');\")",
68
                            {"rawCode": "for i in range(10):\n  if i % 2 == 0:\n    print(i)"},
69
                            "go(http:\\blazemeter.com)",
70
                            {"editContentById(editor)": "lo-la-lu"},
71

72
                            # print, wait, pause, clearcookies, screenshot
73
                            "echoString(${red_pill})",
74
                            {"waitByName('toPort')": "visible"},
75
                            "pauseFor(4.6s)",
76
                            "clearCookies()",
77
                            "screenshot('screen.png')",
78
                            "screenshot()"
79
                        ]}]}}})
80

81 1
        self.obj.prepare()
82 1
        with open(self.obj.script) as fds:
83 1
            content = fds.read()
84

85 1
        print_i = "print(i)"
86

87 1
        self.assertNotIn(content, "self.dlg_mng = DialogsManager(self.driver)")
88

89 1
        target_lines = [
90
            "switch_window('0')",
91
            "open_window('some.url')",
92
            "close_window()",
93
            "close_window('win_ser_local')",
94
            "switch_frame('index=1')",
95
            "switch_frame('relative=parent')",
96
            "ActionChains(self.driver).click_and_hold(self.driver.find_element(var_loc_chain[0], "
97
            "var_loc_chain[1])).perform()",
98
            "ActionChains(self.driver).move_to_element_with_offset(self.driver.find_element(var_loc_chain[0],"
99
            "var_loc_chain[1])",
100
            "ActionChains(self.driver).move_to_element(self.driver.find_element(var_loc_chain[0],"
101
            "var_loc_chain[1])).perform()",
102
            "ActionChains(self.driver).drag_and_drop(self.driver.find_element(source[0], source[1]),"
103
            "self.driver.find_element(target[0],target[1])).perform()",
104
            "Select(self.driver.find_element(var_loc_select[0],var_loc_select[1])).select_by_visible_text",
105
            "self.assertEqual(self.driver.title,'BlazeDemo')",
106
            "self.vars['hEaDeR'] = self.driver.title",
107
            "self.vars['Final'] = 'Title_Basic_By'",
108
            "self.vars['Basic'] = self.driver.find_element(var_loc_as[0],var_loc_as[1])."
109
            "get_attribute('innerText')",
110
            "self.assertEqual(self.driver.find_element(var_loc_as[0],var_loc_as[1])."
111
            "get_attribute('value').strip(),\'123 Beautiful st.\'.strip())",
112
            "self.driver.find_element(var_loc_keys[0],var_loc_keys[1]).clear()",
113
            "send_keys(var_loc_keys,'B')",
114
            "self.driver.execute_script(\"alert('This is Sparta');\")",
115
            "for i in range(10):",
116
            "if ((i % 2) == 0):",
117
            print_i,
118
            "self.driver.get(\'http:\\\\blazemeter.com\')",
119
            "ifself.driver.find_element(var_edit_content[0], var_edit_content[1])."
120
            "get_attribute('contenteditable'):"
121
            "self.driver.execute_script((\"arguments[0].innerHTML=\'%s\';\"%\'lo-la-lu\'),"
122
            "self.driver.find_element(var_edit_content[0],var_edit_content[1]))"
123
            "else:",
124
            "raiseNoSuchElementException((\'The element (%s : %r)is not a contenteditable element\'%"
125
            "(var_edit_content[0], var_edit_content[1])))"
126
            "print(self.vars['red_pill'])",
127
            "wait_for('visible', [{'name': 'toPort'}], 3.5)"
128
            "sleep(4.6)",
129
            "self.driver.delete_all_cookies()",
130
            "self.driver.save_screenshot('screen.png')",
131
            "filename = os.path.join(os.getenv('TAURUS_ARTIFACTS_DIR'), "
132
            "('screenshot-%d.png' % (time() * 1000)))",
133
            "self.driver.save_screenshot(filename)"
134
        ]
135

136 1
        for idx in range(len(target_lines)):
137 1
            self.assertIn(TestSeleniumScriptGeneration.clear_spaces(target_lines[idx]),
138
                          TestSeleniumScriptGeneration.clear_spaces(content),
139
                          msg="\n\n%s. %s" % (idx, target_lines[idx]))
140

141 1
    @staticmethod
142 1
    def clear_spaces(content):
143 1
        return content.replace(" ", "").replace("\t", "").replace("\n", "")
144

145 1
    def test_firefox_setup_generator(self):
146 1
        self.configure({
147
            "execution": [{
148
                "executor": "selenium",
149
                "hold-for": "4m",
150
                "ramp-up": "3m",
151
                "scenario": "loc_sc"}],
152
            "scenarios": {
153
                "loc_sc": {
154
                    "headless": True,
155
                    "default-address": "http://blazedemo.com",
156
                    "variables": {
157
                        "red_pill": "take_it",
158
                        "name": "Name"
159
                    },
160
                    "timeout": "3.5s",
161
                    "requests": [{
162
                        "url": "bla.com",
163
                        "assert": [{
164
                            "contains": ['contained_text'],
165
                            "not": True
166
                        }],
167

168
                    }]}}})
169

170 1
        self.obj.prepare()
171 1
        with open(self.obj.script) as fds:
172 1
            content = fds.read()
173

174 1
        target_lines = [
175
            "options = webdriver.FirefoxOptions()",
176
            "options.set_headless()",
177
            "profile = webdriver.FirefoxProfile()",
178
            "profile.set_preference('webdriver.log.file', '",
179
            "driver = webdriver.Firefox(profile, options=options)"
180
        ]
181

182 1
        for idx in range(len(target_lines)):
183 1
            self.assertIn(target_lines[idx], content, msg="\n\n%s. %s" % (idx, target_lines[idx]))
184

185 1
    def test_chrome_setup_generator(self):
186 1
        self.configure({
187
            "execution": [{
188
                "executor": "selenium",
189
                "hold-for": "4m",
190
                "scenario": "loc_sc"}],
191
            "scenarios": {
192
                "loc_sc": {
193
                    'generate-flow-markers': True,
194
                    "browser": "Chrome",
195
                    "default-address": "http://blazedemo.com",
196
                    "variables": {
197
                        "red_pill": "take_it",
198
                        "name": "Name"
199
                    },
200
                    "timeout": "3.5s",
201
                    "requests": [{
202
                        "url": "bla.com",
203
                        "assert": [{
204
                            "contains": ['contained_text'],
205
                            "not": True
206
                        }],
207

208
                    }]}}})
209

210 1
        self.obj.prepare()
211 1
        with open(self.obj.script) as fds:
212 1
            content = fds.read()
213

214 1
        self.assertNotIn("options.set_headless()", content)
215

216 1
        target_lines = [
217
            "options = webdriver.ChromeOptions()",
218
            "driver = webdriver.Chrome(service_log_path='",
219
            "', options=options)"
220
        ]
221

222 1
        for idx in range(len(target_lines)):
223 1
            self.assertIn(target_lines[idx], content, msg="\n\n%s. %s" % (idx, target_lines[idx]))
224

225 1
    def test_build_script(self):
226 1
        self.configure({
227
            "execution": [{
228
                "executor": "selenium",
229
                "hold-for": "4m",
230
                "ramp-up": "3m",
231
                "scenario": "loc_sc"}],
232
            "scenarios": {
233
                "loc_sc": {
234
                    "data-sources": [{"path": "first.csv", "loop": True}, "second.csv"],
235
                    "default-address": "http://blazedemo.com",
236
                    "variables": {
237
                        "red_pill": "take_it",
238
                        "name": "Name"
239
                    },
240
                    "timeout": "3.5s",
241
                    "requests": [{
242
                        "url": "/",
243
                        "assert": [{
244
                            "contains": ['contained_text'],
245
                            "not": True
246
                        }],
247
                        "actions": [
248
                            "waitByXPath(//input[@type='submit'])",
249
                            {"waitForByXPath(//input[@name='test,name'], present)": "1m20s"},
250
                            "assertTitle(BlazeDemo)",
251
                            "mouseMoveByXPath(/html/body/div[2]/div/p[2]/a)",
252
                            "doubleClickByXPath(/html/body/div[3]/h2)",
253
                            "contextClickByXPath(/html/body/div[3]/form/select[1])",
254
                            "mouseDownByXPath(/html/body/div[3]/form/select[1])",
255
                            "mouseUpByXPath(/html/body/div[3]/form/select[1]/option[6])",
256
                            {"selectByName(toPort)": "London"},
257
                            {"keysByCSS(body input.btn.btn-primary)": "KEY_ENTER"},
258
                            {"assertValueByID(address)": "123 Beautiful st."},
259
                            {"assertTextByXPath(/html/body/div[2]/form/div[1]/label)": "${name}"},
260
                            {"waitByName('toPort')": "visible"},
261
                            {"keysByName(\"toPort\")": "B"},
262
                            {"typeByName(\"toPort\")": "B"},
263
                            {"keysByName(\"toPort\")": u"KEY_ENTER"},
264
                            {"typeByName(\"toPort\")": "KEY_ENTER"},
265
                            "clickByXPath(//div[3]/form/select[1]//option[3])",
266
                            "clickByXPath(//div[3]/form/select[2]//option[6])",
267
                            "switchWindow(0)",
268
                            "openWindow(some.url)",
269
                            "switchWindow('win_ser_local')",
270
                            "switchWindow('win_ser_1')",
271
                            "switchWindow('that_window')",
272
                            "closeWindow(1)",
273
                            "closeWindow('win_ser_local')",
274
                            "closeWindow('win_ser_1')",
275
                            "closeWindow('that_window')",
276
                            "submitByName(\"toPort\")",
277
                            "scriptEval(\"alert('This is Sparta');\")",
278
                            {"rawCode": "for i in range(10):\n  if i % 2 == 0:\n    print(i)"},
279
                            {"dragByID(address)": "elementByName(toPort)"},
280
                            "switchFrameByName('my_frame')",
281
                            "switchFrame('top_frame')",
282
                            "switchFrameByXpath(//*[@id='result'])",
283
                            "switchFrameByCSS(.my_class)",
284
                            "switchFrameById(frame_id)",
285
                            "switchFrameByIdx(1)",
286
                            "switchFrame(relative=parent)",
287
                            {"editContentById(editor)": "lo-la-lu"},
288
                            "pauseFor(3.5s)",
289
                            "clearCookies()",
290
                            "clickByLinkText(destination of the week! The Beach!)",
291
                            {"storeTitle()": "Title"},
292
                            {"storeTextByXPath(//*[@id='basics']/h2)": "Basic"},
293
                            {"storeValueByXPath(//*[@id='basics']/h1)": "World"},
294
                            {"storeString(${Title} ${Basic} by ${By})": "Final"},
295
                            {"storeEval(0 == false)": "var_eval"},
296
                            "assertEval(10 === 2*5)",
297
                            "go(http:\\blazemeter.com)",
298
                            {"assertDialog(alert)": "Alert Message"},
299
                            {"assertDialog(prompt)": "Enter value"},
300
                            {"assertDialog(confirm)": "Are you sure?"},
301
                            {"answerDialog(prompt)": "myvalue"},
302
                            {"answerDialog(confirm)": "#Ok"},
303
                            {"answerDialog(alert)": "#Ok"},
304
                            "echoString(${red_pill})",
305
                            "screenshot(screen.png)",
306
                            "screenshot()",
307
                        ],
308
                    },
309
                        {"label": "empty"}
310
                    ]
311
                },
312
                "loc_sc_remote": {
313
                    "remote": "http://user:key@remote_web_driver_host:port/wd/hub",
314
                    "capabilities": {
315
                        "browserName": "firefox",
316
                        "version": "54.0",
317
                        "platformName": "linux",
318
                        "javascriptEnabled": "True",
319
                        "platformVersion": "",
320
                        "seleniumVersion": "",
321
                        "deviceName": "",
322
                        "app": ""
323
                    },
324
                    "default-address": "http://blazedemo.com",
325
                    "timeout": "3.5s",
326
                    "requests": [{
327
                        "url": "/",
328
                        "assert": [{
329
                            "contains": ['contained_text'],
330
                            "not": True
331
                        }],
332
                        "actions": [
333
                            "waitByXPath(//input[@type='submit'])",
334
                            "assertTitle(BlazeDemo)"
335
                        ],
336
                    },
337
                        {"label": "empty"}
338
                    ]
339
                }
340
            }
341
        })
342

343
        # it changes default of data-source loop parameter to 'false' (see second.csv params)
344 1
        self.obj.engine.aggregator.is_functional = True
345

346 1
        self.obj.prepare()
347 1
        exp_file = RESOURCES_DIR + "selenium/generated_from_requests.py"
348 1
        str_to_replace = (self.obj.engine.artifacts_dir + os.path.sep).replace('\\', '\\\\')
349 1
        self.assertFilesEqual(exp_file, self.obj.script, str_to_replace, "/somewhere/", python_files=True)
350 1
        with open(self.obj.script) as script:
351 1
            self.assertIn("bzt.resources.selenium_extras", script.read())
352

353 1
    def test_headless_default(self):
354 1
        self.configure({
355
            "execution": [{
356
                "executor": "selenium",
357
                "scenario": "loc_sc"}],
358
            "scenarios": {
359
                "loc_sc": {
360
                    "browser": "Chrome",
361
                    "requests": ["http://blazedemo.com/"]
362
                }}})
363

364 1
        self.obj.prepare()
365 1
        with open(self.obj.script) as generated:
366 1
            gen_contents = generated.read()
367

368 1
        self.assertNotIn("options.set_headless()", gen_contents)
369

370 1
    def test_headless_chrome(self):
371 1
        self.configure({
372
            "execution": [{
373
                "executor": "selenium",
374
                "scenario": "loc_sc"}],
375
            "scenarios": {
376
                "loc_sc": {
377
                    "browser": "Chrome",
378
                    "headless": True,
379
                    "requests": ["http://blazedemo.com/"]
380
                }}})
381

382 1
        self.obj.prepare()
383 1
        with open(self.obj.script) as generated:
384 1
            gen_contents = generated.read()
385

386 1
        self.assertIn("options.set_headless()", gen_contents)
387

388 1
    def test_headless_firefox(self):
389 1
        self.configure({
390
            "execution": [{
391
                "executor": "selenium",
392
                "scenario": "loc_sc"}],
393
            "scenarios": {
394
                "loc_sc": {
395
                    "browser": "Firefox",
396
                    "headless": True,
397
                    "requests": ["http://blazedemo.com/"]
398
                }}})
399

400 1
        self.obj.prepare()
401 1
        with open(self.obj.script) as generated:
402 1
            gen_contents = generated.read()
403

404 1
        self.assertIn("options.set_headless()", gen_contents)
405

406 1
    def test_headless_safari(self):
407 1
        self.configure({
408
            "execution": [{
409
                "executor": "selenium",
410
                "scenario": "loc_sc"}],
411
            "scenarios": {
412
                "loc_sc": {
413
                    "browser": "Opera",
414
                    "headless": True,
415
                    "requests": ["http://blazedemo.com/"]
416
                }}})
417

418 1
        self.obj.prepare()
419 1
        with open(self.obj.script) as generated:
420 1
            gen_contents = generated.read()
421

422 1
        self.assertNotIn("options.set_headless()", gen_contents)
423

424 1
    def test_capabilities_type(self):
425 1
        self.configure({
426
            "execution": [{
427
                "executor": "selenium",
428
                "scenario": "loc_sc_remote"}],
429
            "scenarios": {
430
                "loc_sc_remote": {
431
                    "remote": "http://user:key@remote_web_driver_host:port/wd/hub",
432
                    "capabilities": {
433
                        "proxy": {"key": "val"},
434
                        "string_cap": "string_val"},
435
                    "requests": [{
436
                        "url": "https://blazedemo.com"}]}}})
437

438 1
        self.obj.prepare()
439 1
        with open(self.obj.script) as fds:
440 1
            content = fds.read()
441

442 1
        target_lines = [
443
            "'proxy': {'key': 'val'}",
444
            "'string_cap': 'string_val'"
445
        ]
446 1
        wrong_line = "'proxy': \"{'key': 'val'}\""
447

448 1
        for line in target_lines:
449 1
            self.assertIn(line, content)
450

451 1
        self.assertNotIn(wrong_line, content)
452

453 1
    def test_capabilities_order(self):
454 1
        self.configure({
455
            "execution": [{
456
                "executor": "selenium",
457
                "hold-for": "4m",
458
                "scenario": "loc_sc_remote",
459
                "capabilities": {
460
                    "name2": "execution",
461
                    "name4": "execution",
462
                    "name5": "execution"}}],
463
            "scenarios": {
464
                "loc_sc_remote": {
465
                    "remote": "http://user:key@remote_web_driver_host:port/wd/hub",
466
                    "capabilities": {
467
                        "name3": "scenario",
468
                        "name4": "scenario",
469
                        "name6": "scenario"},
470
                    "default-address": "http://blazedemo.com",
471
                    "timeout": "3.5s",
472
                    "requests": [{
473
                        "url": "/",
474
                        "actions": ["assertTitle(BlazeDemo)"]}]}},
475
            "modules": {
476
                "selenium": {
477
                    "capabilities": {
478
                        "name1": "settings",
479
                        "name2": "settings",
480
                        "name3": "settings"}}}})
481

482 1
        self.obj.prepare()
483 1
        with open(self.obj.script) as fds:
484 1
            content = fds.read()
485

486 1
        target_lines = [
487
            "'name1': 'settings'",
488
            "'name2': 'execution'",
489
            "'name3': 'scenario'",
490
            "'name4': 'execution'",
491
            "'name5': 'execution'",
492
            "'name6': 'scenario'"]
493

494 1
        for line in target_lines:
495 1
            self.assertIn(line, content)
496

497 1
    def test_build_script_remote(self):
498 1
        self.configure({
499
            "execution": [{
500
                "executor": "selenium",
501
                "hold-for": "4m",
502
                "ramp-up": "3m",
503
                "scenario": "loc_sc_remote"}],
504
            "scenarios": {
505
                "loc_sc_remote": {
506
                    "remote": "http://user:key@remote_web_driver_host:port/wd/hub",
507
                    "capabilities": {
508
                        "browserName": "firefox",
509
                        "version": "54.0",
510
                        "platformName": "linux",
511
                        "javascriptEnabled": "True",
512
                        "platformVersion": "",
513
                        "seleniumVersion": "",
514
                        "deviceName": "",
515
                        "app": ""
516
                    },
517
                    "default-address": "http://blazedemo.com",
518
                    "timeout": "3.5s",
519
                    "requests": [{
520
                        "url": "/",
521
                        "assert": [{
522
                            "contains": ['contained_text'],
523
                            "not": True
524
                        }],
525
                        "actions": [
526
                            "waitByXPath(//input[@type='submit'])",
527
                            "assertTitle(BlazeDemo)"
528
                        ],
529
                    },
530
                        {"label": "empty"}
531
                    ]
532
                }
533
            }
534
        })
535

536 1
        self.obj.prepare()
537 1
        exp_file = RESOURCES_DIR + "selenium/generated_from_requests_remote.py"
538 1
        self.assertFilesEqual(exp_file, self.obj.script, python_files=True)
539

540 1
    def test_remote_without_browser_validation(self):
541 1
        browser_name = "some strange browser"
542 1
        self.configure({
543
            "execution": [{
544
                "executor": "selenium",
545
                "scenario": "loc_sc_remote"}],
546
            "scenarios": {
547
                "loc_sc_remote": {
548
                    "remote": "http://user:key@remote_web_driver_host:port/wd/hub",
549
                    "capabilities": {"browserName": browser_name},
550
                    "requests": [{"url": "/"}]}}})
551

552 1
        self.obj.prepare()
553 1
        with open(self.obj.script) as script:
554 1
            content = script.read()
555

556 1
        sample = "desired_capabilities={'browserName': '%s'}" % browser_name
557 1
        self.assertIn(sample, content)
558

559 1
    def test_build_script_appium_browser(self):
560 1
        self.configure({
561
            "execution": [{
562
                "executor": "selenium",
563
                "hold-for": "4m",
564
                "ramp-up": "3m",
565
                "scenario": "loc_sc_appium"}],
566
            "scenarios": {
567
                "loc_sc_appium": {
568
                    "browser": "Chrome-Android",
569
                    "capabilities": {
570
                        "deviceName": "",
571
                    },
572
                    "default-address": "http://blazedemo.com",
573
                    "timeout": "3.5s",
574
                    "requests": [{
575
                        "url": "/",
576
                        "assert": [{
577
                            "contains": ['contained_text'],
578
                            "not": True
579
                        }],
580
                        "actions": [
581
                            "waitByXPath(//input[@type='submit'])",
582
                            "assertTitle(BlazeDemo)"
583
                        ],
584
                    },
585
                        {"label": "empty"}
586
                    ]
587
                }
588
            }
589
        })
590

591 1
        self.obj.prepare()
592 1
        exp_file = RESOURCES_DIR + "selenium/generated_from_requests_appium_browser.py"
593 1
        self.assertFilesEqual(exp_file, self.obj.script, python_files=True)
594

595 1
    def test_build_script_remote_empty_browser(self):
596
        """ taurus should not wipe browserName (from capabilities) """
597 1
        self.configure({
598
            "execution": [{
599
                "executor": "selenium",
600
                "remote": "http://addr-of-remote-server.com",
601
                "scenario": "remote_sc"}],
602
            "scenarios": {
603
                "remote_sc": {  # no 'browser' element
604
                    "capabilities": {
605
                        "browserName": "chrome"},  # must be faced in desired_capabilities
606
                    "timeout": "3.5s",
607
                    "requests": [{
608
                        "url": "http://blazedemo.com",
609
                        "actions": [
610
                            "waitByXPath(//input[@type='submit'])"]},
611
                        {"label": "empty"}]}}})
612

613 1
        self.obj.prepare()
614 1
        with open(self.obj.script) as fds:
615 1
            content = fds.read()
616

617 1
        target = "'browserName': 'chrome'"
618 1
        self.assertIn(target, content)
619

620 1
    def test_build_script_remote_browser(self):
621
        """ taurus should not wipe browserName (from capabilities) """
622 1
        self.configure({
623
            "execution": [{
624
                "executor": "selenium",
625
                "remote": "http://addr-of-remote-server.com",
626
                "scenario": "remote_sc"}],
627
            "scenarios": {
628
                "remote_sc": {
629
                    "capabilities": {
630
                        "browserName": "chrome"},  # must be faced in desired_capabilities
631
                    "timeout": "3.5s",
632
                    "requests": [{
633
                        "url": "http://blazedemo.com",
634
                        "actions": [
635
                            "waitByXPath(//input[@type='submit'])"]},
636
                        {"label": "empty"}]}}})
637

638 1
        self.obj.prepare()
639 1
        with open(self.obj.script) as fds:
640 1
            content = fds.read()
641

642 1
        target = "'browserName': 'chrome'"
643 1
        self.assertIn(target, content)
644

645 1
    def test_build_script_remote_Firefox_browser(self):
646
        """ check usage of 'browser' scenario options as browserName (from capabilities) """
647 1
        self.configure({
648
            "execution": [{
649
                "executor": "selenium",
650
                "remote": "http://addr-of-remote-server.com",
651
                "scenario": "remote_sc"}],
652
            "scenarios": {
653
                "remote_sc": {
654
                    "browser": "Firefox",  # must be faced in desired_capabilities (in lower case)
655
                    "timeout": "3.5s",
656
                    "requests": [{
657
                        "url": "http://blazedemo.com",
658
                        "actions": [
659
                            "waitByXPath(//input[@type='submit'])"]},
660
                        {"label": "empty"}]}}})
661

662 1
        self.obj.prepare()
663 1
        with open(self.obj.script) as fds:
664 1
            content = fds.read()
665

666 1
        target = "'browserName': 'firefox'"
667 1
        self.assertIn(target, content)
668

669 1
    def test_build_script_flow_markers(self):
670 1
        self.configure({
671
            "execution": [{
672
                "executor": "selenium",
673
                "hold-for": "4m",
674
                "ramp-up": "3m",
675
                "scenario": "loc_sc"}],
676
            "scenarios": {
677
                "loc_sc": {
678
                    "generate-flow-markers": True,
679
                    "browser": "Chrome",
680
                    "default-address": "http://blazedemo.com",
681
                    "timeout": "3.5s",
682
                    "requests": [{
683
                        "url": "/",
684
                        "assert": [{
685
                            "contains": ['contained_text'],
686
                            "not": True
687
                        }],
688
                        "actions": [
689
                            "waitByXPath(//input[@type='submit'])",
690
                            "assertTitle(BlazeDemo)"
691
                        ],
692
                    },
693
                        {"label": "empty"}
694
                    ]
695
                }
696
            }
697
        })
698 1
        self.obj.prepare()
699 1
        exp_file = RESOURCES_DIR + "selenium/generated_from_requests_flow_markers.py"
700 1
        str_to_replace = (self.obj.engine.artifacts_dir + os.path.sep).replace('\\', '\\\\')
701 1
        self.assertFilesEqual(exp_file, self.obj.script, str_to_replace, "/somewhere/", python_files=True)
702

703 1
    def test_add_external_logging(self):
704 1
        self.configure({
705
            "execution": [{
706
                "executor": "selenium",
707
                "scenario": "sample"}],
708
            "scenarios": {
709
                "sample": {
710
                    "external-logging": True,
711
                    "browser": "Chrome",
712
                    "requests": [{
713
                        "label": "Test",
714
                        "actions": [
715
                            "go(http://blazedemo.com/)",
716
                            "log(leaving blazedemo)",
717
                        ],
718
                    }]
719
                }
720
            }
721
        })
722 1
        self.obj.prepare()
723 1
        exp_file = RESOURCES_DIR + "selenium/external_logging.py"
724 1
        str_to_replace = (self.obj.engine.artifacts_dir + os.path.sep).replace('\\', '\\\\')
725 1
        self.assertFilesEqual(exp_file, self.obj.script, str_to_replace, "/somewhere/", python_files=True)
726

727

728 1
    def test_resize_window(self):
729 1
        self.configure({
730
            "execution": [{
731
                "executor": "selenium",
732
                "concurrency": "1",
733
                "iterations": "1",
734
                "scenario": "window"}],
735
            "scenarios": {
736
                "window": {
737
                    "default-address": "http://blazedemo.com",
738
                    "requests": [{
739
                        "url": "/",
740
                        "actions": [
741
                            "resizeWindow(450, 450)",
742
                            "maximizeWindow()",
743
                            "closeWindow()"
744
                        ],
745
                    }, ]
746
                },
747
            }
748
        })
749

750 1
        self.obj.prepare()
751 1
        with open(self.obj.script) as fds:
752 1
            content = fds.read()
753

754 1
        target_lines = [
755
            "self.driver.set_window_size('450', '450')",
756
            "self.driver.maximize_window()"
757
        ]
758

759 1
        for idx in range(len(target_lines)):
760 1
            self.assertIn(target_lines[idx], content, msg="\n\n%s. %s" % (idx, target_lines[idx]))
761

762 1
    def test_alert(self):
763 1
        self.configure({
764
            "execution": [{
765
                "executor": "selenium",
766
                "concurrency": "1",
767
                "iterations": "1",
768
                "scenario": "window"}],
769
            "scenarios": {
770
                "window": {
771
                    "default-address": "http://blazedemo.com",
772
                    "requests": [{
773
                        "url": "/",
774
                        "actions": [
775
                            "alert('OK')",
776
                            "alert('Dismiss')"
777
                        ],
778
                    }, ]
779
                },
780
            }
781
        })
782

783 1
        self.obj.prepare()
784 1
        with open(self.obj.script) as fds:
785 1
            content = fds.read()
786

787 1
        target_lines = [
788
            "self.driver.switch_to.alert.accept()",
789
            "self.driver.switch_to.alert.dismiss()"
790
        ]
791

792 1
        for idx in range(len(target_lines)):
793 1
            self.assertIn(target_lines[idx], content, msg="\n\n%s. %s" % (idx, target_lines[idx]))
794

795 1
    def test_non_utf(self):
796 1
        self.configure({
797
            "execution": [{
798
                "executor": "selenium",
799
                "scenario": "simple"}],
800
            "scenarios": {
801
                "simple": {
802
                    "requests": [{
803
                        "url": "http://blazedemo.com/测试",
804
                    }, ]
805
                },
806
            }
807
        })
808

809 1
        self.obj.prepare()
810 1
        with open(self.obj.script, encoding='utf8') as fds:
811 1
            content = fds.read()
812

813 1
        target_lines = [
814
            "with apiritif.smart_transaction('http://blazedemo.com/测试')",
815
            "self.driver.get(\'http://blazedemo.com/测试')"
816
        ]
817

818 1
        for idx in range(len(target_lines)):
819 1
            self.assertIn(target_lines[idx], content, msg="\n\n%s. %s" % (idx, target_lines[idx]))
820

821 1
    def test_mix_syntax(self):
822 1
        self.configure({
823
            "execution": [{
824
                "executor": "apiritif",
825
                "scenario": "loc_sc"}],
826
            "scenarios": {
827
                "loc_sc": {
828
                    "requests": [{
829
                        "label": "la-la",
830
                        "actions": [
831
                            {
832
                                "type": "click",
833
                                "locators": [
834
                                    {"name": "btn1"},
835
                                ]
836
                            },
837
                            {"typeById(Id_123)": "London"}
838
                        ]}]}}})
839

840 1
        self.obj.prepare()
841 1
        with open(self.obj.script) as fds:
842 1
            content = fds.read()
843

844 1
        target_lines = [
845
            "var_loc_keys=get_locator([{'name':'btn1',}])",
846
            "self.driver.find_element(var_loc_keys[0],var_loc_keys[1]).click()",
847
            "var_loc_keys=get_locator([{'id':'Id_123',}])",
848
            "self.driver.find_element(var_loc_keys[0],var_loc_keys[1]).clear()",
849
            "send_keys(var_loc_keys,'London')"
850
        ]
851

852 1
        for idx in range(len(target_lines)):
853 1
            target_lines[idx] = astunparse.unparse(ast.parse(target_lines[idx]))
854 1
            self.assertIn(TestSeleniumScriptGeneration.clear_spaces(target_lines[idx]),
855
                          TestSeleniumScriptGeneration.clear_spaces(content),
856
                          msg="\n\n%s. %s" % (idx, target_lines[idx]))
857

858 1
    def test_syntax2_drag_drop(self):
859 1
        self.configure({
860
            "execution": [{
861
                "executor": "apiritif",
862
                "scenario": "loc_sc"}],
863
            "scenarios": {
864
                "loc_sc": {
865
                    "requests": [{
866
                        "label": "la-la",
867
                        "actions": [
868
                            {
869
                                "type": "drag",
870
                                "source": [
871
                                    {"xpath": "/xpath/to"}
872
                                ],
873
                                "target": [
874
                                    {"css": "mycss"},
875
                                    {"id": "ID"}
876
                                ]
877
                            }
878
                        ]}]}}})
879

880 1
        self.obj.prepare()
881 1
        with open(self.obj.script) as fds:
882 1
            content = fds.read()
883

884 1
        target_lines = [
885
            "source=get_locator([{'xpath':'/xpath/to'}])",
886
            "target=get_locator([{'css':'mycss'},{'id':'ID'}])",
887
            "ActionChains(self.driver).drag_and_drop(self.driver.find_element(source[0],source[1]),"
888
            "self.driver.find_element(target[0],target[1])).perform()"
889
        ]
890 1
        for idx in range(len(target_lines)):
891 1
            target_lines[idx] = astunparse.unparse(ast.parse(target_lines[idx]))
892 1
            self.assertIn(TestSeleniumScriptGeneration.clear_spaces(target_lines[idx]),
893
                          TestSeleniumScriptGeneration.clear_spaces(content),
894
                          msg="\n\n%s. %s" % (idx, target_lines[idx]))
895

896 1
    def test_syntax2_drag_drop_missing_source(self):
897 1
        self.configure({
898
            "execution": [{
899
                "executor": "apiritif",
900
                "scenario": "loc_sc"}],
901
            "scenarios": {
902
                "loc_sc": {
903
                    "requests": [{
904
                        "label": "la-la",
905
                        "actions": [
906
                            {
907
                                "type": "drag",
908
                                "source": {
909

910
                                },
911
                                "target": {
912
                                    "locators": [
913
                                        {"css": "mycss"},
914
                                        {"id": "ID"}
915
                                    ]
916
                                }
917
                            }
918
                        ]}]}}})
919

920 1
        with self.assertRaises(TaurusConfigError) as context:
921 1
            self.obj.prepare()
922

923 1
        self.assertTrue('Can not generate action for \'drag\'. Source is empty.' in str(context.exception))
924

925 1
    def test_syntax2_missing_param_assert_store(self):
926 1
        self.configure({
927
            "execution": [{
928
                "executor": "apiritif",
929
                "scenario": "loc_sc"}],
930
            "scenarios": {
931
                "loc_sc": {
932
                    "requests": [{
933
                        "label": "la-la",
934
                        "actions": [
935
                            {
936
                                "type": "assertText",
937
                                "locators": [
938
                                    {"css": "classname"}
939
                                ]
940
                            }
941
                        ]}]}}})
942

943 1
        with self.assertRaises(TaurusConfigError) as context:
944 1
            self.obj.prepare()
945

946 1
        self.assertTrue('Missing param' in str(context.exception))
947

948 1
    def test_syntax2_missing_param_edit(self):
949 1
        self.configure({
950
            "execution": [{
951
                "executor": "apiritif",
952
                "scenario": "loc_sc"}],
953
            "scenarios": {
954
                "loc_sc": {
955
                    "requests": [{
956
                        "label": "la-la",
957
                        "actions": [
958
                            {
959
                                "type": "editContent",
960
                                "locators": [
961
                                    {"css": "classname"}
962
                                ]
963
                            }
964
                        ]}]}}})
965

966 1
        with self.assertRaises(TaurusConfigError) as context:
967 1
            self.obj.prepare()
968

969 1
        self.assertTrue('Missing param' in str(context.exception))
970

971 1
    def test_syntax2_build_script(self):
972 1
        self.configure(
973
            {
974
                "execution": [
975
                    {
976
                        "executor": "apiritif",
977
                        "scenario": "loc_sc"
978
                    }
979
                ],
980
                "scenarios": {
981
                    "loc_sc": {
982
                        "default-address": "http://blazedemo.com,",
983
                        "variables": {
984
                            "my_xpath_locator": "/html/body/div[3]",
985
                            "red_pill": "take_it,",
986
                            "name": "Name"
987
                        },
988
                        "timeout": "3.5s",
989
                        "requests": [
990
                            {
991
                                "label": "Test V2",
992
                                "actions": [
993
                                    {
994
                                        "type": "go",
995
                                        "param": "http://blazedemo.com"
996
                                    },
997
                                    {
998
                                        "type": "resizeWindow",
999
                                        "param": "750, 750"
1000
                                    },
1001
                                    {
1002
                                        "type": "switchWindow",
1003
                                        "param": 0
1004
                                    },
1005
                                    {
1006
                                        "type": "mouseDown",
1007
                                        "locators": [
1008
                                            {"id": "invalid_id"},
1009
                                            {"xpath": "${my_xpath_locator}"}
1010
                                        ]
1011
                                    },
1012
                                    {
1013
                                        "type": "mouseOut",
1014
                                        "locators": [{"id": "id_123"}]
1015
                                    },
1016
                                    {
1017
                                        "type": "mouseOver",
1018
                                        "locators": [{"name": "name_123"}]
1019
                                    },
1020
                                    {
1021
                                        "type": "drag",
1022
                                        "source": [
1023
                                            {"name": "invalid_name"},
1024
                                            {"xpath": "/html/body/div[2]/div/p[2]/a"}
1025
                                        ],
1026
                                        "target": [
1027
                                            {"css": "invalid_css"},
1028
                                            {"xpath": "/html/body/div[3]/form/div"}
1029
                                        ]
1030
                                    },
1031
                                    {
1032
                                        "type": "assertText",
1033
                                        "param": "Choose your departure city:",
1034
                                        "locators": [
1035
                                            {"css": "myclass"},
1036
                                            {"xpath": "/html/body/div[3]/h2"}
1037
                                        ]
1038
                                    },
1039
                                    {
1040
                                        "type": "assertValue",
1041
                                        "param": "Find Flights",
1042
                                        "locators": [
1043
                                            {"css": "myclass"},
1044
                                            {"xpath": "/html/body/div[3]/form/div/input"}
1045
                                        ]
1046
                                    },
1047
                                    {
1048
                                        "type": "assertTitle",
1049
                                        "param": "BlazeDemo"
1050
                                    },
1051
                                    {
1052
                                        "type": "storeTitle",
1053
                                        "param": "hEaDeR"
1054
                                    },
1055
                                    {
1056
                                        "type": "storeString",
1057
                                        "param": "final_var",
1058
                                        "value": "test_text"
1059
                                    },
1060
                                    {
1061
                                        "type": "storeText",
1062
                                        "param": "Basic",
1063
                                        "locators": [{"xpath": "/html/body/div[3]/h2"}]
1064
                                    },
1065
                                    {
1066
                                        "type": "assertEval",
1067
                                        "param": "10 === 2*5"
1068
                                    },
1069
                                    {
1070
                                        "type": "storeEval",
1071
                                        "param": "var_eval",
1072
                                        "value": "0 == false"
1073
                                    },
1074
                                    {
1075
                                        "type": "click",
1076
                                        "locators": [
1077
                                            {"xpath": "/wrong/one"},
1078
                                            {"xpath": "/html/body/div[3]/form/div/input"}
1079
                                        ]
1080
                                    },
1081
                                    {
1082
                                        "type": "keys",
1083
                                        "param": "KEY_ENTER",
1084
                                        "locators": [
1085
                                            {"xpath": "/doc/abc"},
1086
                                            {"css": "body > div.container > table > tbody > tr:nth-child(1) "
1087
                                                    "> td:nth-child(2) > input"}
1088
                                        ]
1089
                                    },
1090
                                    {
1091
                                        "type": "type",
1092
                                        "param": "myusername",
1093
                                        "locators": [
1094
                                            {"id": "fjkafjk"},
1095
                                            {"css": "testCss"}
1096
                                        ]
1097
                                    },
1098
                                    {
1099
                                        "type": "select",
1100
                                        "param": "American Express",
1101
                                        "locators": [
1102
                                            {"css": "myclass"},
1103
                                            {"xpath": "//*[@id=\"cardType\"]"}
1104
                                        ]
1105
                                    },
1106
                                    {
1107
                                        "type": "scriptEval",
1108
                                        "param": "window.scrollTo(0, document.body.scrollHeight);"
1109
                                    },
1110
                                    {
1111
                                        "type": "rawCode",
1112
                                        "param": "for i in range(10):\n  if i % 2 == 0:\n    print(i)"
1113
                                    },
1114
                                    {
1115
                                        "type": "echoString",
1116
                                        "param": "${red_pill}"
1117
                                    },
1118
                                    {
1119
                                        "type": "pauseFor",
1120
                                        "param": "4.6s"
1121
                                    },
1122
                                    {
1123
                                        "type": "clearCookies"
1124
                                    },
1125
                                    {
1126
                                        "type": "screenshot",
1127
                                        "param": "screen.png"
1128
                                    },
1129
                                    {
1130
                                        "type": "screenshot"
1131
                                    },
1132
                                    {
1133
                                        "type": "wait",
1134
                                        "param": "visible",
1135
                                        "locators": [
1136
                                            {"css": "invalid_css"},
1137
                                            {"name": "inputName"}
1138
                                        ]
1139
                                    },
1140
                                    {
1141
                                        "type": "waitFor",
1142
                                        "param": "visible",
1143
                                        "locators": [
1144
                                            {"css": "invalid_css"},
1145
                                            {"name": "inputName"}
1146
                                        ],
1147
                                        "value": "2h30m20s"
1148
                                    },
1149
                                    {
1150
                                        "type": "editContent",
1151
                                        "param": "lo-la-lu",
1152
                                        "locators": [{"id": "editor"}]
1153
                                    },
1154
                                    {
1155
                                        "type": "pauseFor",
1156
                                        "param": "4.6s"
1157
                                    },
1158
                                    {
1159
                                        "type": "clearCookies"
1160
                                    },
1161
                                    {
1162
                                        "type": "screenshot",
1163
                                        "param": "screen.png"
1164
                                    },
1165
                                    {
1166
                                        "type": "screenshot"
1167
                                    },
1168
                                    {
1169
                                        "type": "openWindow",
1170
                                        "param": "vacation.html"
1171
                                    },
1172
                                    {
1173
                                        "type": "maximizeWindow"
1174
                                    },
1175
                                    {
1176
                                        "type": "switchFrameByIdx",
1177
                                        "param": 1
1178
                                    },
1179
                                    {
1180
                                        "type": "switchFrame",
1181
                                        "param": "relative=parent"
1182
                                    },
1183
                                    {
1184
                                        "type": "switchFrameByName",
1185
                                        "param": "my_frame"
1186
                                    },
1187
                                    {
1188
                                        "type": "closeWindow"
1189
                                    },
1190
                                    {
1191
                                        "type": "answerDialog",
1192
                                        "param": "prompt",
1193
                                        "value": "my input"
1194
                                    },
1195
                                    {
1196
                                        "type": "answerDialog",
1197
                                        "param": "confirm",
1198
                                        "value": '#Ok'
1199
                                    },
1200
                                    {
1201
                                        "type": "answerDialog",
1202
                                        "param": "alert",
1203
                                        "value": '#Ok'
1204
                                    },
1205
                                    {
1206
                                        "type": "assertDialog",
1207
                                        "param": "alert",
1208
                                        "value": "Exception occurred!"
1209
                                    },
1210
                                    {
1211
                                        "type": "assertDialog",
1212
                                        "param": "confirm",
1213
                                        "value": "Are you sure?"
1214
                                    },
1215
                                    {
1216
                                        "type": "assertDialog",
1217
                                        "param": "prompt",
1218
                                        "value": "What is your age?"
1219
                                    },
1220
                                ]
1221
                            }
1222
                        ]
1223
                    }
1224
                }
1225
            }
1226
        )
1227

1228 1
        self.obj.prepare()
1229 1
        exp_file = RESOURCES_DIR + "selenium/generated_from_requests_v2.py"
1230 1
        str_to_replace = (self.obj.engine.artifacts_dir + os.path.sep).replace('\\', '\\\\')
1231 1
        self.assertFilesEqual(exp_file, self.obj.script, str_to_replace, "/somewhere/", python_files=True)
1232 1
        with open(self.obj.script) as script:
1233 1
            self.assertIn("bzt.resources.selenium_extras", script.read())
1234

1235 1
    def test_conditions(self):
1236 1
        self.configure(
1237
            {
1238
                "execution": [
1239
                    {
1240
                        "executor": "apiritif",
1241
                        "scenario": "loc_sc"
1242
                    }
1243
                ],
1244
                "scenarios": {
1245
                    "loc_sc": {
1246
                        "default-address": "http://blazedemo.com,",
1247
                        "browser": "Chrome",
1248
                        "variables": {
1249
                            "city_select_name": "fromPort",
1250
                            "input_name_id": "inputName"
1251
                        },
1252
                        "timeout": "3.5s",
1253
                        "requests": [
1254
                            {
1255
                                "label": "Conditions test",
1256
                                "actions": [
1257
                                    "go(http://blazedemo.com)",
1258
                                    {
1259
                                        "if": "document.getElementsByName(\"fromPort\")[0].length > 0",
1260
                                        "then": [
1261
                                            {
1262
                                                "type": "click",
1263
                                                "locators": [
1264
                                                    {
1265
                                                        "id": "wrong_id"
1266
                                                    },
1267
                                                    {
1268
                                                        "xpath": "/html/body/div[3]/form/div/input"
1269
                                                    }
1270
                                                ]
1271
                                            },
1272
                                            "pauseFor(1s)",
1273
                                            {
1274
                                                "if": "document.getElementsByClassName(\"table\")[0].rows.length > 5",
1275
                                                "then": [
1276
                                                    "clickByXPath(/html/body/div[2]/table/tbody/tr[5]/td[1]/input)",
1277
                                                    {
1278
                                                        "if": "document.getElementById(\"${input_name_id}\").value "
1279
                                                              "=== ''",
1280
                                                        "then": [
1281
                                                            {
1282
                                                                "typeById(${input_name_id})": "John Doe"
1283
                                                            }
1284
                                                        ],
1285
                                                        "else": [
1286
                                                            {
1287
                                                                "typeById(${input_name_id})": "Jack Green"
1288
                                                            }
1289
                                                        ]
1290
                                                    },
1291
                                                    "clickByXPath(/html/body/div[2]/form/div[11]/div/input)",
1292
                                                    "pauseFor(5s)"
1293
                                                ]
1294
                                            }
1295
                                        ],
1296
                                        "else": [
1297
                                            {
1298
                                                "if": "document.getElementsByClassName(\"table\")[0].rows.length > 5",
1299
                                                "then": [
1300
                                                    {
1301
                                                        "typeById(${elem2_id})": "my text"
1302
                                                    },
1303
                                                    {
1304
                                                        "if": "window.screen.width > 1000",
1305
                                                        "then": [
1306
                                                            "screenshot(file_1000)"
1307
                                                        ],
1308
                                                        "else": [
1309
                                                            "screenshot(file)"
1310
                                                        ]
1311
                                                    }
1312
                                                ],
1313
                                                "else": [
1314
                                                    "clickByXPath(/html/body/div[3]/input)"
1315
                                                ]
1316
                                            }
1317
                                        ]
1318
                                    }
1319
                                ]
1320
                            }
1321
                        ]
1322
                    }
1323
                }
1324
            }
1325
        )
1326

1327 1
        self.obj.prepare()
1328 1
        exp_file = RESOURCES_DIR + "selenium/generated_from_requests_if_then_else.py"
1329 1
        str_to_replace = (self.obj.engine.artifacts_dir + os.path.sep).replace('\\', '\\\\')
1330 1
        self.assertFilesEqual(exp_file, self.obj.script, str_to_replace, "/somewhere/", python_files=True)
1331

1332 1
    def test_conditions_missing_then(self):
1333 1
        self.configure({
1334
            "execution": [{
1335
                "executor": "apiritif",
1336
                "scenario": "loc_sc"}],
1337
            "scenarios": {
1338
                "loc_sc": {
1339
                    "requests": [{
1340
                        "label": "la-la",
1341
                        "actions": [
1342
                            {
1343
                                "if": "document.getElementsByName(\"fromPort\")[0].length > 0"
1344
                            }
1345
                        ]}]}}})
1346

1347 1
        with self.assertRaises(TaurusConfigError) as context:
1348 1
            self.obj.prepare()
1349

1350 1
        self.assertTrue('Missing then' in str(context.exception))
1351

1352 1
    def test_loop_missing_end(self):
1353 1
        self.configure({
1354
            "execution": [{
1355
                "executor": "apiritif",
1356
                "scenario": "loc_sc"}],
1357
            "scenarios": {
1358
                "loc_sc": {
1359
                    "requests": [{
1360
                        "label": "la-la",
1361
                        "actions": [
1362
                            {
1363
                                "loop": "i",
1364
                                "start": 1,
1365
                                "do": [
1366
                                    "clickById(dd)"
1367
                                ]
1368
                            }
1369
                        ]}]}}})
1370

1371 1
        with self.assertRaises(TaurusConfigError) as context:
1372 1
            self.obj.prepare()
1373

1374 1
        self.assertTrue('Loop must contain' in str(context.exception))
1375

1376 1
    def test_loop_missing_start(self):
1377 1
        self.configure({
1378
            "execution": [{
1379
                "executor": "apiritif",
1380
                "scenario": "loc_sc"}],
1381
            "scenarios": {
1382
                "loc_sc": {
1383
                    "requests": [{
1384
                        "label": "la-la",
1385
                        "actions": [
1386
                            {
1387
                                "loop": "i",
1388
                                "end": 10,
1389
                                "do": [
1390
                                    "clickById(dd)"
1391
                                ]
1392
                            }
1393
                        ]}]}}})
1394

1395 1
        with self.assertRaises(TaurusConfigError) as context:
1396 1
            self.obj.prepare()
1397

1398 1
        self.assertTrue('Loop must contain' in str(context.exception))
1399

1400 1
    def test_loop_missing_do(self):
1401 1
        self.configure({
1402
            "execution": [{
1403
                "executor": "apiritif",
1404
                "scenario": "loc_sc"}],
1405
            "scenarios": {
1406
                "loc_sc": {
1407
                    "requests": [{
1408
                        "label": "la-la",
1409
                        "actions": [
1410
                            {
1411
                                "loop": "i",
1412
                                "start": 1,
1413
                                "end": 10,
1414
                                "do": []
1415
                            }
1416
                        ]}]}}})
1417

1418 1
        with self.assertRaises(TaurusConfigError) as context:
1419 1
            self.obj.prepare()
1420

1421 1
        self.assertTrue('Loop must contain' in str(context.exception))
1422

1423 1
    def test_loop_step_defaults_to_1(self):
1424 1
        self.configure({
1425
            "execution": [{
1426
                "executor": "apiritif",
1427
                "scenario": "loc_sc"}],
1428
            "scenarios": {
1429
                "loc_sc": {
1430
                    "requests": [{
1431
                        "actions": [
1432
                            {
1433
                                "loop": "i",
1434
                                "start": 1,
1435
                                "end": 10,
1436
                                "do": [
1437
                                    "clickById(${i})"
1438
                                ]
1439
                            }
1440
                        ]}]}}})
1441

1442 1
        self.obj.prepare()
1443 1
        with open(self.obj.script) as fds:
1444 1
            content = fds.read()
1445

1446 1
        target_lines = [
1447
            "for i in get_loop_range(1, 10, 1)",
1448
            "self.vars['i'] = str(i)",
1449
            "get_locator([{'id': self.vars['i']"
1450

1451
        ]
1452 1
        for idx in range(len(target_lines)):
1453 1
            self.assertIn(TestSeleniumScriptGeneration.clear_spaces(target_lines[idx]),
1454
                          TestSeleniumScriptGeneration.clear_spaces(content),
1455
                          msg="\n\n%s. %s" % (idx, target_lines[idx]))
1456

1457 1
    def test_loop_step_2(self):
1458 1
        self.configure({
1459
            "execution": [{
1460
                "executor": "apiritif",
1461
                "scenario": "loc_sc"}],
1462
            "scenarios": {
1463
                "loc_sc": {
1464
                    "requests": [{
1465
                        "actions": [
1466
                            {
1467
                                "loop": "i",
1468
                                "start": 1,
1469
                                "end": 10,
1470
                                "step": 2,
1471
                                "do": [
1472
                                    "clickById(id)"
1473
                                ]
1474
                            }
1475
                        ]}]}}})
1476

1477 1
        self.obj.prepare()
1478 1
        with open(self.obj.script) as fds:
1479 1
            content = fds.read()
1480

1481 1
        target_lines = [
1482
            "for i in get_loop_range(1, 10, 2)",
1483
            "self.vars['i'] = str(i)"
1484
        ]
1485 1
        for idx in range(len(target_lines)):
1486 1
            self.assertIn(target_lines[idx], content, msg="\n\n%s. %s" % (idx, target_lines[idx]))
1487

1488 1
    def test_loop_step_negative(self):
1489 1
        self.configure({
1490
            "execution": [{
1491
                "executor": "apiritif",
1492
                "scenario": "loc_sc"}],
1493
            "scenarios": {
1494
                "loc_sc": {
1495
                    "requests": [{
1496
                        "actions": [
1497
                            {
1498
                                "loop": "i",
1499
                                "start": 10,
1500
                                "end": 0,
1501
                                "step": -1,
1502
                                "do": [
1503
                                    "clickById(id)"
1504
                                ]
1505
                            }
1506
                        ]}]}}})
1507

1508 1
        self.obj.prepare()
1509 1
        with open(self.obj.script) as fds:
1510 1
            content = fds.read()
1511

1512 1
        target_lines = [
1513
            "for i in get_loop_range(10, 0, -1)",
1514
            "self.vars['i'] = str(i)"
1515
        ]
1516 1
        for idx in range(len(target_lines)):
1517 1
            self.assertIn(target_lines[idx], content, msg="\n\n%s. %s" % (idx, target_lines[idx]))
1518

1519 1
    def test_loop_w_variables(self):
1520 1
        self.configure({
1521
            "execution": [{
1522
                "executor": "apiritif",
1523
                "scenario": "loc_sc"}],
1524
            "scenarios": {
1525
                "loc_sc": {
1526
                    "variables": {
1527
                        "start": 10,
1528
                        "end": 20,
1529
                        "step": 1
1530
                    },
1531
                    "requests": [{
1532
                        "actions": [
1533
                            {
1534
                                "loop": "i",
1535
                                "start": "${start}",
1536
                                "end": "${end}",
1537
                                "step": "${step}",
1538
                                "do": [
1539
                                    "clickById(id_${i})"
1540
                                ]
1541
                            }
1542
                        ]}]}}})
1543

1544 1
        self.obj.prepare()
1545 1
        exp_file = RESOURCES_DIR + "selenium/generated_from_requests_loop_variables.py"
1546 1
        str_to_replace = (self.obj.engine.artifacts_dir + os.path.sep).replace('\\', '\\\\')
1547 1
        self.assertFilesEqual(exp_file, self.obj.script, str_to_replace, "/somewhere/", python_files=True)
1548

1549 1
    def test_loop_str_var_fields(self):
1550 1
        self.configure({
1551
            "execution": [{
1552
                "executor": "apiritif",
1553
                "scenario": "loc_sc"}],
1554
            "scenarios": {
1555
                "loc_sc": {
1556
                    "variables": {
1557
                        "step": 1
1558
                    },
1559
                    "requests": [{
1560
                        "actions": [
1561
                            {
1562
                                "loop": "i",
1563
                                "start": "1",
1564
                                "end": "10",
1565
                                "step": '1${step}',
1566
                                "do": [
1567
                                    "clickById(id)"
1568
                                ]
1569
                            }
1570
                        ]}]}}})
1571

1572 1
        self.obj.prepare()
1573 1
        with open(self.obj.script) as fds:
1574 1
            content = fds.read()
1575

1576 1
        target_lines = [
1577
            "for i in get_loop_range(1, 10, '1{}'.format(self.vars['step']))",
1578
            "self.vars['i'] = str(i)"
1579
        ]
1580 1
        for idx in range(len(target_lines)):
1581 1
            self.assertIn(target_lines[idx], content, msg="\n\n%s. %s" % (idx, target_lines[idx]))
1582

1583 1
    def test_assert_dialog_wrong_type(self):
1584 1
        self.configure({
1585
            "execution": [{
1586
                "executor": "apiritif",
1587
                "scenario": "loc_sc"}],
1588
            "scenarios": {
1589
                "loc_sc": {
1590
                    "requests": [{
1591
                        "label": "la-la",
1592
                        "actions": [
1593
                            {
1594
                                "assertDialog(wrong)": "test"
1595
                            }
1596
                        ]}]}}})
1597

1598 1
        with self.assertRaises(TaurusConfigError) as context:
1599 1
            self.obj.prepare()
1600

1601 1
        self.assertTrue("assertDialog type must be one of the following: 'alert', 'prompt' or 'confirm'"
1602
                        in str(context.exception))
1603

1604 1
    def test_answer_dialog_wrong_type(self):
1605 1
        self.configure({
1606
            "execution": [{
1607
                "executor": "apiritif",
1608
                "scenario": "loc_sc"}],
1609
            "scenarios": {
1610
                "loc_sc": {
1611
                    "requests": [{
1612
                        "label": "la-la",
1613
                        "actions": [
1614
                            {
1615
                                "answerDialog(wrong)": "test"
1616
                            }
1617
                        ]}]}}})
1618

1619 1
        with self.assertRaises(TaurusConfigError) as context:
1620 1
            self.obj.prepare()
1621

1622 1
        self.assertTrue("answerDialog type must be one of the following: 'alert', 'prompt' or 'confirm'"
1623
                        in str(context.exception))
1624

1625 1
    def test_answer_confirm_incorrect_type(self):
1626 1
        self.configure({
1627
            "execution": [{
1628
                "executor": "apiritif",
1629
                "scenario": "loc_sc"}],
1630
            "scenarios": {
1631
                "loc_sc": {
1632
                    "requests": [{
1633
                        "label": "la-la",
1634
                        "actions": [
1635
                            {
1636
                                "answerDialog(confirm)": "value"
1637
                            }
1638
                        ]}]}}})
1639

1640 1
        with self.assertRaises(TaurusConfigError) as context:
1641 1
            self.obj.prepare()
1642

1643 1
        self.assertTrue("answerDialog of type confirm must have value either '#Ok' or '#Cancel'"
1644
                        in str(context.exception))
1645

1646 1
    def test_answer_alert_incorrect_type(self):
1647 1
        self.configure({
1648
            "execution": [{
1649
                "executor": "apiritif",
1650
                "scenario": "loc_sc"}],
1651
            "scenarios": {
1652
                "loc_sc": {
1653
                    "requests": [{
1654
                        "label": "la-la",
1655
                        "actions": [
1656
                            {
1657
                                "answerDialog(alert)": "value"
1658
                            }
1659
                        ]}]}}})
1660

1661 1
        with self.assertRaises(TaurusConfigError) as context:
1662 1
            self.obj.prepare()
1663

1664 1
        self.assertTrue("answerDialog of type alert must have value '#Ok'"
1665
                        in str(context.exception))
1666

1667 1
    def test_wait_for(self):
1668 1
        self.configure({
1669
            "execution": [{
1670
                "executor": "apiritif",
1671
                "scenario": "loc_sc"}],
1672
            "scenarios": {
1673
                "loc_sc": {
1674
                    "requests": [{
1675
                        "label": "la-la",
1676
                        "actions": [
1677
                            {
1678
                                "type": "waitFor",
1679
                                "param": "visible",
1680
                                "locators": [
1681
                                    {"css": "invalid_css"},
1682
                                    {"id": "input_id"}
1683
                                ],
1684
                                "value": "2h30m20s"
1685
                            },
1686
                            {"waitForById(myId, present)": "10s"},
1687
                            {"waitForById(myId, clickable)": "10s"},
1688
                            {"waitForById(myId, notvisible)": "10s"},
1689
                            {"waitForById(myId, notpresent)": "10s"},
1690
                            {"waitForById(myId, notclickable)": "10s"}
1691
                        ]}]}}})
1692

1693 1
        self.obj.prepare()
1694 1
        with open(self.obj.script) as fds:
1695 1
            content = fds.read()
1696

1697 1
        target_lines = [
1698
            "wait_for('visible',[{'css':'invalid_css'},{'id':'input_id'}],9020.0)",
1699
            "wait_for('present',[{'id':'myId'}],10.0)",
1700
            "wait_for('clickable',[{'id':'myId'}],10.0)",
1701
            "wait_for('notvisible',[{'id':'myId'}],10.0)",
1702
            "wait_for('notpresent',[{'id':'myId'}],10.0)",
1703
            "wait_for('notclickable',[{'id':'myId'}],10.0)"
1704
        ]
1705 1
        for idx in range(len(target_lines)):
1706 1
            target_lines[idx] = astunparse.unparse(ast.parse(target_lines[idx]))
1707 1
            self.assertIn(TestSeleniumScriptGeneration.clear_spaces(target_lines[idx]),
1708
                          TestSeleniumScriptGeneration.clear_spaces(content),
1709
                          msg="\n\n%s. %s" % (idx, target_lines[idx]))
1710

1711 1
    def test_wait_for_invalid_cond(self):
1712 1
        self.configure({
1713
            "execution": [{
1714
                "executor": "apiritif",
1715
                "scenario": "loc_sc"}],
1716
            "scenarios": {
1717
                "loc_sc": {
1718
                    "requests": [{
1719
                        "label": "la-la",
1720
                        "actions": [
1721
                            {"waitForById(myId, invisible)": "10s"},
1722
                        ]}]}}})
1723

1724 1
        with self.assertRaises(TaurusConfigError) as context:
1725 1
            self.obj.prepare()
1726

1727 1
        self.assertTrue('Invalid condition' in str(context.exception),
1728
                        "Given string was not found in '%s'" % str(context.exception))
1729

1730 1
    def test_foreach_all_by_element_actions(self):
1731 1
        self.configure(
1732
            {
1733
                "execution": [
1734
                    {
1735
                        "executor": "apiritif",
1736
                        "scenario": "loc_sc"
1737
                    }
1738
                ],
1739
                "scenarios": {
1740
                    "loc_sc": {
1741
                        "default-address": "http://blazedemo.com,",
1742
                        "browser": "Chrome",
1743
                        "variables": {
1744
                            "city_select_name": "fromPort",
1745
                            "input_name_id": "inputName"
1746
                        },
1747
                        "timeout": "3.5s",
1748
                        "requests": [
1749
                            {
1750
                                "label": "Foreach test",
1751
                                "actions": [
1752
                                    {
1753
                                        "foreach": "el",
1754
                                        "locators": [
1755
                                            {"css": "input"},
1756
                                            {"xpath": "/table/input/"},
1757
                                        ],
1758
                                        "do": [
1759
                                            {"assertTextByElement(el)": "text"},
1760
                                            {
1761
                                                "type": "assertText",
1762
                                                "element": "el",
1763
                                                "param": "text",
1764
                                                "locators": [
1765
                                                    {"css": "style"},
1766
                                                    {"xpath": "//tr"}
1767
                                                ]
1768
                                            },
1769
                                            {"assertValueByElement(el)": "value"},
1770
                                            {
1771
                                                "type": "assertValue",
1772
                                                "element": "el",
1773
                                                "param": "value"
1774
                                            },
1775
                                            {"editContentByElement(el)" : "new text"},
1776
                                            {
1777
                                                "type": "editContent",
1778
                                                "element": "el",
1779
                                                "param": "new text"
1780
                                            },
1781
                                            "clickByElement(el)",
1782
                                            {
1783
                                                "type": "click",
1784
                                                "element": "el",
1785
                                                "locators": [
1786
                                                    {"css": "input-cls"},
1787
                                                    {"xpath": "//input"}
1788
                                                ]
1789
                                            },
1790
                                            "doubleClickByElement(el)",
1791
                                            {
1792
                                                "type": "doubleClick",
1793
                                                "element": "el",
1794
                                            },
1795
                                            "contextClickByElement(el)",
1796
                                            {
1797
                                                "type": "contextClick",
1798
                                                "element": "el",
1799
                                            },
1800
                                            "mouseDownByElement(el)",
1801
                                            {
1802
                                                "type": "mouseDown",
1803
                                                "element": "el",
1804
                                            },
1805
                                            "mouseUpByElement(el)",
1806
                                            {
1807
                                                "type": "mouseUp",
1808
                                                "element": "el",
1809
                                            },
1810
                                            "mouseOutByElement(el)",
1811
                                            {
1812
                                                "type": "mouseOut",
1813
                                                "element": "el",
1814
                                            },
1815
                                            "mouseOverByElement(el)",
1816
                                            {
1817
                                                "type": "mouseOver",
1818
                                                "element": "el",
1819
                                            },
1820
                                            {"dragByElement(el)" : "elementById(id12)"},
1821
                                            {"dragById(id34)": "elementByElement(el)"},
1822
                                            {
1823
                                                "type": "drag",
1824
                                                "source": [
1825
                                                    {"element": "el"}
1826
                                                ],
1827
                                                "target": [
1828
                                                        {"id": "id12"}
1829
                                                ]
1830
                                            },
1831
                                            {
1832
                                                "type": "drag",
1833
                                                "source": [
1834
                                                    {"id": "id34"}
1835
                                                ],
1836
                                                "target": [
1837
                                                    {"element": "el"}
1838
                                                ]
1839
                                            },
1840
                                            {"selectByElement(el)": "value"},
1841
                                            {
1842
                                                "type": "select",
1843
                                                "element": "el",
1844
                                                "param": "value"
1845
                                            },
1846
                                            {"storeTextByElement(el)": "my_var"},
1847
                                            {
1848
                                                "type": "storeText",
1849
                                                "element": "el",
1850
                                                "param": "my_var"
1851
                                            },
1852
                                            {"storeValueByElement(el)": "my_var"},
1853
                                            {
1854
                                                "type": "storeValue",
1855
                                                "element": "el",
1856
                                                "param": "my_var"
1857
                                            },
1858
                                            {"typeByElement(el)": "text"},
1859
                                            {
1860
                                                "type": "type",
1861
                                                "element": "el",
1862
                                                "param": "text"
1863
                                            },
1864
                                            "submitByElement(el)",
1865
                                            {
1866
                                                "type": "submit",
1867
                                                "element": "el"
1868
                                            },
1869
                                            {"keysByElement(el)": "KEY_ENTER"},
1870
                                            {
1871
                                                "type": "keys",
1872
                                                "element": "el",
1873
                                                "param": "KEY_ENTER"
1874
                                            },
1875
                                        ]
1876
                                    }
1877
                                ]
1878
                            }
1879
                        ]
1880
                    }
1881
                }
1882
            }
1883
        )
1884

1885 1
        self.obj.prepare()
1886 1
        exp_file = RESOURCES_DIR + "selenium/generated_from_requests_foreach.py"
1887 1
        str_to_replace = (self.obj.engine.artifacts_dir + os.path.sep).replace('\\', '\\\\')
1888 1
        self.assertFilesEqual(exp_file, self.obj.script, str_to_replace, "/somewhere/", python_files=True)
1889

1890 1
    def test_foreach_missing_locators(self):
1891 1
        self.configure({
1892
            "execution": [{
1893
                "executor": "apiritif",
1894
                "scenario": "loc_sc"}],
1895
            "scenarios": {
1896
                "loc_sc": {
1897
                    "requests": [{
1898
                        "label": "la-la",
1899
                        "actions": [
1900
                            {
1901
                                "foreach": "element",
1902
                                "do": [
1903
                                    "clickByElement(element)"
1904
                                ]
1905
                            }
1906
                        ]}]}}})
1907

1908 1
        with self.assertRaises(TaurusConfigError) as context:
1909 1
            self.obj.prepare()
1910

1911 1
        self.assertTrue("Foreach loop must contain locators and do" in str(context.exception))
1912

1913 1
    def test_all_by_shadow_actions(self):
1914 1
        self.configure(
1915
            {
1916
                "execution": [
1917
                    {
1918
                        "executor": "apiritif",
1919
                        "scenario": "loc_sc"
1920
                    }
1921
                ],
1922
                "scenarios": {
1923
                    "loc_sc": {
1924
                        "default-address": "http://blazedemo.com,",
1925
                        "browser": "Chrome",
1926
                        "variables": {
1927
                            "city_select_name": "fromPort",
1928
                            "input_name_id": "inputName"
1929
                        },
1930
                        "timeout": "3.5s",
1931
                        "requests": [
1932
                            {
1933
                                "label": "Shadow locators test",
1934
                                "actions": [
1935
                                    {"assertTextByShadow(c-basic, lightning-accordion-section, .slds-button)": "text"},
1936
                                    {
1937
                                        "type": "assertText",
1938
                                        "shadow": "c-basic, lightning-accordion-section, .slds-button",
1939
                                        "param": "text"
1940
                                    },
1941
                                    {"assertValueByShadow(c-basic, lightning-accordion-section, .slds-button)": "value"},
1942
                                    {
1943
                                        "type": "assertValue",
1944
                                        "shadow": "c-basic, lightning-accordion-section, .slds-button",
1945
                                        "param": "value"
1946
                                    },
1947
                                    {"editContentByShadow(c-basic, lightning-accordion-section, .slds-button)" : "new text"},
1948
                                    {
1949
                                        "type": "editContent",
1950
                                        "shadow": "c-basic, lightning-accordion-section, .slds-button",
1951
                                        "param": "new text"
1952
                                    },
1953
                                    "clickByShadow(c-basic, lightning-accordion-section, .slds-button)",
1954
                                    {
1955
                                        "type": "click",
1956
                                        "shadow": "c-basic, lightning-accordion-section, .slds-button",
1957
                                    },
1958
                                    "doubleClickByShadow(c-basic, lightning-accordion-section, .slds-button)",
1959
                                    {
1960
                                        "type": "doubleClick",
1961
                                        "shadow": "c-basic, lightning-accordion-section, .slds-button",
1962
                                    },
1963
                                    "contextClickByShadow(c-basic, lightning-accordion-section, .slds-button)",
1964
                                    {
1965
                                        "type": "contextClick",
1966
                                        "shadow": "c-basic, lightning-accordion-section, .slds-button",
1967
                                    },
1968
                                    "mouseDownByShadow(c-basic, lightning-accordion-section, .slds-button)",
1969
                                    {
1970
                                        "type": "mouseDown",
1971
                                        "shadow": "c-basic, lightning-accordion-section, .slds-button",
1972
                                    },
1973
                                    "mouseUpByShadow(c-basic, lightning-accordion-section, .slds-button)",
1974
                                    {
1975
                                        "type": "mouseUp",
1976
                                        "shadow": "c-basic, lightning-accordion-section, .slds-button",
1977
                                    },
1978
                                    "mouseOutByShadow(c-basic, lightning-accordion-section, .slds-button)",
1979
                                    {
1980
                                        "type": "mouseOut",
1981
                                        "shadow": "c-basic, lightning-accordion-section, .slds-button",
1982
                                    },
1983
                                    "mouseOverByShadow(c-basic, lightning-accordion-section, .slds-button)",
1984
                                    {
1985
                                        "type": "mouseOver",
1986
                                        "shadow": "c-basic, lightning-accordion-section, .slds-button",
1987
                                    },
1988
                                    {"dragByShadow(c-basic, lightning-accordion-section, .slds-button)" : "elementById(id12)"},
1989
                                    {"dragById(id34)": "elementByShadow(c-basic, lightning-accordion-section, .slds-button)"},
1990
                                    {
1991
                                        "type": "drag",
1992
                                        "source": [
1993
                                            {"shadow": "c-basic, lightning-accordion-section, .slds-button"}
1994
                                        ],
1995
                                        "target": [
1996
                                            {"id": "id12"}
1997
                                        ]
1998
                                    },
1999
                                    {
2000
                                        "type": "drag",
2001
                                        "source": [
2002
                                            {"id": "id34"}
2003
                                        ],
2004
                                        "target": [
2005
                                            {"shadow": "c-basic, lightning-accordion-section, .slds-button"}
2006
                                        ]
2007
                                    },
2008
                                    {"selectByShadow(c-basic, lightning-accordion-section, .slds-button)": "value"},
2009
                                    {
2010
                                        "type": "select",
2011
                                        "shadow": "c-basic, lightning-accordion-section, .slds-button",
2012
                                        "param": "value"
2013
                                    },
2014
                                    {"storeTextByShadow(c-basic, lightning-accordion-section, .slds-button)": "my_var"},
2015
                                    {
2016
                                        "type": "storeText",
2017
                                        "shadow": "c-basic, lightning-accordion-section, .slds-button",
2018
                                        "param": "my_var"
2019
                                    },
2020
                                    {"storeValueByShadow(c-basic, lightning-accordion-section, .slds-button)": "my_var"},
2021
                                    {
2022
                                        "type": "storeValue",
2023
                                        "shadow": "c-basic, lightning-accordion-section, .slds-button",
2024
                                        "param": "my_var"
2025
                                    },
2026
                                    {"typeByShadow(c-basic, lightning-accordion-section, .slds-button)": "text"},
2027
                                    {
2028
                                        "type": "type",
2029
                                        "shadow": "c-basic, lightning-accordion-section, .slds-button",
2030
                                        "param": "text"
2031
                                    },
2032
                                    "submitByShadow(c-basic, lightning-accordion-section, .slds-button)",
2033
                                    {
2034
                                        "type": "submit",
2035
                                        "shadow": "c-basic, lightning-accordion-section, .slds-button"
2036
                                    },
2037
                                    {"keysByShadow(c-basic, lightning-accordion-section, .slds-button)": "KEY_ENTER"},
2038
                                    {
2039
                                        "type": "keys",
2040
                                        "shadow": "c-basic, lightning-accordion-section, .slds-button",
2041
                                        "param": "KEY_ENTER"
2042
                                    }
2043
                                ]
2044
                            }
2045
                        ]
2046
                    }
2047
                }
2048
            }
2049
        )
2050

2051 1
        self.obj.prepare()
2052 1
        exp_file = RESOURCES_DIR + "selenium/generated_from_requests_shadow.py"
2053 1
        str_to_replace = (self.obj.engine.artifacts_dir + os.path.sep).replace('\\', '\\\\')
2054 1
        self.assertFilesEqual(exp_file, self.obj.script, str_to_replace, "/somewhere/", python_files=True)

Read our documentation on viewing source code .

Loading