web自动化测试

base_page.py
from selenium import webdriver
from selenium.webdriver.remote.webelement import WebElement

class BasePage:

def __init__(self, driver=None):
    if driver is None:
        self.driver = webdriver.Chrome()
        self.driver.implicitly_wait(10)
    else:
        self.driver = driver

def find(self, loc) -> WebElement:
    return self.driver.find_element(*loc)

index_page.py
from base_page import BasePage
from search_page import SearchPage
from selenium.webdriver.common.by import By

class IndexPage(BasePage):
base_url = “https://ceshiren.com/
search_btn = (By.CSS_SELECTOR, “.d-icon-search”)
search_input = (By.ID, “search-term”)
adv_search_btn = (By.CSS_SELECTOR, “.show-advanced-search”)

def open_index_page(self):
    self.driver.get(self.base_url)

def click_search_btn(self):
    self.find(self.search_btn).click()

def input_search_value(self, search_value):
    self.find(self.search_input).send_keys(search_value)

def click_adv_search_btn(self):
    self.find(self.adv_search_btn).click()
    return SearchPage(self.driver)

search_page.py
from base_page import BasePage
from topic_page import TopicPage
from selenium.webdriver.common.by import By

class SearchPage(BasePage):
search_result_title = (By.CSS_SELECTOR, “.search-link”)
#搜索结果
def get_search_result(self):
return self.find(self.search_result_title).text
#点击搜索
def click_search_result(self):
self.find(self.search_result_title).click()
return TopicPage(self.driver)

topic_page.py
from base_page import BasePage
from selenium.webdriver.common.by import By

class TopicPage(BasePage):
topic_title = (By.CSS_SELECTOR, “.fancy-title”)
topic_body = (By.CSS_SELECTOR, “.inline-footnotes”)

def get_title_text(self):
    return self.find(self.topic_title).text

def get_body_text(self):
    return self.find(self.topic_body).text

test_ceshiren.py
from index_page import IndexPage

class TestCeshiren:

def setup(self):
    self.index_page = IndexPage()
    self.index_page.open_index_page()

def test_search(self):
    # 搜索内容
    search_value = "Selenium"
    # 点击查询按钮
    self.index_page.click_search_btn()
    # 输入查询值
    self.index_page.input_search_value(search_value)
    # 点击高级查询按钮
    search_page = self.index_page.click_adv_search_btn()
    # 进行断言:查询结果是否包含关键字
    res = search_page.get_search_result()
    assert search_value in res
    # 点击标签进入帖子
    topic_page = search_page.click_search_result()
    # 进行断言:判断查询结果是否包含关键字
    assert search_value in topic_page.get_title_text()
    assert search_value in topic_page.get_body_text()

202041404109 胡智




4

202041412220 区世钧
主程序:


