示例#1
0
def test_can_see_statistic_by_superuser(selenium: WebDriver):
    selenium.get(base_url)
    selenium.find_element_by_id("SignInButton").click()
    selenium.find_element_by_name("username").send_keys("walrus")
    selenium.find_element_by_name("password").send_keys("wal")
    selenium.find_element_by_id("SubmitLoginButton").click()

    selenium.find_element_by_id("StatisticsButton").click()

    assert selenium.current_url == base_url + "stats/"
示例#2
0
def test_can_navigate_to_user_profile(selenium: WebDriver):
    selenium.get(base_url)
    selenium.find_element_by_id("SignInButton").click()
    selenium.find_element_by_name("username").send_keys("chifir")
    selenium.find_element_by_name("password").send_keys(
        "thispasswordistooshort")
    selenium.find_element_by_id("SubmitLoginButton").click()

    selenium.find_element_by_id("UserProfileButton").click()

    assert selenium.current_url == base_url + "users/chifir/"
示例#3
0
def test_can_sign_out(selenium: WebDriver):
    selenium.get(base_url)
    selenium.find_element_by_id("SignInButton").click()
    selenium.find_element_by_name("username").send_keys("chifir")
    selenium.find_element_by_name("password").send_keys(
        "thispasswordistooshort")
    selenium.find_element_by_id("SubmitLoginButton").click()

    selenium.find_element_by_id("SignOutButton").click()

    assert selenium.current_url == base_url
    selenium.find_element_by_id("SignInButton")
    def verificar_elemento_html_hasta_no_existir_en_el_dom_html(
            web_driver: WebDriver,
            time=5,
            id=None,
            xpath=None,
            link_text=None,
            partial_link_text=None,
            name=None,
            tag_name=None,
            class_name=None,
            css_selector=None):

        msg_selector_html_a_localizar = HtmlActions.generar_identificador_excepcion(
            id, xpath, link_text, partial_link_text, name, tag_name,
            class_name, css_selector)

        tiempo_inicial = Temporizador.obtener_tiempo_timer()

        while True:
            try:
                if id is not None:
                    web_driver.find_element_by_id(id)
                elif xpath is not None:
                    web_driver.find_element_by_xpath(xpath)
                elif link_text is not None:
                    web_driver.find_element_by_link_text(link_text)
                elif partial_link_text is not None:
                    web_driver.find_element_by_partial_link_text(
                        partial_link_text)
                elif name is not None:
                    web_driver.find_element_by_name(name)
                elif tag_name is not None:
                    web_driver.find_element_by_tag_name(tag_name)
                elif class_name is not None:
                    web_driver.find_element_by_class_name(class_name)
                elif css_selector is not None:
                    web_driver.find_element_by_css_selector(css_selector)

                segundos_transcurridos = Temporizador.obtener_tiempo_timer(
                ) - tiempo_inicial

                if segundos_transcurridos > time:
                    e = TimeoutException()
                    e.msg = webdriver_actions_constantes.WEBDRIVER_WAIT_UNTIL_NOT_TIMEOUT_EXCEPTION.format(
                        time, msg_selector_html_a_localizar, e.msg)

                    raise e
                else:
                    pass

            except NoSuchElementException:
                break
示例#5
0
def test_can_autentificate_user(selenium: WebDriver):
    selenium.get(base_url)
    sign_in_elem = selenium.find_element_by_id("SignInButton")
    sign_in_elem.click()

    username_elem = selenium.find_element_by_name("username")
    username_elem.send_keys("chifir")
    password_elem = selenium.find_element_by_name("password")
    password_elem.send_keys("thispasswordistooshort")
    submit_elem = selenium.find_element_by_id("SubmitLoginButton")
    submit_elem.click()

    assert selenium.current_url == base_url
class MouseTest(unittest.TestCase):
  """Mouse command tests for the json webdriver protocol"""

  def setUp(self):
    self._launcher = ChromeDriverLauncher(root_path=os.path.dirname(__file__))
    self._driver = WebDriver(self._launcher.GetURL(),
                             DesiredCapabilities.CHROME)

  def tearDown(self):
    self._driver.quit()
    self._launcher.Kill()

  def testClickElementThatNeedsContainerScrolling(self):
    self._driver.get(self._launcher.GetURL() + '/test_page.html')
    self._driver.find_element_by_name('hidden_scroll').click()
    self.assertTrue(self._driver.execute_script('return window.success'))

  def testClickElementThatNeedsIframeScrolling(self):
    self._driver.get(self._launcher.GetURL() + '/test_page.html')
    self._driver.switch_to_frame('iframe')
    self._driver.find_element_by_name('hidden_scroll').click()
    self.assertTrue(self._driver.execute_script('return window.success'))

  def testClickElementThatNeedsPageScrolling(self):
    self._driver.get(self._launcher.GetURL() + '/test_page.html')
    self._driver.find_element_by_name('far_away').click()
    self.assertTrue(self._driver.execute_script('return window.success'))

  def testDoNotScrollUnnecessarilyToClick(self):
    self._driver.get(self._launcher.GetURL() + '/test_page.html')
    self._driver.find_element_by_name('near_top').click()
    self.assertTrue(self._driver.execute_script('return window.success'))
    script = 'return document.body.scrollTop == 0 && ' \
             '       document.body.scrollLeft == 0'
    self.assertTrue(self._driver.execute_script(script))
