Beispiel #1
0
def get_interactive_page_source(url):
    """Obtém código-fonte completo da página."""
    # inicia o chrome para renderizar o código-fonte
    try:
        start_chrome(url, headless=True)
    except Exception:
        print(
            "Erro: você precisa instalar o Google Chrome e o ChromeDriver par"
            "a executar esse raspador.")
        sys.exit(1)

    driver = get_driver()

    # clica em todos os botões "Veja mais!" para liberar os dados dos resumos
    print(
        f"Raspando a página \"{driver.title}\". Isso pode demorar alguns segundos..."
    )
    buttons = find_all(S("//span[@onClick]"))
    for _ in tqdm(range(len(buttons))):
        click("Veja mais!")
    print('Fim da raspagem da página.')

    # obtém objeto soup a partir do código-fonte renderizado pelo helium
    soup = BeautifulSoup(driver.page_source, 'html.parser')

    # fecha o chrome
    kill_browser()

    return soup
Beispiel #2
0
 def tearDownClass(cls):
     popup_window_handle = Window("test_window - popup").handle
     main_window_handle = Window("test_window").handle
     get_driver().switch_to.window(popup_window_handle)
     get_driver().close()
     get_driver().switch_to.window(main_window_handle)
     super().tearDownClass()
    def test_4_NEW_WEBINTERFACE_PAGES_LOADED(self):
        # ======================================= #
        if not ApplyFirmware.firmware_valid:
            self.skip("Skip test 4: Firmware file is invalid!")

        self.driver = hm.get_driver()
        self.wait_for_exact_text_visible(
            "Загрузка новых страниц вебинтерфейса: 100%",
            selector="#status_res",
            timeout=60)

        assert "Загрузка новых страниц вебинтерфейса: 100%" in self.get_page_source(
        )
    def test_3_FIRMWARE_CODEBASE_REPLACED(self):
        # ==================================== #
        if not ApplyFirmware.firmware_valid:
            self.skip("Skip test 3: Firmware file is invalid!")

        self.driver = hm.get_driver()
        self.wait_for_exact_text_visible(
            "Переход на новый код прошивки успешно завершён",
            selector="#status_reboot",
            timeout=60)

        assert "Переход на новый код прошивки успешно завершён" in self.get_page_source(
        )
    def test_5_FIRMWARE_APPLIED(self):
        # ========================== #
        if not ApplyFirmware.firmware_valid:
            self.skip("Skip test 5: Firmware file is invalid!")

        self.driver = hm.get_driver()
        self.wait_for_exact_text_visible(
            "Обновление прошивки успешно завершено!",
            selector="#status_final",
            timeout=60)

        assert "Обновление прошивки успешно завершено!" in self.get_page_source(
        )
        self.driver.close()
    def test_2_FIRMWARE_LOADED(self):
        # ========================= #
        self.driver = hm.get_driver()
        if not ApplyFirmware.firmware_valid:
            self.skip("Skip test 2: Firmware file is invalid!")

        self.wait_for_exact_text_visible("test_firmware4.npu",
                                         selector="#dropname",
                                         timeout=10)
        self.click('#update', timeout=5)
        self.wait_for_exact_text_visible("Загрузка кода прошивки: 100%",
                                         selector="#status_fw",
                                         timeout=60)

        assert "Загрузка кода прошивки: 100%" in self.get_page_source()
    def test_1_DRAGN_DROP_FIRMWARE_VALID(self):
        # =================================== #
        hm.start_firefox(self.web_page_address, headless=True)
        browser = hm.get_driver()
        error_text = "Данный файл не содержит подходящую прошивку!"

        hm.drag_file(self.firmware_path + self.fw_fake_filename,
                     to=browser.find_element_by_id("holder"))
        hm.drag_file(self.firmware_path + self.fw_real_filename,
                     to=browser.find_element_by_id("holder"))

        error_message = '<span id="status_drop" class="alert">' + error_text + '</span>'
        ApplyFirmware.firmware_valid = error_message not in browser.page_source

        assert error_message not in browser.page_source, "Данный файл не содержит подходящую прошивку!"
Beispiel #8
0
 def test_access_attributes_across_iframes(self):
     text = Text("This text is inside an iframe.")
     self.assertEqual("This text is inside an iframe.", text.value)
     get_driver().switch_to.default_content()
     self.assertEqual("This text is inside an iframe.", text.value)
 def _is_in_popup(self):
     return get_driver().title == 'test_window_handling - Popup'
 def test_switch_to_after_window_closed(self):
     self._open_popup()
     get_driver().close()
     switch_to('test_window_handling - Main')
 def test_handles_closed_window_gracefully(self):
     self._open_popup()
     get_driver().close()
     is_back_in_main_window = Link("Open popup").exists()
     self.assertTrue(is_back_in_main_window)
Beispiel #12
0
            / args.slide_path_or_directory_name
        )
        slides = list(slide_directory.glob("*.html"))
        assert len(slides) == 1, str(slides)
        slide_html_path = slides[0]
    else:
        # Case: slide path
        slide_html_path = Path(args.slide_path_or_directory_name).resolve()
    slide_page_url = slide_html_path.as_uri()
    # タイトルが長い場合は2枚めを使う運用をしている
    if args.is_long_title:
        slide_page_url += "#/1"

    if not args.output_path:
        args.output_path = (
            project_root
            / "docs"
            / "_images"
            / "ogps"
            / f"{slide_html_path.stem}.png"
        )

    options = FirefoxOptions()
    options.add_argument("--width=800")
    options.add_argument("--height=485")  # ブラウザウィンドウ上部が85px分ある

    start_firefox(options=options, headless=True)
    go_to(slide_page_url)  # TODO: #/1 のようにページの指定を追加可能に
    get_driver().save_screenshot(str(args.output_path))
    kill_browser()