seldom icon indicating copy to clipboard operation
seldom copied to clipboard

poium~=1.1.1,在seldom中不能继承driver调用了吗?

Open tzk1986 opened this issue 3 years ago • 1 comments

import seldom
from seldom import Seldom
from poium import Page, Element


class BaiduPage(Page):
    """baidu page"""
    search_input = Element(id_="kw")
    search_button = Element(id_="su")


class BaiduSearchPage(Page):
    """
    百度搜索结果
    """
    search_result = Element(xpath="//div/h3/a", index=1)


class BaiduTest(seldom.TestCase):
    """Baidu serach test case"""

    def start(self):
        """
        可以在start中引用多个页面
        """
        self.baidu_page = BaiduPage(Seldom.driver)
        self.baidu_search_page = BaiduSearchPage(Seldom.driver)

    def test_case(self):
        """
        A simple test
        """
        self.baidu_page.open("https://www.baidu.com")
        self.baidu_page.search_input = "seldom"
        self.baidu_page.search_button.click()
        self.sleep(2)
        ret = self.baidu_search_page.search_result.text
        print(ret)


if __name__ == '__main__':
    seldom.main(debug=True)

执行后提示

Error Traceback (most recent call last): File "/Users/tangzhongkai/PycharmProjects/seldomtest/mytest02/test_dir/new_demo.py", line 40, in test_case self.baidu_page.open("https://www.baidu.com") File "/Users/tangzhongkai/PycharmProjects/2022unittest/venv/lib/python3.9/site-packages/poium/page_objects.py", line 77, in open self.driver.get(root_uri + uri) AttributeError: 'NoneType' object has no attribute 'get'

使用selenium中的webdriver.Chrome()调用,无此问题

class BaiduTest(seldom.TestCase):
    """Baidu serach test case"""

    def start(self):
        """
        可以在start中引用多个页面
        """
        self.baidu_page = BaiduPage(webdriver.Chrome())
        self.baidu_search_page = BaiduSearchPage(webdriver.Chrome())

tzk1986 avatar May 26 '22 11:05 tzk1986

seldom 支持http 接口和 web 自动化。在web测试中自动帮你启动浏览器, 那么seldom 是如何知道你运行的是web测试而不是http接口测试的呢?

通过两个标识:

class BaiduTest(seldom.TestCase):
    """Baidu search test case"""

    def test_case(self):
        """
        A simple test
        """
        self.open("http://www.baidu.com")  # 1. 调用 self.open() 方法


if __name__ == '__main__':
    seldom.main(browser='chrome', debug=True)   # 2.指定浏览器 browser='xxx'

你的代码中既没有 在 main() 方法中指定browser 参数,有没有使用self.open() 方法,所以,seldom 不知道你要执行的是 web测试。那他就无法 启动浏览器 并把浏览器对象给到 Seldom.driverSeldom.driver 是 None, 自然也无法给到 poium,

self.driver.get(root_uri + uri)
AttributeError: 'NoneType' object has no attribute 'get'

Seldom.driver --> self.driver 是None , 所以,他没有get() 方法。

defnngj avatar May 26 '22 14:05 defnngj