• 表示很感兴趣,已加楼主,麻烦楼主推一波😁

  • 在V站肯定有个帖子标题是:35岁水平一般的开发,如何才能不失业。so,最后讨论完也只能继续干下去

  • 之前没做过呢,因为测试环境也是用的谷歌邮箱登录,研究了一番貌似是没办法解决。然后用selenium自动化倒是没有出现过验证码了。。先用selenium顶着用吧😂

  • 最近也在用airetest的selenium,想请问一下楼主做web自动化时,需要验证码登录的场景如何能解决呢?因为我们的web是接入google登录的,没办法让开发弄万能验证码。

  • 作业四:

    data/globalconfig.json【存放初始化driver的参数】

    {
    "app": "",
    "url": "http://127.0.0.1:4723/wd/hub",
    "wait": 6,
    "capabilities":{
    "platformName": "android",
    "deviceName": "127.0.0.1:62001",
    "appPackage": "com.xueqiu.android",
    "appActivity": ".view.WelcomeActivityAlias",
    "autoGrantPermissions": "true"
    }
    }

    common/startset.py【启动driver的类和方法】

    class StartSet():
    def __init__(self):
    self.path = os.getcwd()
    with open(self.path + "\data\globalconfig.json", "r", encoding="UTF-8") as f:
    jsoncaps = json.load(f)
    self.caps = jsoncaps["capabilities"]
    self.driver = webdriver.Remote(jsoncaps["url"], self.caps)
    self.driver.implicitly_wait(jsoncaps["wait"])

    def get_driver(self):
    return self.driver

    page/base_page.py【编写find方法封装,并接收self.driver参数】

    class BasePage(object):
    def __init__(self,driver):
    self.driver = driver

    def find_xpath(self,value):
    loclist = []
    try:
    for n in range(5):
    time.sleep(1)
    ele = self.driver.find_element_by_xpath(value)
    loclist.append(ele.location)
    if n>1:
    if loclist[n] == loclist[n-1]:
    return ele
    except:
    print("出现评价弹框")
    self.driver.find_element_by_xpath("//*[@text='下次再说']").click()
    print("点击下次再说")
    return self.driver.find_element_by_xpath(value)

    page/mian_page.py【编写主页面的page类,包括进入其他页面的入口方法】

    class MainPage(BasePage):
    def __init__(self, driver):
    super(MainPage, self).__init__(driver)

    def gotoProfile(self):
    self.by_id("user_profile_icon").click()
    return ProfilePage(self.driver)

    def gotoSearch(self):
    self.by_id("home_search").click()
    return SearchPage(self.driver)

    page/search_page.py【编写搜索页面的page类】

    class SearchPage(BasePage):
    def __init__(self,driver):
    super(SearchPage,self).__init__(driver)

    def search(self,key):
    self.by_id("search_input_text").send_keys(key)

    def cancel(self):
    self.by_id("action_close").click()

    def guanzhu(self):
    self.find_xpath("//*[@resource-id='com.xueqiu.android:id/add_attention']").\
    find_element_by_class_name("android.widget.TextView").click()

    cases/test_xueqiu.py【编写用例】

     @pytest.fixture(scope='function', autouse=True)
    def setUpdriver(self):
    self.driver = startset.StartSet().get_driver()
    self.MainPage = main_page.MainPage(self.driver)
    self.SearchPage = self.MainPage.gotoSearch()
    yield
    self.driver.quit()

    @pytest.mark.parametrize("key",["阿里巴巴","腾讯"])
    def test_zixuan(self,key):
    self.SearchPage.search(key)
    self.SearchPage.guanzhu()
  • print的内容貌似不会输出到报告中?

  • 课后作业:

    from appium import webdriver
    import pytest
    import time


    class Test_xueqiu(object):
    @pytest.fixture(scope='function', autouse=True)
    def startDriver(self):
    self.caps = {}
    self.caps["platformName"] = "Android"
    self.caps["platformVersion"] = "4.4"
    self.caps["deviceName"] = "127.0.0.1:62001"
    self.caps["appActivity"] = ".view.WelcomeActivityAlias"
    self.caps["appPackage"] = "com.xueqiu.android"

    self.driver = webdriver.Remote('127.0.0.1:4723/wd/hub',self.caps)
    self.driver.implicitly_wait("6")

    yield
    self.driver.quit()


    #封装find方法,处理有时候会弹出的评价弹框
    def find_xpath(self,value):
    loclist = []
    try:
    for n in range(5):
    time.sleep(1)
    ele = self.driver.find_element_by_xpath(value)
    loclist.append(ele.location)
    if n>1:
    if loclist[n] == loclist[n-1]:
    return ele
    except:
    print("出现评价弹框")
    self.driver.find_element_by_xpath("//*[@text='下次再说']").click()
    print("点击下次再说")
    return self.driver.find_element_by_xpath(value)


    def test_pdd(self):
    self.driver.find_element_by_id("home_search").click()
    self.driver.find_element_by_id("search_input_text").send_keys("pdd")
    self.driver.find_elements("xpath", "//*[contains(@resource-id, 'stockName')]")[0].click()

    def test_alibaba(self):
    self.find_xpath("//*[@text='自选']").click()
    self.driver.find_element_by_id("action_create_cube").click()
    self.driver.find_element_by_id("search_input_text").send_keys("alibaba")
    assert self.find_xpath("//*[contains(@resource-id, 'stockName')]").text == "阿里巴巴"
    self.find_xpath("//*[contains(@resource-id, 'follow_btn')]").click()
    time.sleep(4)
    self.find_xpath("//*[@text='取消']").click()
    try:
    self.driver.find_element_by_id("iv_close").click()
    except:
    pass
    assert self.find_xpath( "//*[contains(@text, '阿里巴巴')]")



    if __name__ == "__main__":
    pytest.main("-s test_xueqiu.py")
  • 想问下,为什么用appium跑用例时会出现手工操作时不一样的控件?比如添加自选股票,appium跑的时候会必弹出评价雪球的弹框,添加自选后回到首页会弹出“自选股票在这里”的蒙层提示,但是在手工进行同样操作却没有这些弹框?需要在初始化driver的时候加什么参数吗?

  • 课后作业:
    覆盖率用插件pytest-cov,命令行启动:pytest --cov=dir test/dir

    代码和结果如下:

    from xpinyin import Pinyin
    import pytest
    import allure
    import os


    @allure.feature('test_get_pinyin')
    @allure.story('test_defult')
    @allure.severity('blocker')
    @allure.issue("www.baidu.com")
    def test_get_pinyin_defult():
    with allure.step('默认参数'):
    result = Pinyin().get_pinyin()
    assert result == "ni-hao"


    @allure.feature('test_get_pinyin')
    @allure.story('test_chars_marks_convert')
    @pytest.mark.parametrize("chars,tone_marks,convert,value",[
    ("深圳",None,'lower','shen-zhen'),
    ("深圳",'marks','upper','SHĒN-ZHÈN'),
    ("深圳",'numbers','capitalize','Shen1-Zhen4'),
    ("shenzhen",'numbers','capitalize','shen1zhen'),
    ("深zhen",'numbers','capitalize','Shen1-zhen')
    ])
    def test_get_pinyin(chars,tone_marks,convert,value):
    with allure.step('修改marks参数'):
    result = Pinyin().get_pinyin(chars=chars,tone_marks=tone_marks,convert=convert)
    path = os.path.join(os.path.abspath(os.path.join(os.path.dirname(__file__),"..")),"img/timg.jpg") #获取当前脚本文件的绝对路径
    file = open(path,'rb').read()
    allure.attach('test_img',file,allure.attach_type.JPG)
    assert result == value


    @allure.feature('test_get_pinyin')
    @allure.story('test_split')
    @pytest.mark.parametrize("splitter,value",[(u'+',"ni+hao"),(u'*',"ni*hao")])
    def test_get_pinyin_split(splitter,value):
    assert Pinyin().get_pinyin(splitter=splitter) == value


    @allure.feature('test_get_initial')
    @pytest.mark.parametrize("chars,value",[("芳","F"),("F","F")])
    def test_get_initial(chars,value):
    assert Pinyin().get_initial(chars) == value


    @allure.feature('test_get_initial')
    @pytest.mark.parametrize("chars,value",[("芳芳","F-F"),("F芳","F-F"),("芳F","F-F")])
    def test_get_initials(chars,value):
    assert Pinyin().get_initials(chars) == value

    init文件覆盖率达到90%:

    allure报告截图:

  • 测试基础,编程水平,项目经验,三项至少要有一项是突出才行吧。自身体验来说,功能测试转自动化都不是太容易的事