diff --git a/loc.py b/loc.py index 77e67ac..3efc1a2 100644 --- a/loc.py +++ b/loc.py @@ -94,3 +94,16 @@ class Locators: reject = (By.CSS_SELECTOR, 'button.ant-btn.css-1f72xif.ant-btn-default') # nickname friend_name = (By.CSS_SELECTOR, 'p.text-sm') + session_friendList_loc = (By.CSS_SELECTOR, "div[data-test-id='virtuoso-scroller'] " + ".ant-avatar-square:not(.ant-avatar-image) > span.ant-avatar-string") + Specify_friend_loc = (By.CSS_SELECTOR, " div[data-test-id='virtuoso-scroller'] .div.flex-1.truncate.font-medium") + + # del_vator_loc=(By.CSS_SELECTOR,'div.flex.h-full.items-center.leading-none span.ant-avatar.ant-avatar-square') + setting_loc = (By.CSS_SELECTOR, 'img.ml-5.cursor-pointer:nth-of-type(3)') + + del_loc = (By.CSS_SELECTOR,'button.ant-btn.ant-btn-primary.ant-btn-dangerous') + + del_confirm_loc = (By.XPATH,"//button[contains(., '确定')]") + + # del_not_loc = (By.XPATH,"//button[contains(., '取消')]") + two_avtor_loc = (By.XPATH,'//*[@id="chat-container"]/div[2]/div[3]/div/div[2]/div[1]') diff --git a/pages/add_friend_page.py b/pages/add_friend_page.py index bb774cd..9a0d952 100644 --- a/pages/add_friend_page.py +++ b/pages/add_friend_page.py @@ -29,7 +29,7 @@ def go_to(self): def add_friend(self,friend_phone,greeting_message='Hello'): self.wait_masks_invisible() - time.sleep(2) + time.sleep(4) self.javascript_click(Locators.add_menu_loc) self.base_click(Locators.add_friend_loc) @@ -62,7 +62,7 @@ def add_friend(self,friend_phone,greeting_message='Hello'): EC.visibility_of_element_located(msg_loc) ) message_text = message_element.text - print("Unknown result, the pop-up text is:", message_text) + print("Unknown result, the pop-up text is::", message_text) except TimeoutException: print("The expected feedback message was not found。") @@ -73,7 +73,7 @@ def agree_friend(self,addfriend_nickname): self.base_click(Locators.contacts) self.base_click(Locators.newFriend_list) friend_names = self.base_get_text(Locators.friend_name) - # print('检测申请列表的好友有:', friend_names) + print('friend list:', friend_names) if addfriend_nickname in friend_names: print(f"Received this{addfriend_nickname}Friend's Request。") else: diff --git a/pages/del_friend.py b/pages/del_friend.py new file mode 100644 index 0000000..5febd16 --- /dev/null +++ b/pages/del_friend.py @@ -0,0 +1,44 @@ +import time + +from selenium.common import NoSuchElementException + +from base.base_page import BasePage +from config import HOST +from loc import Locators +from utils.read_accounts import read_registered_accounts + +class DeleteFriedn(BasePage): + def __init__(self,driver): + super().__init__(driver) + self.url = HOST + def go_to(self): + self.driver.get(self.url) + + def del_friend(self): + self.wait_masks_invisible() + has_accounts = read_registered_accounts(1) + _, _, friend_nickname = has_accounts + # print('好友:', friend_nickname) + friend_names = self.base_get_text(Locators.session_friendList_loc) + print('name', friend_names) + for friend in friend_names: + # name_elem = friend.find_elements(Locators.Specify_friend_loc) + # if name_elem.text == friend_nickname: + # print('name', name_elem.text) + if friend_nickname in friend: + self.base_click(Locators.session_friendList_loc) + else: + print('no friend', friend_nickname) + self.base_click(Locators.setting_loc) + self.base_find(Locators.del_loc) + self.base_click(Locators.del_loc) + self.base_find(Locators.del_confirm_loc) + self.base_click(Locators.del_confirm_loc) + # self.base_click(Locators.two_avtor_loc) + + + + + + + diff --git a/script/test_add_friend.py b/script/test_add_friend.py index 97d3ad3..1925edd 100644 --- a/script/test_add_friend.py +++ b/script/test_add_friend.py @@ -42,13 +42,13 @@ def test_add_friends(driver, login): add_friend_page.go_to() registered_accounts = read_registered_accounts(1) - print("Register an account:", registered_accounts) + print("注册 账号:", registered_accounts) if registered_accounts: friend_phone, friend_pwd, _ = registered_accounts add_friend_page.add_friend(friend_phone, "你好,加个好友把!") else: - assert False, "There is no available registered account to test adding friends" + assert False, "没有可用的注册账号来进行添加好友的测试" # # driver.execute_script("window.open('');") # driver.switch_to.window(driver.window_handles[1]) @@ -72,8 +72,8 @@ def test_agree_friends(driver, login): ) text = element.text - print('Verify successful consent:', text) - assert text == "已同意", "Assertion failed: The text content is not '已同意'" + print('验证是否成功同意:', text) + assert text == "已同意", "断言失败:文本内容不是 '已同意'" else: - assert False, "There is no available registered account to test the friend request approval" + assert False, "没有可用的注册账号来进行同意好友申请的测试" diff --git a/script/test_del_friend.py b/script/test_del_friend.py new file mode 100644 index 0000000..936129b --- /dev/null +++ b/script/test_del_friend.py @@ -0,0 +1,42 @@ +import time +from unittest import result + +import pytest +from selenium.common import NoSuchElementException, TimeoutException +from selenium.webdriver.support.wait import WebDriverWait + +from loc import Locators +from pages.del_friend import DeleteFriedn +from utils.headless_browser import create_driver +from utils.read_accounts import read_registered_accounts +from utils.token import login + +from selenium.webdriver.support import expected_conditions as EC +@pytest.fixture +def browser_driver(): + driver = create_driver() + time.sleep(3) + yield driver + driver.quit() + + +@pytest.fixture +def driver(browser_driver): + return browser_driver + +@pytest.mark.run(order=8) +def test_del_friend(driver, login): + has_accounts = read_registered_accounts(0) + phone_number, pwd, _ = has_accounts + login(phone_number, pwd) + del_friend_page = DeleteFriedn(driver) + del_friend_page.go_to() + del_friend_page.del_friend() + + try: + WebDriverWait(driver, 10).until( + EC.invisibility_of_element_located(Locators.del_loc) + ) + print("Delete button disappeared, friend deletion successful.") + except TimeoutException: + pytest.fail("Friend deletion failed, delete button still visible after timeout.")