示例#7
0
def test_cant_autentificate_wrong_user(selenium: WebDriver):
    selenium.get(base_url)
    sign_in_elem = selenium.find_element_by_id("SignInButton")
    sign_in_elem.click()

    username_elem = selenium.find_element_by_name("username")
    username_elem.send_keys("chifir")
    password_elem = selenium.find_element_by_name("password")
    password_elem.send_keys("chifir")
    submit_elem = selenium.find_element_by_id("SubmitLoginButton")
    submit_elem.click()
    error_elem = selenium.find_element_by_name("MessageParagraph")

    assert error_elem.text == "Incorrect username or password"
示例#8
0
    def get_options_internal(self, driver: WebDriver, timeout: int):
        select_gs = driver.find_element_by_name("sg")  # Grid Sizes
        gs_options = {
            option.get_attribute("value"): option.text
            for option in select_gs.find_elements_by_tag_name("option")
        }

        select_d = driver.find_element_by_name("sd")  # Difficulty
        d_options = {
            option.get_attribute("value"): option.text
            for option in select_d.find_elements_by_tag_name("option")
        }

        return [("Grid Size", gs_options), ("Difficulty", d_options)]
示例#9
0
def login(
    driver: WebDriver,
    username: str,
    password: SecretStr,
    timeout: int = 5
) -> bool:
    if is_login(driver):
        return True
    else:
        WebDriverWait(driver, timeout)
        driver.find_element_by_name('login_id').send_keys(username)
        driver.find_element_by_name('login_pass').send_keys(password)
        driver.find_element_by_class_name('submit_b') \
              .find_element_by_tag_name('input').click()
        return is_login(driver)
示例#10
0
def login_driver(driver:WebDriver):
    driver.get(ROUTER_IP)
    sleep(1)
    usernameEle=driver.find_element_by_id(LOGIN_USERNAME_ID)
    usernameEle.send_keys(USERNAME)
    pwdEle=driver.find_element_by_name(LOGIN_PWD_NAME)
    pwdEle.send_keys(PASSWORD)
    driver.execute_script("login();")
 def test_chrome(self, selenium: WebDriver):
     selenium.get("https://google.com")
     queryInput = selenium.find_element_by_name("q")
     queryInput.send_keys("hello world wiki")
     queryInput.submit()
     resultStats = selenium.find_element_by_id("resultStats")
     if "About" not in resultStats.text:
         assert False
 def testSendKeysNative(self):
   driver = WebDriver(self._launcher.GetURL(), self._capabilities)
   driver.get(self._launcher.GetURL() + '/test_page.html')
   # Find the text input.
   q = driver.find_element_by_name("key_input_test")
   # Send some keys.
   q.send_keys("tokyo")
   #TODO(timothe): change to .text when beta 4 wrappers are out.
   self.assertEqual(q.value, "tokyo")
 def test_chrome2(self, selenium: WebDriver):
     selenium.get("https://google.com")
     queryInput = selenium.find_element_by_name("q")
     queryInput.send_keys("hello world wiki")
     queryInput.submit()
     firstResult = selenium.find_element_by_xpath(
         "//*[@id=\"rso\"]/div/div/div[1]/div/div/h3/a")
     firstResult.click()
     if "Wikipedia" not in selenium.title:
         assert False
