def do_upload(prep_upload, expect_ask):
        """Upload the scenario to our test endpoint."""

        # show the scenario card
        find_child("button.scenario-search").click()
        wait_for(2, _find_scenario_card)

        # open the upload dialog
        find_child(".ui-dialog.scenario-info button.upload").click()
        dlg = wait_for_elem(2, ".ui-dialog.scenario-upload")
        if prep_upload:
            prep_upload(dlg)

        # start the upload
        webapp.control_tests.reset_last_asa_upload()
        find_child("button.upload", dlg).click()
        if expect_ask:
            dlg = wait_for_elem(2, ".ui-dialog.ask")
            find_child("button.ok", dlg).click()

        # wait for the upload to be processed
        last_asa_upload = wait_for(5, webapp.control_tests.get_last_asa_upload)
        assert last_asa_upload["user"] == user_name
        assert last_asa_upload["token"] == api_token
        return last_asa_upload
示例#2
0
def _analyze_vlogs(fnames):
    """Analyze log file(s)."""

    # initialize
    if isinstance(fnames, str):
        fnames = [fnames]
    select_menu_option("analyze_vlog")
    dlg = wait_for_elem(2, ".ui-dialog.lfa-upload")

    # add each log file
    for fno, fname in enumerate(fnames):
        fname = os.path.join(
            os.path.split(__file__)[0], "fixtures/analyze-vlog/" + fname)
        with open(fname, "rb") as fp:
            vlog_data = fp.read()
        set_stored_msg(
            "_vlog-persistence_", "{}|{}".format(
                os.path.split(fname)[1],
                base64.b64encode(vlog_data).decode("utf-8")))
        find_child("#lfa-upload .{}".format("hint" if fno == 0 else "files"),
                   dlg).click()
        wait_for(2, lambda: get_stored_msg("_vlog-persistence_") == "")

    # start the analysis
    find_child("button.ok", dlg).click()
    wait_for_elem(30, "#lfa")
def _unlink_scenario():
    """Unlink the scenario from the ASL Scenario Archive."""
    find_child("button.scenario-search").click()
    wait_for_elem(2, "#scenario-info-dialog")
    btn = find_children(".ui-dialog .ui-dialog-buttonpane button")[1]
    assert btn.text == "Unlink"
    btn.click()
示例#4
0
 def unload_report():
     """Unload the hotness popup."""
     find_child("#lfa .hotness img.dice").click()
     wait_for_elem(2, "#lfa .hotness-popup")
     report = {}
     for key in ("2s", "12s", "snipers"):
         report[key] = unload_table(
             "//div[@class='hotness-popup']//table[@class='{}']//tr".format(
                 key))
     return report
def _get_scenario_info():
    """Open the scenario info and unload the information."""
    btn = find_child("button.scenario-search")
    assert find_child("img", btn).get_attribute("src").endswith("/info.gif")
    btn.click()
    wait_for_elem(2, "#scenario-info-dialog")
    card = _unload_scenario_card()
    btn = find_children(".ui-dialog .ui-dialog-buttonpane button")[0]
    assert btn.text == "OK"
    btn.click()
    return card
示例#6
0
def _select_log_file(fname):
    """Select one of the log files being analyzed."""
    find_child("#lfa .banner .select-file").click()
    popup = wait_for_elem(2, "#lfa .select-file-popup")
    for row in find_children(".row", popup):
        if find_child("label", row).text == fname:
            find_child("input[type='radio']", row).click()
            return
    assert False, "Couldn't find file: " + fname
示例#7
0
 def check_color_pickers(expected):
     """Check which color pickers are being presented to the user."""
     find_child("#lfa .options button.player-colors").click()
     popup = wait_for_elem(2, "#lfa .player-colors-popup")
     player_names = [
         e.text for e in find_children(".row .caption", popup) if e.text
     ]
     assert player_names.pop() == "expected results"
     assert player_names == expected
