|
3 | 3 | import json |
4 | 4 | import time |
5 | 5 | import pyautogui |
| 6 | +import logging |
6 | 7 | from dotenv import load_dotenv |
7 | 8 | from selenium import webdriver |
8 | 9 | from selenium.webdriver.chrome.options import Options |
9 | 10 | from selenium.webdriver.chrome.service import Service |
10 | 11 | from webdriver_manager.chrome import ChromeDriverManager |
11 | 12 | from selenium.common.exceptions import WebDriverException |
12 | | -import logging |
13 | 13 |
|
14 | 14 | load_dotenv() |
15 | 15 | api_key = os.getenv('OPENAI_API_KEY') |
16 | 16 |
|
| 17 | +dataset = 'tasks_test.jsonl' |
| 18 | + |
17 | 19 | # Place to store task execution results |
18 | 20 | results_dir = 'results' |
19 | 21 | os.makedirs(results_dir, exist_ok=True) |
20 | 22 |
|
21 | | -dataset = 'tasks_test.jsonl' |
22 | | -example_dataset = 'example_test.jsonl' |
23 | | - |
24 | 23 | # Setup logging |
25 | 24 | logs_path = 'webwand_test_log.txt' |
26 | | -sample_logs_path = 'webwand_test_log_example.txt' |
27 | | -logging.basicConfig(filename=sample_logs_path, level=logging.INFO, format='%(asctime)s:%(levelname)s:%(message)s') |
| 25 | +logging.basicConfig(filename=logs_path, level=logging.INFO, format='%(asctime)s:%(levelname)s:%(message)s') |
28 | 26 |
|
29 | 27 | def setup_driver(): |
30 | 28 | chrome_options = Options() |
@@ -56,26 +54,21 @@ def add_task_listener(driver, task_id, max_retries=3): |
56 | 54 | var callback = arguments[0]; |
57 | 55 | var eventListener = function (e) {{ |
58 | 56 | if (e.detail.type == 'history') {{ |
59 | | - console.log("event listener received history event"); |
60 | 57 | if (e.detail.status === 'success' || e.detail.status === 'error') {{ |
61 | 58 | document.removeEventListener('TaskUpdate', eventListener); |
62 | | - console.log("event listener removed"); |
63 | 59 | callback({{status: e.detail.status, type: 'history', data: e.detail.data}}); |
64 | 60 | }} |
65 | 61 | // Does not do anything when the status is 'running' or 'idle'. |
66 | 62 | // The status 'interrupted' will never be triggered automatically. |
67 | 63 | }} else if (e.detail.type == 'screenshot') {{ |
68 | | - console.log("event listener received screenshot event"); |
69 | 64 | document.removeEventListener('TaskUpdate', eventListener); |
70 | | - console.log("event listener removed"); |
71 | 65 | callback({{status: e.detail.status, type: 'screenshot', data: e.detail.data}}); |
72 | 66 | }} else {{ |
73 | 67 | throw new Error("Invalid event type received: " + e.detail.type); |
74 | 68 | }} |
75 | 69 | }}; |
76 | 70 |
|
77 | 71 | document.addEventListener('TaskUpdate', eventListener); |
78 | | - console.log("added event listener"); |
79 | 72 | """ |
80 | 73 |
|
81 | 74 | attempts = 0 |
@@ -175,15 +168,14 @@ def click_extensions_icon(driver): |
175 | 168 | right = window_position['x'] + window_position['width'] |
176 | 169 | # click Extensions icon |
177 | 170 | pyautogui.click(right - 150, top + 50) |
178 | | - |
179 | 171 | # click webwand |
180 | 172 | pyautogui.click(right - 300, top + 210) |
181 | 173 |
|
182 | 174 | def main(): |
183 | 175 | driver = setup_driver() |
184 | 176 | initial_load = True |
185 | 177 |
|
186 | | - with open(example_dataset, 'r') as file: |
| 178 | + with open(dataset, 'r') as file: |
187 | 179 | for line in file: |
188 | 180 | logging.info(f'-------------------------------------') |
189 | 181 | task = json.loads(line) |
|
0 commit comments