• 哇,占楼~

  • 好的,收到。以后会注意的。

  • 作业地址:https://github.com/yaya19910111/homework_hgws.git
    基于课程贴中的代码进行了修改和添加

  • 课间作业1
    进入testerhome,访问社团,访问霍格沃兹测试学院,访问最顶部的第一个帖子。把代码贴到回复里。

    # Generated by Selenium IDE
    import pytest
    import time
    import json
    from selenium import webdriver
    from selenium.webdriver.common.by import By
    from selenium.webdriver.common.action_chains import ActionChains
    from selenium.webdriver.support import expected_conditions
    from selenium.webdriver.support.wait import WebDriverWait
    from selenium.webdriver.common.keys import Keys
    from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

    class TestTestsele():
    def setup_method(self, method):
    self.driver = webdriver.Chrome()
    self.vars = {}

    def teardown_method(self, method):
    self.driver.quit()

    def test_testsele(self):
    self.driver.get("https://testerhome.com/")
    self.driver.set_window_size(1421, 944)
    self.driver.find_element(By.LINK_TEXT, "社团").click()
    self.driver.find_element(By.LINK_TEXT, "霍格沃兹测试学院").click()
    self.driver.find_element(By.CSS_SELECTOR, ".topic-21848 .title > a").click()

    课间作业2
    进入testerhome,访问MTSC2020置顶帖,点击目录,点击议题征集范围。把代码贴到回复里。

    import time

    from selenium import webdriver
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions
    from selenium.webdriver.support.wait import WebDriverWait


    class TestCase:

    def wait_click(self, element):
    WebDriverWait(self.driver, 10).until(
    expected_conditions.element_to_be_clickable(element)
    )

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

    def teardown_method(self):
    time.sleep(3)
    self.driver.quit()

    def test_page(self):
    element1 = (By.CSS_SELECTOR, 'button.btn.btn-default')
    element2 = (By.LINK_TEXT, '议题征集流程')
    self.driver.find_element(By.PARTIAL_LINK_TEXT, 'MTSC2020 中国互联网测试开发大会议题征集').click()
    self.wait_click(element1)
    self.driver.find_element(*element1).click()
    self.wait_click(element2)
    self.driver.find_element(*element2).click()

    课后作业3
    企业微信自动添加成员,需要复用已经登录的chrome,需要debugger address,代码贴到回复里
    需要在后台开启debug-adress,扫码登录企业微信:

    /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port=9222
    import os
    import time

    import pytest
    from selenium import webdriver
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions
    from selenium.webdriver.support.wait import WebDriverWait


    class TestWinXin:

    def setup_method(self):
    #多浏览器支持
    browser = os.getenv("browser","").lower()
    print(browser)

    if browser == "headless":
    self.driver = webdriver.PhantomJS()
    elif browser == "firefox":
    self.driver = webdriver.Firefox()
    else:
    options=webdriver.ChromeOptions()
    #使用debug
    options.debugger_address='127.0.0.1:9222'
    self.driver = webdriver.Chrome(options=options)

    self.driver.implicitly_wait(3)

    def teardown_method(self):
    time.sleep(3)
    self.driver.quit()

    @pytest.mark.parametrize("username,acctid,phone",
    [('test1','test1','15282064333'),
    ('test2','test2','15282064333')])
    def test_weixin_add(self,username,acctid,phone):
    """
    添加成员
    :return:
    """

    self.driver.get('https://work.weixin.qq.com/wework_admin/frame#index')
    self.driver.find_element(By.LINK_TEXT, "添加成员").click()
    element =(By.CSS_SELECTOR,'#username')
    WebDriverWait(self.driver,10).until(expected_conditions.visibility_of_element_located(element))
    self.driver.find_element(*element).send_keys(username)
    self.driver.find_element(By.CSS_SELECTOR, '#memberAdd_acctid').send_keys(acctid)
    self.driver.find_element(By.CSS_SELECTOR, '#memberAdd_phone').send_keys(phone)
    self.driver.find_element(By.LINK_TEXT, "保存" ).click()
  • 十一期_Python 测试_20191222 at December 22, 2019

    🌸
    1、课间作业一:

    def test_div_1():
    """
    b>0
    :return:
    """

    assert div(1,1)==1

    def test_div_2():
    """
    b=0
    :return:
    """

    assert div(1,0)

    def test_div_3():
    """
    b<0
    :return:
    """

    assert div(1,-1)==-1

    def test_div_4():
    """
    a>0
    :return:
    """

    assert div(1,1)==1

    def test_div_5():
    """
    a=0
    :return:
    """

    assert div(0,1)==0

    def test_div_6():
    """
    a<0
    :return:
    """

    assert div(-1,1)==-1

    2、课后作业2:

    import pytest
    from test_pytest.div import div


    # 整数运算
    @pytest.mark.parametrize("num1,num2,expectation", [(10, 5, 2), (10, -5, -2), (-8, 4, -2), (-8, -4, 2), (0, 2, 0)])
    def test_div_int(num1, num2, expectation):
    assert div(num1, num2) == expectation


    # 浮点运算
    @pytest.mark.parametrize("num1,num2,expectation",
    [(1, 2, 0.5),
    (1, 3, 0.33333333),
    (2, 3, 0.66666667),
    (8.88, 1.33, 6.67669173),
    (8.88, 2, 4.44),
    (8, 2.2, 3.63636364),
    (8, 0.5, 16)])
    def test_div_float(num1, num2, expectation):
    assert div(num1, num2) == expectation


    # 入参不为数字
    @pytest.mark.parametrize("num1,num2", [('a', 5), (1, 'b'), ('hello', 'world')])
    def test_div_non_num(num1, num2):
    assert div(num1, num2)


    # zero
    @pytest.mark.parametrize("num1,num2,expectation", [(1, 0, None), (0.5, 0, None), (0, 0, None)])
    def test_div_zero(num1, num2, expectation):
    assert div(num1, num2) == expectation

    报告截图:

  • 重邮的还可以投吗?

  • 课间作业1:从testerhome获取首页的代码,并统计有多少个帖子

    curl 'https://testerhome.com/' |grep -n '.*<a title=".*" href=".*">.*</a>$' |grep -v img |wc -l

    答案:30

    课间作业2:使用bing搜索引擎搜索shell,并给出bing的检索结果数,换成纯数字, 把代码和结果贴到回复里

    curl 'https://cn.bing.com/search?q=shell' > bing.txt
    grep -o "[0-9, ]*条结果" bing.txt |awk -F' ' '{print $1}' |sed 's/\,/''/g'

    答案:79100000

    拓展:返回的结果改为万返回

    grep -o "[0-9, ]*条结果" bing.txt |awk -F' ' '{print $1}' |sed -E -e 's/\,/''/g' -e 's/[0]{4,4}$//'

    答案:7910万

    课后作业3:(看完课后解答,觉得自己写得不够简练优美,决定改下自己的回答😂 😀
    演练web日志 /tmp/nginx.log
    1、找出log中的404 500的记录总共有多少条

    grep -E -o "^[0-9]*.[0-9]*.[0-9]*.[0-9]* - - \[.*\] \".*\" (404|500) " /tmp/nginx.log |wc -l
    #改正后
    awk '$9~/404|500/' /tmp/nginx.log |wc -l

    答案:267条

    2、找出访问量最高的前三名ip

    grep -E -o "^[0-9]*.[0-9]*.[0-9]*.[0-9]*" /tmp/nginx.log | sort | uniq -c |sort -rn |head -n 3
    #改正后
    awk '{print $1}' /tmp/nginx.log |sort |uniq -c |sort -rn |head -3
    #答案:
    282 216.244.66.241
    130 136.243.151.90
    110 127.0.0.1

    3、聚类所有的url,比如把/topics/1234 /topics/2434 都聚类成 /topics/id,去掉变化的数字等元素,聚类完成后取出top10的访问量最高的路由地址

    grep -E -o "(GET|POST|HEAD|PUT|DELETE|TRACE|OPTIONS|CONNECT).*HTTP"  /tmp/nginx.log | awk -F' ' '{print $2}' |sed -E -e 's/\?.*//g' -e 's/\/[0-9]+\//\/id\//g' -e 's/\/[0-9]+$/\/id/g' -e 's/\/[0-9]+\./\/id\./g' |sed -E -e 's#\/id\/.*(jpg|png|gif|jpeg).*#\/id#g' | sort | uniq -c | sort -rn |head -n 10
    #改正后
    awk '{print $7}' /tmp/nginx.log |sed -E \
    -e 's#\?.*##g' \
    -e 's#/[0-9]+[/|\.]#/id/#g' \
    -e 's#/[0-9]+$#/id#g' \
    -e 's#/[0-9a-z\-]*.(jpg|png|gif|jpeg).*$#/id#g' \
    | sed -E \
    -e 's#/topics/id#/topics/id/udid#' \
    -e 's#/([^/]*)/(topics|following|replies|followers|reward|favorites|columns|id)$#/userid/\2#' \
    -e 's#^/(topic|cable|id)$#/\1/udid#' \
    -e 's#^/[^/]+$#/userid#' \
    -e 's#/topics/node[0-9]+#/topic/nodeid#' \
    -e 's#/udid##' \
    |sort |uniq -c |sort -rn |head -10

    答案:

    584 /cable
    372 /topics/id
    195 /userid
    147 /topics/id/replies/id/edit
    94 /
    61 /uploads/photo/userid/id
    55 /_img/uploads/photo/userid/id
    49 /topics/id/replies/id/reply_suggest
    46 /userid/replies
    41 /topics/id/show_wechat
  • 😀 已填,占楼

  • 确定不说一下是哪家公司吗?直招还是什么?

  • 换了个手机就可以了😂