| 517 | |
| 518 | |
| 519 | class Script(ScriptProcess): |
| 520 | |
| 521 | @check |
| 522 | def __init__(self, script: dict | str | list, global_script: dict | str | list = None, interval: float = 0.5, |
| 523 | wait: float = 10, is_need_syntax_check: bool = True): |
| 524 | """ |
| 525 | Script Parser |
| 526 | :param script: Need a str of json or dict or list steps that conforms to syntax conventions |
| 527 | :param global_script: This script will be executed before every actions |
| 528 | :param interval: The direct interval between two consecutive scripts |
| 529 | :param wait: The longest wait time before presence of element located |
| 530 | :param is_need_syntax_check: Whether the script need a syntax check |
| 531 | """ |
| 532 | self.script = ScriptProcess.generate(script) |
| 533 | if global_script is None: |
| 534 | self.global_script = {} |
| 535 | else: |
| 536 | self.global_script = ScriptProcess.generate(global_script) |
| 537 | self.is_need_syntax_check = is_need_syntax_check |
| 538 | if self.is_need_syntax_check: |
| 539 | ScriptProcess.syntax_check(self.script) |
| 540 | ScriptProcess.syntax_check(self.global_script) |
| 541 | assert interval >= 0 |
| 542 | assert wait >= 0 |
| 543 | self.interval = interval |
| 544 | self.wait = wait |
| 545 | self.return_record = {} |
| 546 | |
| 547 | @check |
| 548 | def process(self, webdriver: WebDriver, variable: VariableBase = None, store: StoreBase = None) -> Any: |
| 549 | """ |
| 550 | process the script |
| 551 | """ |
| 552 | self.return_record.clear() |
| 553 | if self.is_need_syntax_check: |
| 554 | ScriptProcess.syntax_check(self.script) |
| 555 | ScriptProcess.syntax_check(self.global_script) |
| 556 | script = copy.deepcopy(self.script) |
| 557 | global_script = copy.deepcopy(self.global_script) |
| 558 | if variable: |
| 559 | ScriptProcess._replace_variable(script, variable) |
| 560 | ScriptProcess._replace_variable(global_script, variable) |
| 561 | if self.is_need_syntax_check: |
| 562 | ScriptProcess.syntax_check(script) |
| 563 | ScriptProcess.syntax_check(global_script) |
| 564 | return ScriptProcess._process_script(script=script, |
| 565 | global_script=global_script, |
| 566 | webdriver=webdriver, |
| 567 | return_record=self.return_record, |
| 568 | store=store, |
| 569 | interval=self.interval, |
| 570 | wait=self.wait) |
| 571 | |
| 572 | def __call__(self, webdriver: WebDriver): |
| 573 | return self.process(webdriver) |
nothing calls this directly
no outgoing calls
no test coverage detected