Skip to content

Commit

Permalink
Merge pull request #118 from quickstrom/html-report-timestamps
Browse files Browse the repository at this point in the history
Html report timestamps
  • Loading branch information
owickstrom committed Nov 18, 2022
2 parents a2ca09b + 3641c29 commit 7b82861
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
16 changes: 10 additions & 6 deletions quickstrom/executor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from ast import Await
import dataclasses
import io
import subprocess
Expand All @@ -8,7 +7,7 @@
from shutil import which
from dataclasses import dataclass
import png
from typing import List, Tuple, Union, Literal, Any, AnyStr
from typing import List, Union, Literal, Any
from selenium import webdriver
from selenium.common.exceptions import StaleElementReferenceException
from selenium.webdriver.common.action_chains import ActionChains
Expand Down Expand Up @@ -38,6 +37,7 @@ class SpecstromError(Exception):
def __str__(self):
return f"{self.message}, exit code {self.exit_code}"


@dataclass
class SpecstromAbortedError(Exception):
message: str
Expand Down Expand Up @@ -275,9 +275,10 @@ def run_sessions() -> List[result.PlainResult]:
raise e
except Exception as e:
send(Error(str(e)))
msg = receive()
msg = receive()
if not isinstance(msg, End):
raise Exception(f"Expected End after Error but got: {msg}")
raise Exception(
f"Expected End after Error but got: {msg}")
elif isinstance(msg, Done):
return [
attach_screenshots(result.from_protocol_result(r))
Expand All @@ -286,7 +287,8 @@ def run_sessions() -> List[result.PlainResult]:
elif isinstance(msg, Aborted):
raise SpecstromAbortedError(msg.error_message)
else:
raise Exception(f"Unexpected message in run_sessions: {msg}")
raise Exception(
f"Unexpected message in run_sessions: {msg}")

def await_session_commands(driver: WebDriver, deps, state_version):
try:
Expand Down Expand Up @@ -365,7 +367,9 @@ def new_driver(self):
if self.browser == 'chrome':
options = chrome_options.Options()
options.headless = self.headless
browser_path = self.browser_binary or which("chromium") or which("google-chrome-stable") or which("google-chrome") or which("chrome")
browser_path = self.browser_binary or which("chromium") or which(
"google-chrome-stable") or which("google-chrome") or which(
"chrome")
options.binary_location = browser_path # type: ignore
options.add_argument('--no-sandbox')
options.add_argument("--single-process")
Expand Down
17 changes: 11 additions & 6 deletions quickstrom/reporter/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from quickstrom.result import *
from quickstrom.reporter import Reporter
from pathlib import Path
from datetime import datetime
from datetime import datetime, timezone


@dataclass(frozen=True)
Expand All @@ -22,23 +22,27 @@ class JsonReporter(Reporter):
files_dir: Path

def report(self, result: PlainResult):
result_with_paths = write_screenshots(result, self.path.parent, self.files_dir)
result_with_paths = write_screenshots(result, self.path.parent,
self.files_dir)
report = Report(diff_result(result_with_paths), datetime.utcnow())
encode_file(report, self.path)


def write_screenshots(result: PlainResult,
base: Path,
def write_screenshots(result: PlainResult, base: Path,
dir: Path) -> ResultWithScreenshots[Path]:
os.makedirs(dir)

def on_state(
state: State[protocol.JsonLike,
bytes]) -> State[protocol.JsonLike, Path]:

if state.screenshot:
p = dir / Path(f"{state.hash}.png")
p.write_bytes(state.screenshot.image)
return State(state.hash, state.queries, Screenshot(p.relative_to(base), state.screenshot.width, state.screenshot.height, state.screenshot.scale))
return State(
state.hash, state.queries,
Screenshot(p.relative_to(base), state.screenshot.width,
state.screenshot.height, state.screenshot.scale))
else:
return State(state.hash, state.queries, None)

Expand All @@ -63,7 +67,8 @@ def default(self, o: Any):
if isinstance(o, Report):
return {
'result': self.default(o.result),
'generatedAt': str(o.generated_at),
'generatedAt':
o.generated_at.astimezone(timezone.utc).isoformat(),
'tag': 'Report'
}
elif isinstance(o, Passed):
Expand Down

0 comments on commit 7b82861

Please sign in to comment.