示例#14
0
    def get_puzzle(self, driver: WebDriver, timeout: int):
        self.get_home(driver, timeout)

        WebDriverWait(driver, timeout).until(
            EC.presence_of_element_located((By.TAG_NAME, "body")))
        # Set window size for screenshots
        driver.set_window_size(self.scroll_extent(driver, "Width"),
                               self.scroll_extent(driver, "Height"))

        if self.has_options:
            self.select_options(driver, timeout)

            # Create Puzzle
            driver.find_element_by_name("CreatePuzzle").click()

        WebDriverWait(driver, timeout).until(
            EC.presence_of_element_located((By.NAME, "submit"))).click()

        return self.get_populated_puzzle(driver, timeout)
 def DISABLED_testSendKeysNativeProcessedByIME(self):
   driver = WebDriver(self._launcher.GetURL(), self.capabilities)
   driver.get(self._launcher.GetURL() + '/test_page.html')
   q = driver.find_element_by_name("key_input_test")
   # Send key combination to turn IME on.
   q.send_keys(Keys.F7)
   q.send_keys("toukyou")
   # Now turning it off.
   q.send_keys(Keys.F7)
   self.assertEqual(q.value, "\xe6\x9d\xb1\xe4\xba\xac")
示例#16
0
def select_studio(
    driver: WebDriver,
    studio: str
) -> None:
    if not is_login(driver):
        raise NotLoginError()

    driver.get(RESERVE_URL)
    selector = Select(driver.find_element_by_name('tenpo'))
    for option in selector.options:
        name = option.text
        if '(' not in name or ')' not in name:
            continue
        name = name.replace(')', '').split('(')[1]
        name = name.replace(' ', '').replace(' ', '')
        if name == studio:
            selector.select_by_value(option.get_attribute('value'))
            return
    raise StudioSelectionError()
示例#17
0
    def select_options(self, driver: WebDriver, timeout: int):
        select_gs = Select(driver.find_element_by_name("sg"))
        select_gs.select_by_value(self.grid_size_option)

        select_d = Select(driver.find_element_by_name("sd"))
        select_d.select_by_value(self.difficulty_option)
示例#18
0
def signin(driver: WebDriver,
           email: str,
           password: str,
           short_timeout_secs: int = 10,
           long_timeout_secs: int = 20):
    logging.info("Loading Amazon home page ...")
    driver.get("https://www.amazon.com/")
    el = WebDriverWait(driver, long_timeout_secs).until(
        EC.presence_of_element_located(
            (By.CSS_SELECTOR, "#nav-link-accountList, #captchacharacters")))
    if el.get_attribute('id') == "captchacharacters":
        while True:
            img = driver.find_element_by_css_selector(
                "div.a-text-center > img")
            captcha_url = img.get_attribute("src")
            captcha = input("Please enter the captcha code in '%s': " %
                            captcha_url)
            if captcha:
                el.click()
                el.send_keys(captcha)
                driver.find_element_by_css_selector(
                    "button[type=submit]").click()
                try:
                    WebDriverWait(driver, short_timeout_secs).until(
                        EC.staleness_of(el))
                    break
                except TimeoutException:
                    pass
                # Refresh to load a diferent captcha code.
                driver.refresh()
                el = WebDriverWait(driver, long_timeout_secs).until(
                    EC.element_to_be_clickable((By.ID, "captchacharacters")))

        logging.info("Wait for signin page...")
        el = WebDriverWait(driver, long_timeout_secs).until(
            EC.presence_of_element_located(
                (By.CSS_SELECTOR, "#nav-link-accountList")))

    logging.info("Loading signin page...")
    href = el.get_attribute("href")
    if not href.startswith("https://www.amazon.com/ap/signin?"):
        logging.info("Already signed in.")
        return
    el.click()
    WebDriverWait(driver, long_timeout_secs).until(EC.staleness_of(el))

    if email and password:
        logging.info("Entering email ...")
        el = WebDriverWait(driver, short_timeout_secs).until(
            EC.element_to_be_clickable((By.ID, "ap_email")))
        el.click()
        el.send_keys(email)
        WebDriverWait(driver, short_timeout_secs).until(
            EC.element_to_be_clickable((By.ID, "continue"))).click()
        WebDriverWait(driver, long_timeout_secs).until(EC.staleness_of(el))

        logging.info("Entering password ...")
        el = WebDriverWait(driver, short_timeout_secs).until(
            EC.element_to_be_clickable((By.ID, "ap_password")))
        el.click()
        el.send_keys(password)
        driver.find_element_by_name("rememberMe").click()
        WebDriverWait(driver, short_timeout_secs).until(
            EC.element_to_be_clickable((By.ID, "signInSubmit"))).click()
        WebDriverWait(driver, long_timeout_secs).until(EC.staleness_of(el))
    else:
        logging.info("Please sign in Amazon...")
        while True:
            time.sleep(3)
            try:
                el = driver.find_element_by_id("nav-link-accountList")
                href = el.get_attribute("href")
                if not href.starts_with("https://www.amazon.com/ap/signin?"):
                    break
            except NoSuchElementException:
                pass

    url = driver.current_url
    logging.info("Loaded '%s'." % url)