Пример #1
0
def test_write_space_comment():
    """
  WC3: Exceptional flow of user comment procedure
  :return: assert Passed if having warning text when user comment space
  """
    driver = CookieLoader.load_cookie()
    driver.get(TINHTE_COMMENT_POST)

    try:
        WebDriverWait(driver, 2).until(
            EC.presence_of_element_located(
                (By.XPATH, COMMENT_BOX_XPATH))).send_keys("      ")

        WebDriverWait(driver, DELAY) \
          .until(EC.presence_of_element_located((By.XPATH, POST_BUTTON_XPATH))).click()

        error_xpath = '//p[@class="jsx-3593820457 error"]'
        error_text = WebDriverWait(driver, DELAY) \
          .until(EC.presence_of_element_located((By.XPATH, error_xpath))).text

        define_error_text = "Vui lòng không để trống bình luận"
        assert define_error_text == error_text

    except TimeoutException:
        raise TimeoutException("Time out when in test_write_space_comment")
Пример #2
0
def test_create_post_with_background():
  """
  CP3: Alternative flow of post with selective background
  """
  post_content = "iphone 12 mau tim"
  driver = CookieLoader.load_cookie()
  driver.get(TINHTE)
  background_list_xpath = "//button[@class='jsx-1783754700 thread-background-switch']"
  theme_chosen_xpath = "//div[@class='jsx-1783754700 thread-background-container visible']/img[1]"

  try:
    WebDriverWait(driver, 2).until(EC.presence_of_element_located((By.XPATH, BUTTON_CREATE_POST))).click()

    WebDriverWait(driver, DELAY) \
      .until(EC.presence_of_element_located((By.XPATH, POST_BOX_XPATH))) \
      .send_keys(post_content)

    driver.find_element_by_xpath(background_list_xpath).click()

    WebDriverWait(driver, DELAY) \
      .until(EC.element_to_be_clickable((By.XPATH, theme_chosen_xpath))).click()

    sleep(2)
    driver.find_element_by_xpath(POST_BUTTON_XPATH).click()

    commented_text = WebDriverWait(driver, DELAY) \
      .until(EC.presence_of_element_located((By.XPATH, POSTED_BOX_XPATH))).text

    assert post_content == commented_text
  except TimeoutException:
    raise TimeoutException("Time out when in test_create_post_with_background")
Пример #3
0
def test_write_comment_sicker():
    """
  WC2: Alternative flow of comment with sticker
  :return: assert Passed if user commented successfully
  """
    driver = CookieLoader.load_cookie()
    driver.get(TINHTE_COMMENT_POST)

    try:
        WebDriverWait(driver, 2).until(
            EC.presence_of_element_located(
                (By.XPATH, COMMENT_BOX_XPATH))).send_keys(COMMENT)

        sicker_path = '//button[@title="Stickers"]'
        imoji_xpath = '//div[@class="jsx-3529665607 sticker-list"]//button[2]'

        driver.find_element_by_xpath(sicker_path).click()

        WebDriverWait(driver, DELAY) \
          .until(EC.presence_of_element_located((By.XPATH, imoji_xpath))).click()

        WebDriverWait(driver, DELAY) \
          .until(EC.presence_of_element_located((By.XPATH, POST_BUTTON_XPATH))).click()

        commented_text = WebDriverWait(driver, DELAY) \
          .until(EC.presence_of_element_located((By.XPATH, COMMENT_POSTED_BOX))).text

        assert COMMENT == commented_text
    except TimeoutException:
        raise TimeoutException("Time out when in test_write_comment_sicker")
Пример #4
0
def test_write_comment_and_edit():
    """
  WC4: Alternative flow when editing a comment
  :return: assert Passed if user commented successfully
  """
    driver = CookieLoader.load_cookie()
    driver.get(TINHTE_COMMENT_POST)

    try:
        WebDriverWait(driver, 2).until(
            EC.presence_of_element_located(
                (By.XPATH, COMMENT_BOX_XPATH))).send_keys(COMMENT)

        WebDriverWait(driver, DELAY) \
          .until(EC.presence_of_element_located((By.XPATH, POST_BUTTON_XPATH))).click()

        commented_text = WebDriverWait(driver, DELAY) \
          .until(EC.presence_of_element_located((By.XPATH, COMMENT_POSTED_BOX))).text

        assert COMMENT == commented_text

        edit_xpath = '//button[@class="jsx-2274533257 thread-action"]'
        driver.find_element_by_xpath(edit_xpath).click()

        edit_text_path = '//div[@id="post-reply-"]//textarea[@class="post-reply-input"]'
        WebDriverWait(driver, 2)\
          .until(EC.presence_of_element_located((By.XPATH, edit_text_path)))\
          .send_keys("edit")

        WebDriverWait(driver, DELAY) \
          .until(EC.presence_of_element_located((By.XPATH, POST_BUTTON_XPATH))).click()

        edit_commented_text = WebDriverWait(driver, DELAY) \
          .until(EC.presence_of_element_located((By.XPATH, COMMENT_POSTED_BOX))).text

        assert "edit" in edit_commented_text
    except TimeoutException:
        raise TimeoutException("Time out when in test_write_comment_and_edit")
