• docker 实战 at November 28, 2019

    #作业一:使用docker搭建一个可以访问的jenkins服务

    #作业二:使用docker搭建一个可以访问的testlink服务

    #作业三:使用container模式搭建前端和后端服务

    #作业四:启动grafana

    #作业五:使用普罗米修斯+grafana监控mysql

  • 作业一、二:

    from time import sleep
    import pytest
    from appium import webdriver

    class TestXueqiu:
    def setup(self):
    caps = {}
    caps["platformName"] = "android"
    caps["deviceName"] = "shirley"
    caps["appPackage"] = "com.xueqiu.android"
    caps["appActivity"] = ".view.WelcomeActivityAlias"
    caps["autoGrantPermissions"] = True

    self.driver = webdriver.Remote("http://localhost:4723/wd/hub", caps) # self变成实例变量
    self.driver.implicitly_wait(15) # 隐式等待

    self.driver.find_element_by_id('user_profile_icon').click()
    self.driver.find_element_by_id('login_more').click()

    def test_wrong_phone(self): # 错误的手机号,断言弹框内容
    self.driver.find_element_by_id('login_account').send_keys('5765dg')
    self.driver.find_element_by_id('login_password').send_keys('35678245d')
    self.driver.find_element_by_id('button_next').click()
    error = self.driver.find_element_by_id('md_content').text
    assert error == '手机号码填写错误'
    self.driver.find_element_by_xpath("//*[@text='确定']")

    def test_wrong_password(self): # 错误的密码,断言弹框内容
    self.driver.find_element_by_id('login_account').send_keys('15501862637')
    self.driver.find_element_by_id('login_password').send_keys('35678245d')
    self.driver.find_element_by_id('button_next').click()
    error = self.driver.find_element_by_id('md_content').text
    assert error == '用户名或密码错误'
    self.driver.find_element_by_xpath("//*[@text='确定']")

    def teardown(self):
    sleep(10)
    self.driver.quit()

    作业三:

    from appium import webdriver
    from hamcrest import *

    class TestXueqiu:
    def setup_class(self):
    caps = {}
    caps["platformName"] = "android"
    caps["deviceName"] = "shirley"
    caps["appPackage"] = "com.xueqiu.android"
    caps["appActivity"] = ".view.WelcomeActivityAlias"
    caps["autoGrantPermissions"] = True

    self.driver = webdriver.Remote("http://localhost:4723/wd/hub", caps) # self变成实例变量
    self.driver.implicitly_wait(15) # 隐式等待

    def setup(self):
    pass # 因为setup不用做什么,直接从主页输入就可以

    def teardown(self):
    sleep(10)
    self.driver.find_element_by_id('action_close').click()

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

    @pytest.mark.parametrize("keyword, stock_type, expect_price", [
    ('alibaba', 'BABA', 170),
    ('xiaomi', '01810', 8.5),
    ('google', 'GOOGL', 1260)
    ])
    def test_search(self, keyword, stock_type, expect_price):
    self.driver.find_element_by_id('home_search').click()
    self.driver.find_element_by_id('search_input_text').send_keys(keyword)
    self.driver.find_element_by_id('name').click()
    price = float(self.driver.find_element_by_xpath(
    "//*[contains(@resource-id, 'stockCode') and @text='"
    + stock_type + "']/../../..//*[contains(@resource-id, 'current_price')]").text)
    print(price)
  • 作业一:百度输入“腾讯”,篡改成数据“阿里”,返回阿里结果。

    作业二:百度搜索“你好”,设置breakpoint,修改request,改成“哈哈”

    作业三:通过设置throtting中的参数,控制网速后访问百度:

    查找的相关参数解释:

  • 课间作业一:
    def test_get_login(self):
    url = 'https://testerhome.com/api/v3/topics.json'
    r = requests.get(url, params={'limit': '2'})
    assert r.json()['topics'][1]['user']['login'] == 'chenhengjie123'

    def test_xueqiu_search(self):
    url = 'https://xueqiu.com/stock/search.json'
    params = {'code': 'sogo', 'size': '3', 'page': '1'}
    headers = {'Accept': 'application/json', 'aliyungf_tc': 'AQAAAKdDATuZuggAKBYRDlDFMpODE4QO',
    'User-Agent': 'Mozilla/5.0'}
    cookies = {'xq_a_token': 'd831cd39b53563679545656fba1f4efd8e48faa0'}
    data = requests.get(url, params=params, headers=headers, cookies=cookies).json()
    assert data['stocks'][0]['name'] == '搜狗'