Skip to content

Commit

Permalink
Final interaction improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
szymsza committed Nov 1, 2024
1 parent 52211d0 commit 639441c
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 17 deletions.
4 changes: 4 additions & 0 deletions bci/browser/configuration/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ def _get_executable_file_path(self) -> str:
def _get_terminal_args(self) -> list[str]:
pass

@abstractmethod
def get_navigation_sleep_duration(self) -> int:
pass

@staticmethod
def get_browser(
browser_config: BrowserConfiguration, eval_config: EvaluationConfiguration, state: State
Expand Down
3 changes: 3 additions & 0 deletions bci/browser/configuration/chromium.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@

class Chromium(Browser):

def get_navigation_sleep_duration(self) -> int:
return 1

def _get_terminal_args(self) -> list[str]:
assert self._profile_path is not None

Expand Down
3 changes: 3 additions & 0 deletions bci/browser/configuration/firefox.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@

class Firefox(Browser):

def get_navigation_sleep_duration(self) -> int:
return 2

def _get_terminal_args(self) -> list[str]:
assert self._profile_path is not None

Expand Down
17 changes: 11 additions & 6 deletions bci/browser/interaction/interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@ def __init__(self, browser: BrowserConfig, script: list[str], params: TestParame
def execute(self) -> None:
simulation = Simulation(self.browser, self.params)

self._interpret(simulation)
simulation.sleep('0.5')
if self._interpret(simulation):
simulation.sleep(str(self.browser.get_navigation_sleep_duration()))
simulation.navigate('https://a.test/report/?bughog_sanity_check=OK')

simulation.navigate('https://a.test/report/?bughog_sanity_check=OK')

def _interpret(self, simulation: Simulation) -> None:
def _interpret(self, simulation: Simulation) -> bool:
for statement in self.script:
if statement.strip() == '' or statement[0] == '#':
continue
Expand All @@ -49,4 +48,10 @@ def _interpret(self, simulation: Simulation) -> None:
)

logger.debug(f'Executing interaction method `{method_name}` with the arguments {args}')
method(*args)

try:
method(*args)
except:
return False

return True
2 changes: 1 addition & 1 deletion bci/browser/interaction/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def parse_position(self, position: str, max_value: int) -> int:
def navigate(self, url: str):
self.browser_config.terminate()
self.browser_config.open(url)
self.sleep('0.5')
self.sleep(str(self.browser_config.get_navigation_sleep_duration()))

def click_position(self, x: str, y: str):
max_x, max_y = gui.size()
Expand Down
2 changes: 1 addition & 1 deletion experiments/pages/Support/AutoGUI/a.test/main/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<script src="/res/bughog.js"></script>
</head>
<body>
<form action="/report" method="GET">
<form action="/report/" method="GET">
<input id="one">
<input name="leak" id="two">
<input type="submit">
Expand Down
4 changes: 2 additions & 2 deletions experiments/pages/Support/AutoGUI/interaction_script.cmd
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
NAVIGATE https://a.test/Support/AutoGUI/main
SLEEP 1
SCREENSHOT test

SCREENSHOT click1
CLICK one
WRITE AutoGUI
HOTKEY ctrl a
HOTKEY ctrl c

SCREENSHOT click2
CLICK two

# Equivalent to HOTKEY ctrl v
Expand Down
14 changes: 7 additions & 7 deletions experiments/res/bughog.css
Original file line number Diff line number Diff line change
Expand Up @@ -30,34 +30,34 @@
#two {
background-color: #dcbeff;
color: #dcbeff;
top: 45px;
top: 70px;
left: 10px;
}

#three {
background-color: #ffe119;
color: #ffe119;
top: 80px;
top: 130px;
left: 10px;
}

#four {
background-color: #4363d8;
color: #4363d8;
top: 10px;
left: 45px;
left: 85px;
}

#five {
background-color: #f58231;
color: #f58231;
top: 45px;
left: 45px;
top: 70px;
left: 85px;
}

#six {
background-color: #000075;
color: #000075;
top: 80px;
left: 45px;
top: 130px;
left: 85px;
}

0 comments on commit 639441c

Please sign in to comment.