• 作业2:

    click函数
    #/bin/bash
    click (){
    adb shell "uiautomator dump --compressed && cat /sdcard/window_dum.xml" > dump.xml
    bounds=`less dump.xml | sed -e $'s#<node#\\\n<node#g' | grep "$1" | grep -o "bounds=[^ ]*" | awk -F '\\[|,|\\]' '{print $2,$3}'`
    adb shell "input tap $bounds"
    }

    send_keys函数
    #/bin/bash
    send_keys (){
    adb shell "uiautomator dump --compressed && cat /sdcard/window_dum.xml" > dump.xml
    bounds=`less dump.xml | sed -e $'s#<node#\\\n<node#g' | grep "$1" | grep -o "bounds=[^ ]*" | awk -F '\\[|,|\\]' '{print $2,$3}'`
    adb shell "input tap $bounds"
    adb shell "input text $2"
    }
  • Docker 实战 at July 13, 2019

    练习一
    使用host模式或者bridge模式启动jenkins服务
    需要的插件:
    GitHub
    SSH Salve
    Maven
    Allure

    bridge模式:docker run -d --name myjenkins -p 8080:8080 -v /e/Docker/test/jenkins:/var/jenkins_home jenkins/jenkins
    host模式: docker run -d --name myjenkins --network host -v /e/Docker/test/jenkins:/var/jenkins_home jenkins/jenkins

    练习二
    自己使用dockerfile build一个容器并启动。 然后使用jenkins的slave连接到这个容器上。

    docker build -t newtech .

    练习三
    自己使用container模式搭建模拟测试环境。

    docker run -d --name conan -p 8999:4200 conan
    docker run -d --name halmes --network container:conan halmes

    练习四
    使用docker selenium 启动一个hub,两个node。 每个node10个浏览器
    UI自动化代码地址:https://github.com/ycwdaaaa/techUI

    练习五
    配置自己的jenkins job 执行UI自动化

  • 作业1
    主页面的个人信息图标 -> 登录雪球 -> 手机及其他登陆 -> 邮箱手机号登陆 -> 输入用户名密码

    from appium import webdriver
    import unittest

    class LoginTesst(unittest.TestCase):
    def setUp(self):
    caps = {}
    caps["platformName"] = "android"
    caps["deviceName"] = "127.0.0.1:62001"
    caps["appPackage"] = "com.xueqiu.android"
    caps["appActivity"] = ".view.WelcomeActivityAlias"
    # caps["unicodeKeyBoard"] = "true"
    # caps["resetKeyBoard"] = "true"

    self.driver = webdriver.Remote("http://localhost:4723/wd/hub", caps)

    # 智能等待
    self.driver.implicitly_wait(5)


    def test_First(self):
    # 主页面的个人信息图标 -> 登录雪球 -> 手机及其他登陆 -> 邮箱手机号登陆 -> 输入用户名密码
    self.driver.find_element_by_id("user_profile_icon").click()
    self.driver.find_element_by_id("tv_login").click()
    self.driver.find_element_by_id("tv_login_by_phone_or_others").click()
    self.driver.find_element_by_id("tv_login_with_account").click()
    self.driver.find_element_by_id("login_account").send_keys("13269835517")
    self.driver.find_element_by_id("login_password").send_keys("123456")
    self.driver.find_element_by_id("button_next").click()
    self.driver.find_element_by_id("md_buttonDefaultPositive").click()

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


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

    作业2
    搜索 -> 输入小米 -> 点击股票类型 -> 点击小米股票

    from appium import webdriver
    import unittest

    class LoginTesst(unittest.TestCase):
    def setUp(self):
    caps = {}
    caps["platformName"] = "android"
    caps["deviceName"] = "127.0.0.1:62001"
    caps["appPackage"] = "com.xueqiu.android"
    caps["appActivity"] = ".view.WelcomeActivityAlias"
    # caps["unicodeKeyBoard"] = "true"
    # caps["resetKeyBoard"] = "true"

    self.driver = webdriver.Remote("http://localhost:4723/wd/hub", caps)

    # 智能等待
    self.driver.implicitly_wait(5)


    def test_login(self):
    # 主页面的个人信息图标 -> 登录雪球 -> 手机及其他登陆 -> 邮箱手机号登陆 -> 输入用户名密码
    self.driver.find_element_by_id("user_profile_icon").click()
    self.driver.find_element_by_id("tv_login").click()
    self.driver.find_element_by_id("tv_login_by_phone_or_others").click()
    self.driver.find_element_by_id("tv_login_with_account").click()
    self.driver.find_element_by_id("login_account").send_keys("13269835517")
    self.driver.find_element_by_id("login_password").send_keys("123456")
    self.driver.find_element_by_id("button_next").click()
    self.driver.find_element_by_id("md_buttonDefaultPositive").click()

    def test_search(self):
    # 搜索 -> 输入小米 -> 点击股票类型 -> 点击小米股票
    self.driver.find_element_by_id("tv_search").click()
    self.driver.find_element_by_id("search_input_text").send_keys("xiaomi")
    self.driver.find_element_by_xpath("//*[@text='股票' and @instance=2]").click()
    self.driver.find_element_by_xpath("//*[@text='小米集团-W']").click()

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


    if __name__ == '__main__':
    unittest.main()
  • Linux 三剑客 at May 06, 2019

    grep测试题
    找出nginx.log中所有404和503报错的log数据,取出前3条数据,把命令贴到回复里

    方法1cat nginx.log | grep -E -m3  'HTTP/1.1" 404|HTTP/1.1" 503'
    方法2cat nginx.log | awk '$9==404||$9==503{print $0}' | head -3
    方法3cat nginx.log | awk '{print $9}'| grep -E "404|503" | head -3

    找出404和500的数据,只打印状态码这一列,然后排序去重

    cat nginx.log | awk '$9~/404|500/{print $9}' | sort | uniq -c

    对所有404 500 的数据,统计出现这种状态码的url,需要对url汇总(汇总相似的url,把相同的资源但是变化的id去掉)去重,打印前5个出问题的路径

    cat nginx.log | awk '$9~/404|500/{print $7}' | sed 's/[0-9]\{1,\}/*/g'|sort | uniq -c | sort -nr| head -5
  • 作业1
    cat /etc/passwd | awk -F ':' '{print NR,$1}'

    作业2
    curl -s http://www.baidu.com/s?wd=ip | grep -o "本机IP:&nbsp;[0-9.]*" | awk -F ";" '{print $2}'

    作业3
    #!/bin/bash
    # 获取当前页面中的每个贴的id
    url="https://testerhome.com/topics"
    ids=$(curl -s $url | grep -o 'href="/topics/[0-9]*"' | awk -F "/|\"" '{print $(NF-1)}')

    # 遍历所有获取的id
    for id in $ids
    do
    # 获取点赞个数
    num=$(curl -s "$url/$id" | grep -o -m1 "<span>[0-9]* 个赞</span>"| awk -F ">|个" '{print $2}')
    if [ -z $num ]
    then
    echo "$url/$id 有0 个赞"
    else
    echo "$url/$id 有$num个赞"
    fi
    done

  • 作业2
    功能封装

    测试用例

  • 作业四:
    java
    import org.junit.Test;

    import static io.restassured.RestAssured.given;
    import static io.restassured.RestAssured.useRelaxedHTTPSValidation;
    import static io.restassured.matcher.RestAssuredMatchers.;
    import static org.hamcrest.Matchers.
    ;

    public class Xueqiu {

    @Test
    public void testSearch(){
    //信任https的任何证书
    // useRelaxedHTTPSValidation();

    //given开头表示输入数据
    given()
    //.log().all()
    //设置代理
    // .proxy("127.0.0.1",8888)
    //query请求
    .queryParam("code","sogo")
    //关信息
    .header("Cookie","liyungf_tc=AQAAAMWMITiaDQgAXA4M0p1ZfIdOus7l; xq_a_token=8309c28a83ae5d20f26b7fcc22debbcd459794bd; xq_a_token.sig=ekfY9a_we8nNlhOpvhWeZz85MrU; xq_r_token=d55d09822791a788916028e59055668bed1b7018; xq_r_token.sig=h9qWLLwRXV-QxfHHukEC2U76ZDA; _ga=GA1.2.804261921.1552390227; Hm_lvt_1db88642e346389874251b5a1eded6e3=1552390228; u=971552390230609; device_id=dcc4ee40bc6ab714e71e4ee6c305d8d5; s=e418vkw8kk; __utma=1.804261921.1552390227.1552561758.1552561758.1; __utmc=1; __utmz=1.1552561758.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); __utmb=1.1.10.1552561758; _gid=GA1.2.528240687.1552561763; Hm_lpvt_1db88642e346389874251b5a1eded6e3=1552562405; _gat=1")
    //表示触发条件
    .when()
    .get("https://xueqiu.com/stock/search.json")
    //对结果断言
    .then()
    //打断log
    .log().all()
    //状态码断言
    .statusCode(200)
    //.body("stocks[0].name",equalTo("搜狗"));
    //字段断言
    .body("stocks.name",hasItems("搜狗"))
    .body("stocks.code",hasItems("SOGO"))
    .body("stocks[0].stock_id",equalTo(1029472));

    }
    }

  • conftest.py文件

    from xpinyin import Pinyin
    import pytest
    @pytest.fixture(scope="session",autouse=True)
    def setup():
    # 初始化Pinyin
    print("测试开始")
    p = Pinyin()
    yield p
    print("测试结束")

    测试用例

    from xpinyin import Pinyin
    import pytest
    class TestParametrize:

    # 1、参数化
    @pytest.mark.parametrize("data,result", [
    ({}, "ni-hao"),
    ({"chars": u"上海"}, "shang-hai"),
    ({"chars": u"上海你好"}, "shang-hai-ni-hao"),
    ({"chars": u"上海", "splitter": u"*"}, "shang*hai"),
    ({"chars": u"上海", "splitter": u""}, "shanghai"),
    ({"chars": u"上海", "splitter": u" "}, "shang hai"),
    ({"chars": u"上海", "splitter": u"*", "tone_marks": "marks"}, "shàng*hǎi"),
    ({"chars": u"上海", "splitter": u"*", "tone_marks": "numbers"}, "shang4*hai3"),
    ({"chars": u"上海", "splitter": u"*", "tone_marks": "marks", "convert": "capitalize"}, "Shàng*Hǎi"),
    ({"chars": u"上海", "splitter": u"*", "tone_marks": "numbers", "convert": "upper"}, "SHANG4*HAI3")])
    def test_get_pinyin_one(self, setup,data, result):
    print("测试数据:%s,预约结果%s" % (data, result))
    assert setup.get_pinyin(**data) == result

    # 2pytest.assume断言多个assert
    def test_get_initial(self,setup):
    pytest.assume(setup.get_initial() == "N")
    pytest.assume(setup.get_initial("上") == "S")
    pytest.assume(setup.get_initial("行") == "X")

    执行命令和执行结果

    执行命令:pytest -s -q test_parametrize.py
    执行结果
    Test session starts (platform: win32, Python 3.6.5, pytest 3.6.1, pytest-sugar 0.9.2)
    cachedir: .pytest_cache
    sensitiveurl: .*
    rootdir: E:\python\practice\testerHome\xpinyin, inifile:
    plugins: rerunfailures-4.1, parallel-0.0.2, metadata-1.7.0, html-1.19.0, allure-adaptor-1.7.10, variables-1.7.1, sugar-0.9.2, selenium-1.15.0, ordering-0.6, datafiles-2.0, datadir-1.2.1, cov-2.6.1, base-ur
    l-1.4.1, assume-1.2
    测试开始
    测试数据:{},预约结果ni-hao

    test_parametrize.py 9% 测试数据:{'chars': '上海'},预约结果shang-hai
    test_parametrize.py ✓✓ 18% █▊ 测试数据:{'chars': '上海你好'},预约结果shang-hai-ni-hao
    test_parametrize.py ✓✓✓ 27% ██▊ 测试数据:{'chars': '上海', 'splitter': '*'},预约结果shang*hai
    test_parametrize.py ✓✓✓✓ 36% ███▋ 测试数据:{'chars': '上海', 'splitter': ''},预约结果shanghai
    test_parametrize.py ✓✓✓✓✓ 45% ████▋ 测试数据:{'chars': '上海', 'splitter': ' '},预约结果shang hai
    test_parametrize.py ✓✓✓✓✓✓ 55% █████▌ 测试数据:{'chars': '上海', 'splitter': '*', 'tone_marks': 'marks'},预约结果shàng*hǎi
    test_parametrize.py ✓✓✓✓✓✓✓ 64% ██████▍ 测试数据:{'chars': '上海', 'splitter': '*', 'tone_marks': 'numbers'},预约结果shang4*hai3
    test_parametrize.py ✓✓✓✓✓✓✓✓ 73% ███████▍ 测试数据:{'chars': '上海', 'splitter': '*', 'tone_marks': 'marks', 'convert': 'capitalize'},预约结果Shàng*Hǎi
    test_parametrize.py ✓✓✓✓✓✓✓✓✓ 82% ████████▎ 测试数据:{'chars': '上海', 'splitter': '*', 'tone_marks': 'numbers', 'convert': 'upper'},预约结果SHANG4*HAI3
    test_parametrize.py ✓✓✓✓✓✓✓✓✓✓ 91% █████████▏测试结束
    test_parametrize.py ✓✓✓✓✓✓✓✓✓✓✓ 100% ██████████

    Results (0.19s):
    11 passed

  • 数据驱动

    测试用例

    testng.xml配置

    测试报告

  • 作业1:提取系统state连接种类
    命令: netstat -ntp| awk '{print $6}' | sort |uniq
    结果:
    CLOSE_WAIT
    ESTABLISHED
    Foreign

    作业2:testerhome某一精华贴任意一回复贴的数量
    命令:ids=`curl -s https://testerhome.com/ | grep -o 'href="/topics/[0-8]"' | awk -F '\"' '{print $2};for id in $ids;do url=https ://testerhome.com/$id;result=curl -s $url | grep -o -m1 '[0-9]'| awk -F '<|>' '{print $3}'`;echo "$url 共收到$result 条回复";done
    结果:
    https://testerhome.com//topics/17281 共收到5 条回复
    https://testerhome.com//topics/17200 共收到42 条回复
    https://testerhome.com//topics/17218 共收到2 条回复
    https://testerhome.com//topics/17285 共收到4 条回复
    https://testerhome.com//topics/17251 共收到6 条回复
    https://testerhome.com//topics/17117 共收到12 条回复
    https://testerhome.com//topics/17066 共收到8 条回复
    https://testerhome.com//topics/16556 共收到38 条回复
    https://testerhome.com//topics/16376 共收到36 条回复
    https://testerhome.com//topics/17068 共收到24 条回复
    https://testerhome.com//topics/17004 共收到16 条回复
    https://testerhome.com//topics/16605 共收到10 条回复
    https://testerhome.com//topics/16436 共收到19 条回复
    https://testerhome.com//topics/16354 共收到92 条回复
    https://testerhome.com//topics/17223 共收到76 条回复
    https://testerhome.com//topics/17205 共收到44 条回复
    https://testerhome.com//topics/17261 共收到22 条回复
    https://testerhome.com//topics/17208 共收到21 条回复
    https://testerhome.com//topics/17244 共收到17 条回复
    https://testerhome.com//topics/17207 共收到16 条回复
    https://testerhome.com//topics/17280 共收到15 条回复
    https://testerhome.com//topics/17266 共收到15 条回复
    https://testerhome.com//topics/17277 共收到13 条回复
    https://testerhome.com//topics/17248 共收到1 条回复
    https://testerhome.com//topics/17220 共收到0 条回复
    https://testerhome.com//topics/17217 共收到1 条回复
    https://testerhome.com//topics/17211 共收到0 条回复