vomebook commited on
Commit
31fbccc
·
1 Parent(s): 265c27c

test: recover opening benchmark after failed navigation

Browse files
Files changed (1) hide show
  1. scripts/benchmark_reader_open.py +14 -5
scripts/benchmark_reader_open.py CHANGED
@@ -97,6 +97,8 @@ def main():
97
  requests.clear()
98
  started = time.monotonic()
99
  row = {'sample': name, 'attempt': attempt}
 
 
100
  try:
101
  if params is None:
102
  page.evaluate('()=>{randomTxt();}')
@@ -123,17 +125,24 @@ def main():
123
  row['media_metadata_seconds'] = round(time.monotonic()-started, 3)
124
  row['success'] = True
125
  frame.locator('#back').click()
126
- overlay.wait_for(state='detached')
 
127
  except Exception as error:
128
  row.update(success=False, error=str(error), elapsed_seconds=round(time.monotonic()-started, 3))
129
- try:
130
- page.evaluate('()=>closeReaderOverlay()')
131
- except Exception:
132
- home()
133
  row['network'] = list(requests.values())
134
  rows.append(row)
135
  print(json.dumps({k:v for k,v in row.items() if k not in ('network','stages','assets','resources')}, ensure_ascii=False), flush=True)
136
  save()
 
 
 
 
 
 
 
 
 
137
  page.wait_for_timeout(500)
138
  except Exception as error:
139
  row = {'sample': 'search-host', 'success': False, 'error': str(error),
 
97
  requests.clear()
98
  started = time.monotonic()
99
  row = {'sample': name, 'attempt': attempt}
100
+ return_url = page.url
101
+ reset_host = False
102
  try:
103
  if params is None:
104
  page.evaluate('()=>{randomTxt();}')
 
125
  row['media_metadata_seconds'] = round(time.monotonic()-started, 3)
126
  row['success'] = True
127
  frame.locator('#back').click()
128
+ overlay.wait_for(state='detached', timeout=5000)
129
+ page.wait_for_function('url=>location.pathname===new URL(url).pathname', arg=return_url, timeout=5000)
130
  except Exception as error:
131
  row.update(success=False, error=str(error), elapsed_seconds=round(time.monotonic()-started, 3))
132
+ reset_host = True
 
 
 
133
  row['network'] = list(requests.values())
134
  rows.append(row)
135
  print(json.dumps({k:v for k,v in row.items() if k not in ('network','stages','assets','resources')}, ensure_ascii=False), flush=True)
136
  save()
137
+ if reset_host:
138
+ # Closing only the iframe leaves an overlay history entry that
139
+ # a later Back can reopen. Reset this benchmark's failed trial.
140
+ page.evaluate('''url=>{
141
+ closeReaderOverlay();
142
+ sessionStorage.removeItem('reader-navigation-current');
143
+ history.replaceState(null,'',url);
144
+ }''', base + prefix + '/')
145
+ home()
146
  page.wait_for_timeout(500)
147
  except Exception as error:
148
  row = {'sample': 'search-host', 'success': False, 'error': str(error),