Пример #5
0
def test_create_post_less_or_equal_ten_words():
  """
  CP2: Exception flow of a post has less than or equal 10 words required
  """
  post_content = "ip 12 timm" # 10 characters
  warning_message_xpath = '//span[@class="jsx-1783754700 text"]'
  warning_mess = "Bạn phải gõ dài hơn 10 kí tự mới được nhé :D"
  driver = CookieLoader.load_cookie()
  driver.get(TINHTE)

  try:
    WebDriverWait(driver, 2).until(EC.presence_of_element_located((By.XPATH, BUTTON_CREATE_POST))).click()

    WebDriverWait(driver, DELAY) \
      .until(EC.presence_of_element_located((By.XPATH, POST_BOX_XPATH))) \
      .send_keys(post_content)

    warning_text = WebDriverWait(driver, DELAY) \
      .until(EC.presence_of_element_located((By.XPATH, warning_message_xpath))).text

    assert warning_mess == warning_text
  except TimeoutException:
    raise TimeoutException("Time out when in test_create_post_less_or_equal_ten_words")
Пример #6
0
def test_create_post_and_cancel():
  """
  CP1: Basic flow of writing post
  """
  post_content = "iphone 12 mau tim"
  driver = CookieLoader.load_cookie()
  driver.get(TINHTE)
  cancel_button = '//div[@role="dialog"]//div[@class="jsx-1783754700 top-area"]//button'

  try:
    WebDriverWait(driver, 2).until(EC.presence_of_element_located((By.XPATH, BUTTON_CREATE_POST))).click()

    WebDriverWait(driver, DELAY) \
      .until(EC.presence_of_element_located((By.XPATH, POST_BOX_XPATH))) \
      .send_keys(post_content)

    driver.find_element_by_xpath(cancel_button).click()

    boxes = driver.find_elements_by_xpath(POST_BOX_XPATH)

    assert len(boxes) == 0
  except TimeoutException:
    raise TimeoutException("Time out when in test_create_post_basic_flow")
Пример #7
0
def test_write_comment_basic_flow():
    """
  WC1: Basic flow of user comment procedure
  :return: assert Passed if user commented successfully
  """
    driver = CookieLoader.load_cookie()
    driver.get(TINHTE_COMMENT_POST)

    try:
        WebDriverWait(driver, 2).until(
            EC.presence_of_element_located(
                (By.XPATH, COMMENT_BOX_XPATH))).send_keys(COMMENT)

        WebDriverWait(driver, DELAY)\
          .until(EC.presence_of_element_located((By.XPATH, POST_BUTTON_XPATH))).click()

        commented_text = WebDriverWait(driver, DELAY) \
          .until(EC.presence_of_element_located((By.XPATH, COMMENT_POSTED_BOX))).text

        assert COMMENT == commented_text
    except TimeoutException:
        raise TimeoutException(
            "Time out when in test_write_comment_basic_flow")
Пример #8
0
def test_create_post_basic_flow():
  """
  CP1: Basic flow of writing post
  """
  post_content = "iphone 12 mau tim"
  driver = CookieLoader.load_cookie()
  driver.get(TINHTE)

  try:
    WebDriverWait(driver, 2).until(EC.presence_of_element_located((By.XPATH, BUTTON_CREATE_POST))).click()

    WebDriverWait(driver, DELAY) \
      .until(EC.presence_of_element_located((By.XPATH, POST_BOX_XPATH)))\
      .send_keys(post_content)

    sleep(2)
    driver.find_element_by_xpath(POST_BUTTON_XPATH).click()

    commented_text = WebDriverWait(driver, DELAY) \
      .until(EC.presence_of_element_located((By.XPATH, POSTED_BOX_XPATH))).text

    assert post_content == commented_text
  except TimeoutException:
    raise TimeoutException("Time out when in test_create_post_basic_flow")
Пример #9
0
def test_write_comment_and_delete():
    """
  WC5: Exception flow when delete a comment
  :return: assert Passed if user commented deleted successfully
  """
    driver = CookieLoader.load_cookie()
    driver.get(TINHTE_COMMENT_POST)

    try:
        WebDriverWait(driver, 2).until(
            EC.presence_of_element_located(
                (By.XPATH, COMMENT_BOX_XPATH))).send_keys(COMMENT)

        WebDriverWait(driver, DELAY) \
          .until(EC.presence_of_element_located((By.XPATH, POST_BUTTON_XPATH))).click()

        commented_text = WebDriverWait(driver, DELAY) \
          .until(EC.presence_of_element_located((By.XPATH, COMMENT_POSTED_BOX))).text

        assert COMMENT == commented_text

        delete_xpath = '//div[@class="jsx-2274533257 thread-comment__action--right"]//button[2]'
        comfirm_delete_path = "//button[@class='jsx-3932553558 button active']"

        WebDriverWait(driver, DELAY) \
          .until(EC.presence_of_element_located((By.XPATH, delete_xpath))).click()

        driver.find_element_by_xpath(comfirm_delete_path).click()

        commented_text = WebDriverWait(driver, DELAY) \
          .until(EC.presence_of_element_located((By.XPATH, COMMENT_POSTED_BOX))).text

        assert COMMENT != commented_text
    except TimeoutException:
        raise TimeoutException(
            "Time out when in test_write_comment_and_delete")
Пример #10
0
from Utils.CookieLoader import CookieLoader

if __name__ == '__main__':
    CookieLoader.get_cookie()