示例#8
0
def test_multiple_images(webapp, webdriver):
    """Test handling of VASL counters that have multiple images."""

    # initialize
    webapp.control_tests \
        .set_data_dir( "{REAL}" ) \
        .set_vasl_version( "random", None )
    init_webapp(webapp, webdriver, scenario_persistence=1)

    # load the test scenario
    load_scenario({
        "PLAYER_1": "british",
        "OB_VEHICLES_1": [{
            "name": "2pdr Portee"
        }],
    })

    # configure the user settings
    set_user_settings({
        "scenario-images-source": SCENARIO_IMAGES_SOURCE_INTERNET,
        "include-vasl-images-in-snippets": True,
    })

    # generate a snippet for the vehicle (using the default image)
    select_tab("ob1")
    btn = find_child("button[data-id='ob_vehicles_1']")
    btn.click()
    wait_for_clipboard(
        2,
        re.compile(
            r'<img src="https://raw.githubusercontent.com/.+/br/vehicles/portee.gif"'
        ))

    # select the second image for the vehicle
    sortable = find_child("#ob_vehicles-sortable_1")
    elems = find_children("li", sortable)
    assert len(elems) == 1
    ActionChains(webdriver).double_click(elems[0]).perform()
    btn = wait_for_elem(2, "#edit-vo input.select-vo-image")
    btn.click()
    images = find_children(".ui-dialog.select-vo-image .vo-images img")
    assert len(images) == 2
    images[1].click()
    click_dialog_button("OK")

    # generate a snippet for the vehicle (using the new image)
    btn = find_child("button[data-id='ob_vehicles_1']")
    btn.click()
    wait_for_clipboard(
        2,
        re.compile(
            r'<img src="https://raw.githubusercontent.com/.+/br/vehicles/portee0.gif"'
        ))
示例#9
0
def test_help(webapp, webdriver):
    """Test the help page."""

    # initialize
    init_webapp(webapp, webdriver)

    # make sure the HELP tab is not visible
    def get_tabs():
        """Get the visible tabs."""
        return [
            c.get_attribute("aria-controls")
            for c in find_children("#tabs .ui-tabs-tab") if c.is_displayed()
        ]

    assert "tabs-help" not in get_tabs()

    # show the help
    select_menu_option("show_help")

    # make sure that the HELP tab is now visible
    assert "tabs-help" in get_tabs()

    # check what's in the help iframe
    try:

        # switch to the frame
        webdriver.switch_to.frame(find_child("#tabs-help iframe"))

        # check that the content loaded OK
        assert "everyone's favorite scenario" in webdriver.page_source

        # check that the license loaded OK
        elem = wait_for_elem(2, "a.ui-tabs-anchor[href='#helptabs-license']")
        assert elem.is_displayed()
        wait_for(
            2, lambda: "GNU AFFERO GENERAL PUBLIC LICENSE" in webdriver.
            page_source)
        assert "Version 3" in webdriver.page_source

    finally:

        # switch back to the main window
        webdriver.switch_to.default_content()
def _do_scenario_search(query, expected, webdriver):
    """Do a scenario search."""

    # find the dialog
    dlg = find_child("#scenario-search")
    if not dlg.is_displayed():
        select_tab("scenario")
        btn = find_child("button.scenario-search")
        ActionChains(webdriver).key_down(Keys.SHIFT).click(btn).perform()
        dlg = wait_for_elem(2, "#scenario-search")
        ActionChains(webdriver).key_up(Keys.SHIFT).perform()

    # initialize
    card = find_child(".scenario-card", dlg)
    seq_no = card.get_attribute("data-seqNo")

    # do the search and check the results
    elem = find_child("input.select2-search__field", dlg)
    elem.clear()
    # IMPORTANT: We can't use send_keys() here because it simulates a key-press for each character in the query,
    # and the incremental search feature means that we will constantly be loading scenario cards as the results
    # change, which makes it difficult for us to be able to tell when everything's stopped and it's safe to unload
    # the scenario card. Instead, we manually load the text box and trigger an event to update the UI.
    webdriver.execute_script(
        "arguments[0].value = arguments[1] ; $(arguments[0]).trigger('input')",
        elem, query)

    def check_search_results():  #pylint: disable=missing-docstring
        results = _unload_search_results()
        return [r[0] for r in results] == [str(e) for e in expected]

    wait_for(2, check_search_results)

    # wait for the scenario card to finish loading
    # NOTE: We do this here since the typical use case is to search for something, then check what was found.
    wait_for(2, lambda: card.get_attribute("data-seqNo") != seq_no)

    return dlg
 def unload_downloads():
     """Unload the available downloads."""
     btn = find_child(
         ".ui-dialog.scenario-search .import-control button.downloads")
     if not btn.is_enabled():
         return None
     btn.click()
     dlg = wait_for_elem(2, "#scenario-downloads-dialog")
     # unload the file groups
     fgroups = []
     for elem in find_children(".fgroup", dlg):
         fgroup = {
             "screenshot":
             fixup(
                 find_child(".screenshot img", elem).get_attribute("src")),
             "user":
             fixup(find_child(".user", elem).text),
             "timestamp":
             fixup(find_child(".timestamp", elem).text),
         }
         add_download_url(fgroup, "vt_setup", elem)
         add_download_url(fgroup, "vasl_setup", elem)
         fgroups.append(fgroup)
     return fgroups
