Project

General

Profile

« Previous | Next » 

Revision ad69f9c8

Added by koszko over 1 year ago

add support for testing with other browsers (especially Abrowser and Librewolf)

There are still some spurious failures when running under those newer browsers. Those will be systematically investigated and fixed.

View differences:

test/unit/test_patterns_query_manager.py
20 20
import pytest
21 21
import json
22 22
from selenium.webdriver.support.ui import WebDriverWait
23
from selenium.common.exceptions import TimeoutException
23 24

  
24 25
from ..script_loader import load_script
25 26

  
......
240 241
@pytest.mark.usefixtures('webextension')
241 242
def test_pqm_script_injection(driver, execute_in_page):
242 243
    # Let's open a normal page in a second window. Window 0 will be used to make
243
    # changed to IndexedDB and window 1 to test the working of content scripts.
244
    # changes to IndexedDB and window 1 to test the working of content scripts.
244 245
    driver.execute_script('window.open("about:blank", "_blank");')
245 246
    WebDriverWait(driver, 10).until(lambda d: len(d.window_handles) == 2)
246 247
    windows = [*driver.window_handles]
247 248

  
248
    def run_content_script():
249
        driver.switch_to.window(windows[1])
250
        driver.get('https://gotmyowndoma.in/index.html')
251
        windows[1] = driver.window_handles[1]
249
    def get_tree_json(driver):
252 250
        return driver.execute_script(
253 251
            '''
254 252
            return (document.getElementById("tree-json") || {}).innerText;
255 253
            ''')
256 254

  
257
    for attempt in range(10):
255
    def run_content_script():
256
        driver.switch_to.window(windows[1])
257
        driver.get('https://gotmyowndoma.in/index.html')
258
        windows[1] = driver.current_window_handle
259
        try:
260
            return WebDriverWait(driver, 10).until(get_tree_json)
261
        except TimeoutException:
262
            pass
263

  
264
    for attempt in range(2):
258 265
        json_txt = run_content_script()
259
        if json.loads(json_txt) == {}:
266
        if json_txt and json.loads(json_txt) == {}:
260 267
            break;
261
        assert attempt != 9
268
        assert attempt != 2
262 269

  
263 270
    driver.switch_to.window(windows[0])
264 271
    execute_in_page(load_script('common/indexeddb.js'))
......
271 278
    }
272 279
    execute_in_page('returnval(save_items(arguments[0]));', sample_data)
273 280

  
274
    for attempt in range(10):
275
        tree_json = run_content_script()
281
    for attempt in range(2):
282
        tree_json = run_content_script() or '{}'
276 283
        json.loads(tree_json)
277 284
        if all([m['identifier'] in tree_json for m in sample_mappings]):
278 285
            break
279
        assert attempt != 9
286
        assert attempt != 2
280 287

  
281 288
    driver.switch_to.window(windows[0])
282 289
    execute_in_page(

Also available in: Unified diff