def test_13_rate_after_operator_responds(self): time.sleep(5) # "three-dots" menu button driver.find_element_by_css_selector( "button.webim-action:nth-child(1)").click() driver.find_element_by_class_name("webim-chat-action-rate").click() rate_elements = driver.find_elements_by_class_name( "webim-icon-operator-rate") random_rating = choice(rate_elements) random_rating.click() self.rate_btn = driver.find_element_by_css_selector( ".webim-js-button-style") self.assertTrue( self.rate_btn.is_displayed(), "the rating should be put after the answer of the operator") self.rate_btn.click() success_icon = driver.find_element_by_css_selector("div.webim-icon") self.assertTrue(success_icon, "a green check mark does not appears after rating.") try: rate_error = driver.find_element_by_css_selector( ".webim-rate-error") except NoSuchElementException: pass # normal, because we are checking that no one rare error in chat window else: self.assertNotIn( "Нет оператора для выставления оценки", rate_error.text, "should not been message that operator is not selected")
def setUp(self): self.file_dir = "your/path/to/file" self.files_name = { "valid": [ "cat.jpg", "cat.png", "cat.jpeg", "cat.gif", "file.doc", "file.rtf", "file.txt", "file.pdf", "file.docx", "file.wepb" ], "not_valid": [ "cat.jpg.zip", "cat.mp3", "cat.NaN", "file.log", ] } driver.find_element_by_css_selector( "button.webim-action:nth-child(1)").click() # "three-dots" button # FIXME: can't load file to the server self.load_btn = driver.find_element_by_xpath( "/html/body/div[2]/div[2]/div[2]/div[2]/div[1]/div[1]/div[3]/div[1]/div[2]/div[2]/ul/li[2]/label/span[2]")
def test_14_close_chat(self): btn_close = driver.find_element_by_css_selector("div.webim-action-close") self.assertTrue(btn_close.is_displayed(), "chat close button is not displaying") btn_close.click() self.assertFalse(btn_close.is_displayed(), "chat close button is displaying, but chat window has been closed")
def setUp(self): self.text_area = driver.find_element_by_css_selector(".webim-message-area") self.assertTrue(self.text_area.is_displayed(), "field for message input is not displaying") self.msg_templates_positive = { "i love chatting myself;", "Eat @ sleep @ testing", ",.%#+=!@^*()", "∆", "&", # BUG: ampersand (&) --> '&' 20 * "many-" + "elephants-live-in-my-head, doctor!", 50 * "WЁ are зе чемпiонs? Май френд. ", "https://goo.gl/3smbEA", } self.msg_templates_negative = [ " ", 15 * "\n", 1000 * " ", "\t\t\n \n\t " ] self.operator_msg = [ "Добро пожаловать в демо приложение для демонстрации чата.", "Пожалуйста, подождите немного, к Вам присоединится оператор...", "К сожалению, оператор сейчас не может ответить." ]
def test_16_minimize_chat(self): btn_minimize = driver.find_element_by_css_selector(".webim-action-minimize") self.assertTrue(btn_minimize.is_displayed(), "chat minimize button is not displaying") btn_minimize.click() self.assertFalse(btn_minimize.is_displayed(), "chat minimize button is displaying, but chat window has been minimized") driver.close()
def test_10_send_file_valid(self): for file_name in self.files_name["valid"]: self.load_btn.send_keys(self.file_dir + file_name) time.sleep(1) last_msg = driver.find_element_by_css_selector( "li.webim-message:nth-child(6) > div:nth-child(3) > span:nth-child(1)") self.assertIn("Отправил", last_msg.text, "file \'" + file_name + "\' with valid format was not uploaded")
def test_09_rate_operator_before_reply(self): time.sleep(2) # "three-dots" menu button driver.find_element_by_css_selector( "button.webim-action:nth-child(1)").click() driver.find_element_by_class_name("webim-chat-action-rate").click() rate_elements = driver.find_elements_by_class_name("webim-icon-operator-rate") random_rating = choice(rate_elements) random_rating.click() self.rate_btn = driver.find_element_by_css_selector(".webim-js-button-style") rate_error = driver.find_element_by_css_selector(".webim-rate-error") self.assertIn("Нет оператора для выставления оценки", rate_error.text, "no message that operator is not selected") close_rate_btn = driver.find_element_by_xpath( "/html/body/div[2]/div[2]/div[2]/div[2]/div[1]/div[2]/div[2]/div/div[1]/div/span") close_rate_btn.click()
def test_08_send_emoji(self): text_area = self.text_area btn_emoji = driver.find_element_by_css_selector("button.webim-action:nth-child(3)") btn_emoji.click() time.sleep(3) # for loading emoji panel. increase if low internet connection emoji_list = driver.find_elements_by_class_name("webim-emoji") for _ in range(5): emoji = choice(emoji_list) emoji.click() text_area.send_keys(Keys.ENTER) self.assertEqual("", text_area.text, "after sending emoji text field is not empty") text_area.clear() btn_emoji.click() # close emoji panel
def test_15_reopen_chat(self): driver.find_element_by_css_selector( ".webim_button > img:nth-child(1)").click() msg_area = driver.find_element_by_css_selector(".webim-dialogues") self.assertTrue(msg_area.is_displayed(), "chat is not displaying")
def test_12_send_file_large(self): self.load_btn.send_keys(self.file_dir + "book.pdf") error = driver.find_element_by_css_selector(".webim-file-upload-error") self.assertIn("Файл слишком большой для передачи.", error.text, "no error after loading file with large size")
def test_11_send_file_not_valid(self): for file_name in self.files_name["not_valid"]: self.load_btn.send_keys(self.file_dir + file_name) error = driver.find_element_by_css_selector(".webim-file-upload-error") self.assertIn("Разрешены следующие типы: png, jpg, jpeg, doc, rtf, gif, txt, pdf, docx, webp.", error.text, "no error after loading \'" + file_name + "\' file with invalid extension")