• 作业链接

    基于PO,app测试框架:https://github.com/RunzeWu/SnowBallTest

  • GitHub链接

    基于PO,app测试框架:https://github.com/RunzeWu/SnowBallTest

  • GitHub链接

    基于PO,app测试框架:https://github.com/RunzeWu/SnowBallTest

    allure测试结果:


  • 抽空写了粗糙的框架,代码有点多,上传github了

    Github: https://github.com/RunzeWu/SnowBallTest

    测试结果

    5个用例共耗时36s

    allure截图如下:

  • GitHub地址

    https://github.com/RunzeWu/WeWorkTest

    公司任务重,天天加班,有部分地方没有写的很完善。。

    结果

    • 课后作业
    import logging
    import time
    import pytest, allure
    from faker import Faker
    from selenium import webdriver
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    from selenium.webdriver.support.ui import WebDriverWait

    logging.basicConfig(level=logging.INFO)

    contacts_locator = (By.ID, "menu_contacts")
    add_member_btn_locator = (By.LINK_TEXT, "添加成员")
    user_input_locator = (By.ID, "username")
    userid_input_locator = (By.ID, "memberAdd_acctid")
    memberAdd_phone_locator = (By.ID, "memberAdd_phone")
    save_btn_locator = (By.LINK_TEXT, "保存")


    @allure.feature("企业微信测试")
    class TestWework():

    def setup(self):
    options = webdriver.ChromeOptions()
    options.debugger_address = "127.0.0.1:9222"
    self.driver = webdriver.Chrome(options=options)
    logging.info("debug调试链接成功")
    self.f = Faker(locale='zh_CN')
    self.fakename = self.f.name()
    self.fake_id = self.f.ssn()
    self.fake_mobile = self.f.phone_number()

    def teardown(self):
    # self.driver.close()
    pass

    @allure.story("测试添加成员")
    @user30801
    def test_add_member(self):
    # 1
    with allure.step("点击通讯录"):
    WebDriverWait(self.driver,5).until(EC.presence_of_element_located(contacts_locator)).click()
    time.sleep(3)
    logging.info("{}操作成功".format(contacts_locator))
    # 2
    with allure.step("点击添加按钮"):
    WebDriverWait(self.driver, 5).until(EC.presence_of_element_located(add_member_btn_locator)).click()
    # self.driver.execute_script("arguments[0].click();",
    # WebDriverWait(self.driver,5).until(EC.presence_of_element_located(add_member_btn_locator)))
    logging.info("{}操作成功".format(add_member_btn_locator))
    # 3
    with allure.step("输入用户名"):
    WebDriverWait(self.driver, 5).until(EC.presence_of_element_located(user_input_locator)).send_keys(self.fakename)
    logging.info("{}操作成功".format(user_input_locator))
    # 4
    with allure.step("输入id"):
    WebDriverWait(self.driver, 5).until(EC.presence_of_element_located(userid_input_locator)).send_keys(self.fake_id)
    logging.info("{}操作成功".format(userid_input_locator))
    # 5
    with allure.step("输入手机号码"):
    WebDriverWait(self.driver, 5).until(EC.presence_of_element_located(memberAdd_phone_locator)).send_keys(self.fake_mobile)
    logging.info("{}操作成功".format(memberAdd_phone_locator))
    # 6
    with allure.step("点击保存按钮"):
    WebDriverWait(self.driver, 5).until(EC.presence_of_element_located(save_btn_locator)).click()
    logging.info("{}操作成功".format(save_btn_locator))

    with allure.step("断言判断"):
    try:
    assert self.fakename,self.fake_mobile in self.driver.page_source
    logging.info("添加成员用例测试成功")
    except AssertionError as e:
    logging.error("添加成员用例测试失败")
    raise e

    • allure截图
    • 课间作业
    import time

    from selenium import webdriver


    class TestDemo():

    def setup_class(self):
    self.driver = webdriver.Chrome()
    self.driver.implicitly_wait(5)

    def teardown_class(self):
    self.driver.quit()

    def test_homework(self):
    self.driver.get('https://testerhome.com/')
    topic_ele = self.driver.find_element_by_xpath("//a[@href='/topics/19682']")
    topic_ele.click()
    btn_ele = self.driver.find_element_by_xpath("//button[@class='btn btn-default']")
    btn_ele.click()
    ele = self.driver.find_element_by_xpath("//a[@class='toc-item-link'][contains(.,'下载方法')]")
    ele.click()
    time.sleep(3)
    • 课后作业
    # -*- coding: utf-8 -*-
    '''
    @Time: 2019-07-28
    @Author: 吴润泽
    '''
    import logging
    import time

    from selenium import webdriver
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    from selenium.webdriver.support.ui import WebDriverWait

    logging.basicConfig(level=logging.INFO)


    class TestTesterhome():

    def setup(self):
    self.driver = webdriver.Chrome()
    self.driver.implicitly_wait(5)
    self.driver.get('https://testerhome.com/')

    def teardown(self):
    self.driver.close()

    def test_view_newest_topic(self):
    view_more_locator = (By.XPATH, "//a[@href='/topics/last']")
    view_more_ele = WebDriverWait(self.driver, 10).until(EC.presence_of_element_located(view_more_locator))
    view_more_ele.click()
    logging.info("查看最新帖子成功")

    def test_access_denied(self):
    team_locator = (By.XPATH, "//a[@href='/teams']")
    team_ele = WebDriverWait(self.driver, 10).until(EC.presence_of_element_located(team_locator))
    logging.info("{}元素定位成功".format(team_locator))
    team_ele.click()

    hogwarts_locator = (By.LINK_TEXT, "霍格沃兹测试学院")
    hogwarts_ele = WebDriverWait(self.driver, 10).until(EC.presence_of_element_located(hogwarts_locator))
    logging.info("{}元素定位成功".format(hogwarts_locator))
    hogwarts_ele.click()

    topic_locator = (By.XPATH,"//a[contains(@title,'20190728')]")
    topic_ele = WebDriverWait(self.driver, 10).until(EC.presence_of_element_located(topic_locator))
    logging.info("{}元素定位成功".format(topic_locator))
    topic_ele.click()
    time.sleep(3)

    try:
    assert "没有权限" in self.driver.page_source
    logging.info("用例执行成功")
    except AssertionError as e:
    logging.error("用例执行失败")
    raise e

    def test_wrong_login(self):
    login_locator = (By.XPATH, "//a[@href='/account/sign_in']")
    team_ele = WebDriverWait(self.driver, 10).until(EC.presence_of_element_located(login_locator))
    logging.info("{}元素定位成功".format(login_locator))
    team_ele.click()

    user_locator = (By.ID, "user_login")
    user_ele = WebDriverWait(self.driver, 10).until(EC.presence_of_element_located(user_locator))
    logging.info("{}元素定位成功".format(user_locator))
    user_ele.send_keys("hogwarts")

    pwd_locator = (By.ID, "user_password")
    pwd_ele = WebDriverWait(self.driver, 10).until(EC.presence_of_element_located(pwd_locator))
    logging.info("{}元素定位成功".format(pwd_locator))
    pwd_ele.send_keys("hogwarts")
    pwd_ele.submit()
    time.sleep(3)

    try:
    assert "Your account is locked" or "密码错误" in self.driver.page_source
    logging.info("用例执行成功")
    except AssertionError as e:
    logging.error("用例执行失败")
    raise e

    def test_content_match(self):
    search_input_locator = (By.XPATH, "//input[@name='q']")
    search_input_ele = WebDriverWait(self.driver, 10).until(EC.presence_of_element_located(search_input_locator))
    logging.info("{}元素定位成功".format(search_input_locator))
    search_input_ele.send_keys("测试媛")
    search_input_ele.submit()

    ceshiyuan_topic_locator = (By.XPATH, "//a[@href='/topics/18442']")
    ceshiyuan_topic_ele = WebDriverWait(self.driver, 10).until(EC.presence_of_element_located(ceshiyuan_topic_locator))
    logging.info("{}元素定位成功".format(ceshiyuan_topic_locator))

    content_locator = (By.XPATH, "//a[@href='/topics/18442']/../following-sibling::div[2]")
    content = WebDriverWait(self.driver, 10).until(EC.presence_of_element_located(content_locator)).text
    logging.info("{}元素定位成功".format(content_locator))
    logging.info(content)

    ceshiyuan_topic_ele.click()
    time.sleep(3)
    try:
    assert content in self.driver.page_source
    logging.error("用例执行成功")
    except AssertionError as e:
    logging.error("用例执行失败")
    raise e

    • allure 截图
  • # -*- coding: utf-8 -*-
    '''
    @Time: 2019-07-28
    @Author: 夜雨声烦
    '''
    from selenium import webdriver


    class TestDemo():

    def setup_class(self):
    self.driver = webdriver.Chrome()
    self.driver.implicitly_wait(5)

    def teardown_class(self):
    self.driver.quit()

    def test_homework(self):
    self.driver.get('https://testerhome.com/')
    topic_ele = self.driver.find_element_by_xpath("//a[@href='/topics/19682']")
    topic_ele.click()
    link_ele = self.driver.find_element_by_link_text("https://testerhome.com/topics/19664")
    link_ele.click()
    windows = self.driver.window_handles
    self.driver.switch_to.window(windows[-1])
    try:
    assert '有奖投票' in self.driver.page_source
    print("success")
    except AssertionError as e:
    print("failed")
    raise e
  • conftest.py

    # -*- coding: utf-8 -*-
    '''
    create time: 2019-07-21
    author: 吴润泽
    '''
    import pytest
    import logging


    @pytest.fixture(scope="module")
    def module_env():
    logging.info(" module set up")
    yield
    logging.info("module tear down")


    @pytest.fixture(scope="class")
    def classA_env():
    yield
    logging.info("classA tear down")


    @pytest.fixture(scope="function")
    def func_env():
    logging.info("classB func setup")
    return

    test_homework.py

    # -*- coding: utf-8 -*-
    '''
    create time: 2019-07-20
    author: 吴润泽
    '''
    import pytest
    import logging
    import yaml

    logging.basicConfig(level=logging.DEBUG)

    @pytest.mark.usefixtures('module_env')
    @pytest.mark.usefixtures("classA_env")
    @pytest.mark.run(order=1)
    class TestClassA:


    def test_one(self):
    print("This is ClassA func1")

    def test_two(self):
    print("This is ClassA func2")

    def test_three(self):
    print("This is ClassA func3")


    @pytest.mark.run(order=2)
    @pytest.mark.usefixtures("func_env")
    class TestClassB:

    def test_four(self):
    print("This is ClassB func4")

    def test_five(self):
    print("This is ClassB func5")

    @pytest.mark.parametrize("x,y,z", yaml.load(open("data.yml")))
    def test_six(self, x, y, z):
    print("This is ClassB func6")
    print(x,y,z)


    class TestClassC:

    @pytest.mark.run(order=5)
    def test_seven(self):
    print("This is ClassC func7")

    @pytest.mark.run(order=3)
    def test_egiht(self):
    print("This is ClassC func8")

    @pytest.mark.run(order=4)
    def test_nine(self):
    print("This is ClassC func9")


    if __name__ == '__main__':
    pytest.main()

    结果

  • 作业

    # -*- coding: utf-8 -*-
    '''
    create time: 2019-07-20
    author: 吴润泽
    '''
    import pytest
    import logging
    import yaml

    logging.basicConfig(level=logging.DEBUG)


    def setup_module():
    logging.info("login")


    def teardown_module():
    logging.info("module teardown")


    @pytest.mark.run(order=1)
    class TestClassA:

    @classmethod
    def teardown_class(cls):
    logging.info("ClassA tear down")

    def test_one(self):
    print("This is ClassA func1")

    def test_two(self):
    print("This is ClassA func2")

    def test_three(self):
    print("This is ClassA func3")


    @pytest.mark.run(order=2)
    class TestClassB:

    def setup(self):
    logging.info("ClassB function set up")

    def test_four(self):
    print("This is ClassB func4")

    def test_five(self):
    print("This is ClassB func5")

    @pytest.mark.parametrize("x,y,z", yaml.load(open("data.yml")))
    def test_six(self, x, y, z):
    print("This is ClassB func6")
    print(x,y,z)


    class TestClassC:

    @pytest.mark.run(order=5)
    def test_seven(self):
    print("This is ClassC func7")

    @pytest.mark.run(order=3)
    def test_egiht(self):
    print("This is ClassC func8")

    @pytest.mark.run(order=4)
    def test_nine(self):
    print("This is ClassC func9")


    if __name__ == '__main__':
    pytest.main()

    截图