各功能页面:
初始化:
M60JA}PQ4(U)X6O$5ONO
在搜索界面:
(@`A3BV2_6TB3P2(KZ13TC
从普通搜索跳转到高级搜索,再到详情页面
$@UR@ZA6((N}D{X7Y1KWZ6
在详情页面返回内容text并在主程序里asset比对
9E{N@V89FTLF74{O(AXPMW

202041404211 李范佑

base_page

from selenium.webdriver.remote.webelement import WebElement


class BasePage:
    """
    公共父类,封装页面的功能方法
    """

    def __init__(self, driver=None):
        if driver is None:
            self.driver = webdriver.Chrome()
            # 设置隐式等待时间
            self.driver.implicitly_wait(5)
        else:
            self.driver = driver

    def find(self, loc) -> WebElement:
        """
        元素查找
        """
        return self.driver.find_element(*loc)

index_page

from selenium.webdriver.common.by import By
from webtest.page_obj.pages.base_page import BasePage
from webtest.page_obj.pages.search_page import SearchPage


class Indexpage(BasePage):
    base_url = "https://ceshiren.com"
    search_btn = (By.CSS_SELECTOR, ".d-icon-search")
    search_input = (By.ID, "search-term")
    adv_search_btn = (By.CSS_SELECTOR, ".show-advanced-search")

    def open_index_page(self):
        self.driver.get(self.base_url)

    def click_search_btn(self):
        #点击查询按钮
        self.find(self.search_btn).click()

    def input_search_value(self,search_value):
        #输入查询值
        self.find(self.search_input).send_keys(search_value)

    def click_adv_search_btn(self):
        #点击高级查询按钮
        self.find(self.adv_search_btn).click()
        return SearchPage(self.driver)

search_page

from selenium.webdriver.common.by import By
from webtest.page_obj.pages.base_page import BasePage
from webtest.page_obj.pages.topic_page import TopicPage

class SearchPage(BasePage):
    search_result_title = (By.CSS_SELECTOR, ".search-link")
    def get_search_result(self):
        return self.find(self.search_result_title).text

    def click_search_result(self):
        #点击查询结果
        self.find(self.search_result_title).click()
        return TopicPage(self.driver)

test_ceshiren_po

import time

import pytest
from selenium import webdriver
from selenium.webdriver.common.by import By

from webtest.page_obj.pages.index_page import Indexpage


class TestCeshirenPo:
    def setup(self):
        # base_url = "http://ceshiren.com/"
        # 打开测试人首页
        # self.driver = webdriver.Chrome()
        # self.driver.get(base_url)
        self.index_page = Indexpage()
        self.index_page.open_index_page()
    def test_search(self):
        search_value = "Selenium"
        # 点击查询按钮
        self.index_page.click_search_btn()
        # 输入查询
        self.index_page.input_search_value(search_value)
        # 点击高级查询按钮
        search_page = self.index_page.click_adv_search_btn()
        # 判断查询结果是否包含关键字
        res = search_page.get_search_result()
        assert search_value in res
        time.sleep(2)
        #点击进入帖子
        topic_page =  search_page.click_search_result()

        #判断是否包含关键字
        assert search_value in topic_page.get_title_text()

        # todo: 判断帖子详情内容是否包含关键字
        assert search_value in topic_page.get_page_text()

        time.sleep(2)

topic_page

from selenium.webdriver.common.by import By
from webtest.page_obj.pages.base_page import BasePage

class TopicPage(BasePage):
    topic_title = (By.CSS_SELECTOR, ".fancy-title")
    page_title = (By.CSS_SELECTOR, ".inline-footnotes")

    def get_title_text(self):
        return self.find(self.topic_title).text

    def get_page_text(self):
        return self.find(self.page_title).text

姓名 :王冠毅 学号 :202041412222

test_ceshiren.py

# 测试前置动作
def setup(self):
    base_url = "https://ceshiren.com/"
    # 打开测试人首页
    self.driver = webdriver.Chrome()
    self.driver.get(base_url)
    # 设置隐式等待时间
    self.driver.implicitly_wait(10)

# 搜索功能测试
def test_search(self):
    search_btn = (By.CSS_SELECTOR,".d-icon-search")
    search_input = (By.ID,"search-term")
    adv_search_btn = (By.CSS_SELECTOR,".show-advanced-search")
    search_result_title = (By.CSS_SELECTOR,".search-link")
    search_value = "Selenium"
    # 点击查询按钮
    self.driver.find_element(*search_btn).click()
    # 输入查询值
    self.driver.find_element(*search_input).send_keys(search_value)
    # 点击高级查询按钮
    self.driver.find_element(*adv_search_btn).click()

    # 判断查询结果是否包含关键字
    res = self.driver.find_element(*search_result_title)
    assert search_value in res.text

base_page.py

class BasePage:
    def __init__(self,driver=None):

        if driver is None:


            self.driver = webdriver.Edge()



            self.driver.implicitly_wait(10)
        else:
            self.driver = driver

    def find(self,loc):
        return  self.driver.find_element(*loc)

index_page.py

from selenium.webdriver.common.by import By

from page_obj.pages.base_page import BasePage
from page_obj.pages.search_page import SearchPage
from page_obj.pages.topic_page import TopicPage


class IndexPage(BasePage):
    base_url = "https://ceshiren.com/"
    search_btn=(By.CSS_SELECTOR,".d-icon-search")
    search_input=(By.ID,"search-term")
    adv_search_btn=(By.CSS_SELECTOR,".show-advanced-search")
    search_btn_xiangqing=(By.CSS_SELECTOR,".search-link")

    def open_index_page(self):
        self.driver.get(self.base_url)

    def click_search_btn(self):
        self.find(self.search_btn).click()

    def input_search_value(self,search_value):

        self.find(self.search_input).send_keys(search_value)

    def click_adv_search_btn(self):
        #点击高级查询按钮
        self.find(self.adv_search_btn).click()
        return SearchPage(driver=self.driver)

    def click_search_xaingqing(self):
        self.find(self.search_btn_xiangqing).click()
        return TopicPage(driver=self.driver)

search_page.py

from selenium.webdriver.common.by import By

from page_obj.pages import topic_page
from page_obj.pages.base_page import BasePage
from page_obj.pages.topic_page import TopicPage


class SearchPage(BasePage):
    search_result_title = (By.CSS_SELECTOR,".search-link")

    def get_search_result(self):
        return self.find(self.search_result_title).text



    def click_search_result(self):
        self.find(self.search_result_title).click()
        return TopicPage(driver=self.driver)

topic_gage.py

from selenium.webdriver.common.by import By

from page_obj.pages.base_page import BasePage


class TopicPage(BasePage):
    topic_title=(By.CSS_SELECTOR,".fancy-title")
    xiangqing=(By.CSS_SELECTOR,".inline-footnotes")



    def get_title_text(self):
        return  self.find(self.topic_title).text


    def get_xiangqing_text(self):
        return self.find(self.xiangqing).text

202041404213 刘建升
test_ceshiren_po.py
from seleniumtest.index_page import IndexPage
from seleniumtest.search_page import SearchPage

class TestCesshiren:
def setup(self):
self.index_page=IndexPage()
self.index_page.open_index_page()

def test_search(self):
    search_value="Selenium"

    self.index_page.click_search_btn()

    self.index_page.input_search_value(search_value)

    search_page=self.index_page.click_adv_search_btn()

    res=search_page.get_search_result()

    assert search_value in res

    topic_page=search_page.click_search_result()

    assert search_value in topic_page.get_title_text()

base_page.py
from selenium import webdriver
from selenium.webdriver.remote.webelement import WebElement

class BasePage:
def init(self,driver=None):
if driver is None:
self.driver=webdriver.Chrome()
self.driver.implicitly_wait(10)
else:
self.driver=driver
def find(self,loc) → WebElement:

    # :param
    # :return

    return self.driver.find_element(*loc)

search_page.py
from selenium.webdriver.common.by import By

from seleniumtest.basepage import BasePage
from seleniumtest.topic_page import TopicPage

class SearchPage(BasePage):
search_result_title=(By.CSS_SELECTOR,“.search-link”)

def get_search_result(self):
    return self.find(self.search_result_title).text

def click_search_result(self):
    self.find(self.search_result_title).click()
    return TopicPage(self.driver)

index_page.py
from seleniumtest.basepage import BasePage
from selenium.webdriver.common.by import By

from seleniumtest.search_page import SearchPage

class IndexPage(BasePage):
base_url = “https://ceshiren.com/”
search_btn = (By.CSS_SELECTOR, “.d-icon-search”)
search_input = (By.ID, “search-term”)
adv_search_btn = (By.CSS_SELECTOR, “.show-advanced-search”)

def open_index_page(self):
    self.driver.get(self.base_url)
def click_search_btn(self):
    self.find(self.search_btn).click()
def input_search_value(self,search_value):
    self.find(self.search_input).send_keys(search_value)
def click_adv_search_btn(self):
    self.find(self.adv_search_btn).click()
    return SearchPage(self.driver)
![666|779x432](upload://4dnU7O44Qwi1IIa8YPmwaVn79sZ.png)
![777|800x723](upload://9Ob3eokDTwkXyhfFnLBMd9hhD9K.png)
![888|800x579](upload://10uqnMzfvdwl9Q64oQ7SwPEbdWM.png)
![999|800x718](upload://d2tFEuqyvYI2I5BxmXjH7mxuaKn.png)

image

202041404124王沛维

202044101107黄亦斌
屏幕截图 2023-10-15 234314


屏幕截图 2023-10-15 234401

屏幕截图 2023-10-15 234448

吴宏杰202041404218

202041404202 陈杰选
base_page.py

from selenium import webdriver
from selenium.webdriver.remote.webelement import WebElement


class BasePage:
    def __init__(self, driver=None):

        if driver is None:
            self.driver = webdriver.Chrome()
            self.driver.implicitly_wait(10)
        else:
            self.driver = driver

    def find(self, loc) -> WebElement:
        return self.driver.find_element(*loc)

index_page.py

from selenium.webdriver.common.by import By

from page_obj.pages.base_page import BasePage
from page_obj.pages.search_page import SearchPage


class IndexPage(BasePage):
    base_url = "https://ceshiren.com/"

    search_btn = (By.CSS_SELECTOR, ".d-icon-search")
    search_input = (By.ID, "search-term")
    adv_search_btn = (By.CSS_SELECTOR, ".show-advanced-search")

    def open_index_page(self):
        self.driver.get(self.base_url)

    def click_search_btn(self):
        self.find(self.search_btn).click()

    def input_search_value(self, search_value):
        self.find(self.search_input).send_keys(search_value)

    def click_adv_search_btn(self):
        self.find(self.adv_search_btn).click()
        return SearchPage(self.driver)

search_page.py

from selenium.webdriver.common.by import By

from page_obj.pages.base_page import BasePage
from page_obj.pages.topic_page import TopicPage


class SearchPage(BasePage):
    search_result_title = (By.CSS_SELECTOR, ".search-link")

    def get_search_result_text(self):
        return self.find(self.search_result_title).text

    def click_search_result(self):
        self.find(self.search_result_title).click()
        return TopicPage(self.driver)

topic_page.py

from selenium.webdriver.common.by import By

from page_obj.pages.base_page import BasePage


class TopicPage(BasePage):
    topic_title = (By.CSS_SELECTOR, ".fancy-title")
    topic_content = (By.CSS_SELECTOR, ".cooked.inline-footnotes")

    def get_title_text(self):
        return self.find(self.topic_title).text

    def get_content_text(self):
        return self.find(self.topic_content).text

text_ceshiren_po.py

import pytest
from selenium import webdriver
from selenium.webdriver.common.by import By

from page_obj.pages.index_page import IndexPage


class TestCeshiren:
    # 测试前置动作
    def setup(self):
        self.index_page = IndexPage()
        self.index_page.open_index_page()

    # 搜索功能测试
    def test_search(self):
        search_value = "Selenium"
        # 点击查询按钮
        self.index_page.click_search_btn()
        # 输入查询值
        self.index_page.input_search_value(search_value)
        # 点击高级查询按钮
        search_page = self.index_page.click_adv_search_btn()
        # 判断查询结果是否包含关键字
        res = search_page.get_search_result_text()
        assert search_value in res
        # 点击帖子进入详情页面
        topic_page = search_page.click_search_result()
        # 判断帖子详情页面title是否包含关键字
        assert search_value in topic_page.get_title_text()
        # 判断帖子详情页面内容是否包含关键字
        assert search_value in topic_page.get_content_text()

202041404217万晋江
base_page.py:

from selenium import webdriver


class BasePage:
    def __init__(self, driver = None):
        if driver is None:
            #打开浏览器
            self.driver = webdriver.Chrome()
            #隐式等待
            self.driver.implicitly_wait(10)
        else:
            self.driver = driver

    def find(self, element):
        #找元素
        return self.driver.find_element(*element)

index_page.py:

from selenium.webdriver.common.by import By

from page_object.pages.base_page import BasePage
from page_object.pages.search_page import SearchPage


class IndexPage(BasePage):
    base_url = "https://ceshiren.com/"
    search_btn = (By.CSS_SELECTOR, ".d-icon-search")
    search_input = (By.ID, "search-term")
    adv_search_btn = (By.CSS_SELECTOR, ".show-advanced-search")

    def open_url(self):
        #打开首页
        self.driver.get(self.base_url)

    def click_search_btn(self):
        #点击搜索按钮
        self.find(self.search_btn).click()

    def send_keys(self, search_value):
        #往查询框输入待查内容
        self.find(self.search_input).send_keys(search_value)

    def click_adv_btn(self):
        #点击高级查询按钮
        self.find(self.adv_search_btn).click()
        return SearchPage(self.driver)

search_page.py:

from selenium.webdriver.common.by import By

from page_object.pages.base_page import BasePage
from page_object.pages.topic_page import TopicPage


class SearchPage(BasePage):
    search_result_title = (By.CSS_SELECTOR, ".search-link")

    def get_search_result_text(self):
        #返回查询结果
        return self.find(self.search_result_title).text

    def click_search_result(self):
        #点击查询结果
        self.find(self.search_result_title).click()
        return TopicPage(self.driver)

topic_page.py:

from selenium.webdriver.common.by import By

from page_object.pages.base_page import BasePage


class TopicPage(BasePage):
    topic_title = (By.CSS_SELECTOR, ".fancy-title")
    topic_content = (By.CSS_SELECTOR, ".cooked.inline-footnotes")

    def get_title_text(self):
        #获取帖子标题
        return self.find(self.topic_title).text

    def get_content_text(self):
        #获取帖子内容
        return self.find(self.topic_content).text

test_ceshiren.py

import pytest
from selenium import webdriver
from selenium.webdriver.common.by import By

from page_object.pages.index_page import IndexPage


class TestCeshiren:
    #测试前置条件
    def setup(self):
        self.index_page = IndexPage()
        self.index_page.open_url()

    #搜索功能测试
    # @pytest.mark.parametrize("search_value", ["Selenium", "测试"])
    def test_search(self):
        search_value = "Selenium"

        #点击查询按钮
        self.index_page.click_search_btn()
        #输入查询值
        self.index_page.send_keys(search_value)
        #点击高级查询按钮
        search_page = self.index_page.click_adv_btn()

        #判断查询页面结果是否包含关键字
        res = search_page.get_search_result_text()
        assert search_value in res

        #点击进入帖子详情页面
        topic_page = search_page.click_search_result()
        #判断帖子详情页面title是否包含关键字
        assert search_value in topic_page.get_title_text()

        #判断帖子详情内容是否包含关键字
        assert search_value in topic_page.get_content_text()

202041412115欧明朗
base_page.py

from selenium import webdriver


class BasePage:
    def __init__(self, driver=None):
        if driver is None:
            # 打开浏览器
            self.driver = webdriver.Chrome()
            # 隐式等待
            self.driver.implicitly_wait(6)
        else:
            self.driver = driver

    def find(self, element):
        # 找元素
        return self.driver.find_element(*element)

index_page.py

from selenium.webdriver.common.by import By
from bpytest.pages.base_page import BasePage
from bpytest.pages.search_page import SearchPage


class IndexPage(BasePage):
    base_url = "https://ceshiren.com/"
    search_btn = (By.CSS_SELECTOR, ".d-icon-search")
    search_input = (By.ID, "search-term")
    adv_search_btn = (By.CSS_SELECTOR, ".show-advanced-search")

    def open_url(self):
        # 打开首页
        self.driver.get(self.base_url)

    def click_search_btn(self):
        # 点击搜索按钮
        self.find(self.search_btn).click()

    def send_keys(self, search_value):
        # 往查询框输入待查内容
        self.find(self.search_input).send_keys(search_value)

    def click_adv_btn(self):
        # 点击高级查询按钮
        self.find(self.adv_search_btn).click()
        return SearchPage(self.driver)


search_page.py

from selenium.webdriver.common.by import By
from bpytest.pages.base_page import BasePage
from bpytest.pages.topic_page import TopicPage


class SearchPage(BasePage):
    search_result_title = (By.CSS_SELECTOR, ".search-link")

    def get_search_result_text(self):
        # 返回查询结果
        return self.find(self.search_result_title).text

    def click_search_result(self):
        # 点击查询结果
        self.find(self.search_result_title).click()
        return TopicPage(self.driver)


topic_page.py

from selenium.webdriver.common.by import By
from bpytest.pages.base_page import BasePage


class TopicPage(BasePage):
    topic_title = (By.CSS_SELECTOR, ".fancy-title")
    topic_content = (By.CSS_SELECTOR, ".cooked.inline-footnotes")

    def get_title_text(self):
        # 获取帖子标题
        return self.find(self.topic_title).text

    def get_content_text(self):
        # 获取帖子内容
        return self.find(self.topic_content).text

test_ceshiren_po.py

import pytest
from selenium import webdriver
from selenium.webdriver.common.by import By
from bpytest.pages.index_page import IndexPage


class TestCeshiren:
    # 测试前置条件
    def setup(self):
        self.index_page = IndexPage()
        self.index_page.open_url()

    # 搜索功能测试
    # @pytest.mark.parametrize("search_value", ["Selenium", "测试"])
    def test_search(self):
        search_value = "Selenium"

        # 点击查询按钮
        self.index_page.click_search_btn()
        # 输入查询值
        self.index_page.send_keys(search_value)
        # 点击高级查询按钮
        search_page = self.index_page.click_adv_btn()

        # 判断查询页面结果是否包含关键字
        res = search_page.get_search_result_text()
        assert search_value in res

        # 点击进入帖子详情页面
        topic_page = search_page.click_search_result()
        # 判断帖子详情页面title是否包含关键字
        assert search_value in topic_page.get_title_text()

        # 判断帖子详情内容是否包含关键字
        assert search_value in topic_page.get_content_text()

谢世龙 202041412121

from selenium import webdriver

class BasePage:
def init(self, driver = None):
if driver is None:
#打开浏览器
self.driver = webdriver.Chrome()
#隐式等待
self.driver.implicitly_wait(10)
else:
self.driver = driver

def find(self, element):
    #找元素
    return self.driver.find_element(*element)

from selenium.webdriver.common.by import By

from study3.base_page import BasePage
from study3.search_page import SearchPage

class IndexPage(BasePage):
base_url = “https://ceshiren.com/
search_btn = (By.CSS_SELECTOR, “.d-icon-search”)
search_input = (By.ID, “search-term”)
adv_search_btn = (By.CSS_SELECTOR, “.show-advanced-search”)

def open_url(self):
    #打开首页
    self.driver.get(self.base_url)

def click_search_btn(self):
    #点击搜索按钮
    self.find(self.search_btn).click()

def send_keys(self, search_value):
    #往查询框输入待查内容
    self.find(self.search_input).send_keys(search_value)

def click_adv_btn(self):
    #点击高级查询按钮
    self.find(self.adv_search_btn).click()
    return SearchPage(self.driver)

from selenium.webdriver.common.by import By

from study3.base_page import BasePage
from study3.topic_page import TopicPage

class SearchPage(BasePage):
search_result_title = (By.CSS_SELECTOR, “.search-link”)

def get_search_result_text(self):
    #返回查询结果
    return self.find(self.search_result_title).text

def click_search_result(self):
    #点击查询结果
    self.find(self.search_result_title).click()
    return TopicPage(self.driver)

import pytest
from selenium import webdriver
from selenium.webdriver.common.by import By

from study3.index_page import IndexPage

class TestCeshiren:
#测试前置条件
def setup(self):
self.index_page = IndexPage()
self.index_page.open_url()

#搜索功能测试
# @pytest.mark.parametrize("search_value", ["Selenium", "测试"])
def test_search(self):
    search_value = "Selenium"

    #点击查询按钮
    self.index_page.click_search_btn()
    #输入查询值
    self.index_page.send_keys(search_value)
    #点击高级查询按钮
    search_page = self.index_page.click_adv_btn()

    #判断查询页面结果是否包含关键字
    res = search_page.get_search_result_text()
    assert search_value in res

    #点击进入帖子详情页面
    topic_page = search_page.click_search_result()
    #判断帖子详情页面title是否包含关键字
    assert search_value in topic_page.get_title_text()

    #判断帖子详情内容是否包含关键字
    assert search_value in topic_page.get_content_text()

from selenium.webdriver.common.by import By

from study3.base_page import BasePage

class TopicPage(BasePage):
topic_title = (By.CSS_SELECTOR, “.fancy-title”)
topic_content = (By.CSS_SELECTOR, “.cooked.inline-footnotes”)

def get_title_text(self):
    #获取帖子标题
    return self.find(self.topic_title).text

def get_content_text(self):
    #获取帖子内容
    return self.find(self.topic_content).text

``

202041413221 叶磊
basePage

from selenium import webdriver


class BasePage:
    def __init__(self, driver = None):
        if driver is None:
            #打开浏览器
            self.driver = webdriver.Chrome()
            #隐式等待
            self.driver.implicitly_wait(10)
        else:
            self.driver = driver

    def find(self, element):
        #找元素
        return self.driver.find_element(*element)

indexPage

from selenium.webdriver.common.by import By

from study3.base_page import BasePage
from study3.search_page import SearchPage


class IndexPage(BasePage):
    base_url = "https://ceshiren.com/"
    search_btn = (By.CSS_SELECTOR, ".d-icon-search")
    search_input = (By.ID, "search-term")
    adv_search_btn = (By.CSS_SELECTOR, ".show-advanced-search")

    def open_url(self):
        #打开首页
        self.driver.get(self.base_url)

    def click_search_btn(self):
        #点击搜索按钮
        self.find(self.search_btn).click()

    def send_keys(self, search_value):
        #往查询框输入待查内容
        self.find(self.search_input).send_keys(search_value)

    def click_adv_btn(self):
        #点击高级查询按钮
        self.find(self.adv_search_btn).click()
        return SearchPage(self.driver)

searchPage

from selenium.webdriver.common.by import By

from study3.base_page import BasePage
from study3.topic_page import TopicPage


class SearchPage(BasePage):
    search_result_title = (By.CSS_SELECTOR, ".search-link")

    def get_search_result_text(self):
        #返回查询结果
        return self.find(self.search_result_title).text

    def click_search_result(self):
        #点击查询结果
        self.find(self.search_result_title).click()
        return TopicPage(self.driver)

test

import pytest
from selenium import webdriver
from selenium.webdriver.common.by import By

from study3.index_page import IndexPage


class TestCeshiren:
    #测试前置条件
    def setup(self):
        self.index_page = IndexPage()
        self.index_page.open_url()

    #搜索功能测试
    # @pytest.mark.parametrize("search_value", ["Selenium", "测试"])
    def test_search(self):
        search_value = "Selenium"

        #点击查询按钮
        self.index_page.click_search_btn()
        #输入查询值
        self.index_page.send_keys(search_value)
        #点击高级查询按钮
        search_page = self.index_page.click_adv_btn()

        #判断查询页面结果是否包含关键字
        res = search_page.get_search_result_text()
        assert search_value in res

        #点击进入帖子详情页面
        topic_page = search_page.click_search_result()
        #判断帖子详情页面title是否包含关键字
        assert search_value in topic_page.get_title_text()

        #判断帖子详情内容是否包含关键字
        assert search_value in topic_page.get_content_text()

topicPage

from selenium.webdriver.common.by import By

from study3.base_page import BasePage


class TopicPage(BasePage):
    topic_title = (By.CSS_SELECTOR, ".fancy-title")
    topic_content = (By.CSS_SELECTOR, ".cooked.inline-footnotes")

    def get_title_text(self):
        #获取帖子标题
        return self.find(self.topic_title).text

    def get_content_text(self):
        #获取帖子内容
        return self.find(self.topic_content).text

201941412218 魏峰
test_ceshiren.py
def setup(self):
base_url = “https://ceshiren.com/
self.driver = webdriver.Chrome()
self.driver.get(base_url)
self.driver.implicitly_wait(10)

def test_search(self):
search_btn = (By.CSS_SELECTOR,“.d-icon-search”)
search_input = (By.ID,“search-term”)
adv_search_btn = (By.CSS_SELECTOR,“.show-advanced-search”)
search_result_title = (By.CSS_SELECTOR,“.search-link”)
search_value = “Selenium”
self.driver.find_element(*search_btn).click()
self.driver.find_element(*search_input).send_keys(search_value)

self.driver.find_element(*adv_search_btn).click()

res = self.driver.find_element(*search_result_title)
assert search_value in res.text

base_page.py

class BasePage:
def init(self,driver=None):

    if driver is None:


        self.driver = webdriver.Edge()

        self.driver.implicitly_wait(10)
    else:
        self.driver = driver

def find(self,loc):
    return  self.driver.find_element(*loc)

index_page.py
from selenium.webdriver.common.by import By

from page_obj.pages.base_page import BasePage
from page_obj.pages.search_page import SearchPage
from page_obj.pages.topic_page import TopicPage

class IndexPage(BasePage):
base_url = “https://ceshiren.com/
search_btn=(By.CSS_SELECTOR,“.d-icon-search”)
search_input=(By.ID,“search-term”)
adv_search_btn=(By.CSS_SELECTOR,“.show-advanced-search”)
search_btn_xiangqing=(By.CSS_SELECTOR,“.search-link”)

def open_index_page(self):
    self.driver.get(self.base_url)

def click_search_btn(self):
    self.find(self.search_btn).click()

def input_search_value(self,search_value):

    self.find(self.search_input).send_keys(search_value)

def click_adv_search_btn(self):
    self.find(self.adv_search_btn).click()
    return SearchPage(driver=self.driver)

def click_search_xaingqing(self):
    self.find(self.search_btn_xiangqing).click()
    return TopicPage(driver=self.driver)

search_page.py

from selenium.webdriver.common.by import By

from page_obj.pages import topic_page
from page_obj.pages.base_page import BasePage
from page_obj.pages.topic_page import TopicPage

class SearchPage(BasePage):
search_result_title = (By.CSS_SELECTOR,“.search-link”)

def get_search_result(self):
    return self.find(self.search_result_title).text


def click_search_result(self):
    self.find(self.search_result_title).click()
    return TopicPage(driver=self.driver)

topic_gage.py

from selenium.webdriver.common.by import By

from page_obj.pages.base_page import BasePage

class TopicPage(BasePage):
topic_title=(By.CSS_SELECTOR,“.fancy-title”)
xq=(By.CSS_SELECTOR,“.inline-footnotes”)

def get_title_text(self):
    return  self.find(self.topic_title).text

def get_xq_text(self):
    return self.find(self.xq).text