def test_roar_linking(webapp, webdriver):
    """Test linking scenarios with ROAR scenarios."""

    # initialize
    init_webapp(webapp, webdriver)

    def check(bgraph, connect, disconnect):
        """Check the scenario card."""

        # check if the balance graph is shown
        try:
            card = _unload_scenario_card()
        except StaleElementReferenceException:
            # NOTE: We can get here if the scenario card is reloaded while we're reading it.
            return False
        if bgraph:
            balance = card["balances"].get("roar")
            if not balance:
                return False
            if balance[0]["name"] != bgraph[0] or balance[1]["name"] != bgraph[
                    1]:
                return False
        else:
            if "roar" in card["balances"]:
                return False

        # check if the "connect to ROAR" button is shown
        elem = find_child("#scenario-info-dialog .connect-roar")
        if connect:
            if not elem.is_displayed():
                return False
        else:
            if elem and elem.is_displayed():
                return False

        # check if the "disconnect from ROAR" is shown
        elem = find_child("#scenario-info-dialog .disconnect-roar")
        if disconnect:
            if not elem.is_displayed():
                return False
        else:
            if elem and elem.is_displayed():
                return False

        return True

    def disconnect_roar():
        """Disconnect the scenario from ROAR."""
        btn = find_child("#scenario-info-dialog .disconnect-roar")
        btn.click()
        wait_for(2, lambda: not btn.is_displayed())
        wait_for(2, lambda: check(None, True, False))

    # import the "Fighting Withdrawal" scenario
    dlg = _do_scenario_search("withdrawal", [2], webdriver)
    wait_for(2, lambda: check(["Russian", "Finnish"], False, False))
    find_child("#scenario-search button.import").click()
    wait_for(2, lambda: not dlg.is_displayed())

    # connect to another ROAR scenario
    find_child("button.scenario-search").click()
    wait_for(2, lambda: check(["Russian", "Finnish"], False, True))
    disconnect_roar()
    find_child("#scenario-info-dialog .connect-roar").click()
    dlg = wait_for_elem(2, ".ui-dialog.select-roar-scenario")
    find_child(".select2-search__field", dlg).send_keys("another")
    find_child(".select2-search__field", dlg).send_keys(Keys.RETURN)
    wait_for(2, lambda: check(["British", "French"], False, True))
    find_child(".ui-dialog.scenario-info button.ok").click()

    # disconnect from the ROAR scenario
    find_child("button.scenario-search").click()
    wait_for(2, lambda: check(["British", "French"], False, True))
    disconnect_roar()
    find_child(".ui-dialog.scenario-info button.ok").click()

    # connect to a ROAR scenario
    find_child("button.scenario-search").click()
    wait_for(2, lambda: check(None, True, False))
    find_child("#scenario-info-dialog .connect-roar").click()
    dlg = wait_for_elem(2, ".ui-dialog.select-roar-scenario")
    elem = find_child(".select2-search__field", dlg)
    elem.send_keys("withdrawal")
    elem.send_keys(Keys.RETURN)
    wait_for(2, lambda: check(["Russian", "Finnish"], False, True))
    find_child(".ui-dialog.scenario-info button.ok").click()
def _import_scenario_and_confirm(dlg):
    """Import a scenario, confirming any warnings."""
    _click_import_button(dlg)
    btn = wait_for_elem(2, "button.confirm-import", dlg)
    btn.click()
    wait_for(2, lambda: not dlg.is_displayed())