Skip to content

Commit

Permalink
fix: prevent test errors
Browse files Browse the repository at this point in the history
  • Loading branch information
adeprez committed Sep 3, 2024
1 parent a5a6725 commit c9454bb
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,9 @@ def click(self, xpath: str):
f"Failed to click at element coordinates of {xpath} : {str(click_error)}"
)
except Exception as e:
import traceback

traceback.print_exc()
raise Exception(
f"An unexpected error occurred when trying to click on {xpath}: {str(e)}"
)
Expand Down
2 changes: 1 addition & 1 deletion lavague-tests/lavague/tests/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def cli(


def _load_sites(directory, site):
sites_to_test: List[Path] = []
sites_to_test: List[TestConfig] = []
try:
for item in os.listdir(directory):
if (len(site) == 0 or item in site) and os.path.isfile(
Expand Down
5 changes: 1 addition & 4 deletions lavague-tests/lavague/tests/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,9 @@ def __init__(
def run(self) -> RunnerResult:
results: List[RunResults] = []
for site in self.sites:
try:
site.setup.start()
with site.setup:
task_results = self._run_tasks(site.tasks)
results.append(RunResults(site, task_results))
finally:
site.setup.stop()

return RunnerResult(results)

Expand Down
29 changes: 19 additions & 10 deletions lavague-tests/lavague/tests/setup.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
from typing import Dict
from typing import Dict, Optional, Any
import http.server
import socketserver
import threading
import os


class Setup:
default_url: str = None
default_url: Optional[str] = None

def __enter__(self):
self.start()
return self

def __exit__(self, exc_type, exc_value, traceback):
self.stop()

def start(self):
pass
Expand All @@ -16,27 +23,29 @@ def stop(self):

@staticmethod
def parse(directory: str, args: Dict) -> "Setup":
if args.get("type", "web") == "web":
return Setup()

if args["type"] == "static":
directory = os.path.join(directory, args.get("directory", "www"))
return StaticServer(directory, args.get("port", "8000"))

return Setup()


class StaticServer(Setup):
default_url = "http://localhost:8000"
httpd: socketserver.TCPServer = None
httpd: Optional[socketserver.TCPServer] = None

def __init__(self, directory: str, port: int):
self.directory = directory
self.port = port

def start(self):
def handler(*args, **kwargs):
http.server.SimpleHTTPRequestHandler(
*args, directory=self.directory, **kwargs
)
def handler(*args, **kwargs) -> Any:
try:
return http.server.SimpleHTTPRequestHandler(
*args, directory=self.directory, **kwargs
)
except ConnectionResetError:
pass

self.httpd = socketserver.TCPServer(("", self.port), handler)
self.thread = threading.Thread(target=self.httpd.serve_forever)
Expand Down
12 changes: 1 addition & 11 deletions lavague-tests/sites/examples/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,10 @@ type: static
port: 8000
directory: www
tasks:

- name: Navigate using link
url: http://localhost:8000
prompt: Go to the menu
max_steps: 1
expect:
- URL is http://localhost:8000/menu.html
- HTML contains <h1>Menu</h1>

- name: Upload a file
url: http://localhost:8000/file.html
prompt: Upload my picture
max_steps: 1
user_data:
my_picture: dummy_file.png
expect:
- HTML contains File uploaded
- HTML contains <h1>Menu</h1>
33 changes: 0 additions & 33 deletions lavague-tests/sites/examples/www/file.html

This file was deleted.

0 comments on commit c9454bb

Please sign in to comment.