• 课间作业1

    # 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 TestDefaultSuite():
    def setup_method(self, method):
    self.driver = webdriver.Chrome()
    self.vars = {}

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

    def test_testlink2(self):
    self.driver.get("https://testerhome.com/")
    self.driver.set_window_size(1280, 680)
    self.driver.find_element(By.LINK_TEXT, "社区").click()
    self.driver.find_element(By.CSS_SELECTOR, ".topic-21839 .title > a").click()


    老师帮忙看看,为什么显式等待没起作用,下面代码执行之后报错:element is not attached to the page document

    # 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 TestHogwarts():
    def setup_method(self):
    self.driver = webdriver.Chrome()
    self.driver.get("https://testerhome.com/")
    self.driver.implicitly_wait(5)

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

    def test_hogwarts(self) :
    self.driver.find_element(By.LINK_TEXT, "社团").click()
    # time.sleep(2)

    # 使用link定位
    element=(By.PARTIAL_LINK_TEXT,'霍格沃兹测试学院')
    WebDriverWait(self.driver,10).until(expected_conditions.element_to_be_clickable(element))
    self.driver.find_element(By.PARTIAL_LINK_TEXT,"霍格沃兹测试学院").click()
    # 使用css定位,比link更好用
    # self.driver.find_element(By.CSS_SELECTOR,'[data-name="霍格沃兹测试学院"]').click()
    self.driver.find_element(By.CSS_SELECTOR, ".topic:nth-child(1) .title").click()
    # 不加a也可以
    # self.driver.find_element(By.CSS_SELECTOR, ".topic:nth-child(1) .title a").click()

    课间作业2

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

    class TestSeleniumDemo1():
    def setup_method(self):
    self.driver = webdriver.Chrome()
    self.driver.get("https://testerhome.com/")
    self.driver.implicitly_wait(5)

    def test_seleniumdemo1(self):
    self.driver.find_element(By.CSS_SELECTOR,'[title="MTSC2020 中国互联网测试开发大会议题征集"]').click()
    self.driver.find_element(By.CSS_SELECTOR,'.toc-container > .btn').click()
    self.driver.find_element(By.CSS_SELECTOR,'.toc-item:nth-child(4) > .toc-item-link').click()

    def teardown_method(self):
    time.sleep(3)
    self.driver.quit()
  • 十一期_Python 测试_20191222 at December 22, 2019

    课后作业

    import pytest
    def div(a, b):
    return a/b
    @pytest.mark.parametrize("num1,num2,expection",{
    (4,2,2),
    (0,3,0),
    (1,2,0.5),
    (100000000,1,100000000),
    (-1,2,-0.5),
    (2,-1,-2),
    (-9,-9,1)
    })
    def test_div_int(num1,num2,expection):
    assert div(num1,num2) == expection

    @pytest.mark.parametrize("num1,num2,expection",{
    (0.4,2,0.2),
    (10,0.1,100),
    (-1.5,1,-1.5),
    (100000000,-2,-50000000),
    })
    def test_div_float(num1,num2,expection):
    assert div(num1,num2) == expection

  • 十一期_Python 测试_20191222 at December 22, 2019

    课间作业

    import pytest
    def div(a, b):
    return a/b
    def test_div():
    assert div(4,2) == 2
    assert div(0,3) == 0
    assert div(1,2) == 0.5
    assert div(8,0.1) == 80
    assert div(0.8,2) == 0.4
    assert div(-1,1) == -1
    assert div(-1,-1) == 1
    assert div(1000000,2.5) == 40000
    assert div(10,3) == 3.3333333333333335
    assert div(9,0)
    assert div('123',1)
    assert div(12,'122')

    课后作业
    版本1

    import pytest

    from unit.Div import div

    @pytest.mark.parametrize("num1,num2,expection", {
    (4, 2, 2),
    (0, 3, 0),
    (1, 2, 0.5),
    (100000000, 1, 100000000),
    (-1, 2, -0.5),
    (2, -1, -2),
    (-9, -9, 1)
    })
    def test_div_int(num1, num2, expection):
    assert div(num1, num2) == expection

    @pytest.mark.parametrize("num1,num2,expection", {
    (0.4, 2, 0.2),
    (10, 0.1, 100),
    (-1.5, 1, -1.5),
    (100000000, -2, -50000000),
    })
    def test_div_float(num1, num2, expection):
    assert div(num1, num2) == expection

    @pytest.mark.parametrize("num1,num2,expection", [
    (1, "a", "error"),
    ("a", 2, "error"),
    ("a", "b", "error"),

    ])
    def test_div_string(num1,num2,expection):
    assert div(num1, num2) == expection


    # 测试异常情况,如除数为0
    @pytest.mark.parametrize("num1,num2,expection", [
    (1, 0, "error")
    ])
    def test_div_exception(num1, num2, expection):
    assert div(num1, num2) == expection

    版本2

    import pytest

    from unit.Div import div
    data1 = [ [4, 2, 2],
    [0, 3, 0],
    [1, 2, 0.5],
    [100000000, 1, 100000000],
    [-1, 2, -0.5],
    [2, -1, -2],
    [-9, -9, 1]
    ]

    @pytest.mark.parametrize("num1,num2,expection",data1)
    def test_div_int(num1, num2, expection):
    assert div(num1, num2) == expection

    @pytest.mark.parametrize("num1,num2,expection", {
    (0.4, 2, 0.2),
    (10, 0.1, 100),
    (-1.5, 1, -1.5),
    (100000000, -2, -50000000),
    })
    def test_div_float(num1, num2, expection):
    assert div(num1, num2) == expection

    @pytest.mark.parametrize("num1,num2,expection", [
    (1, "a", "error"),
    ("a", 2, "error"),
    ("a", "b", "error"),

    ])
    def test_div_string(num1,num2,expection):
    assert div(num1, num2) == expection


    # 测试异常情况,如除数为0
    @pytest.mark.parametrize("num1,num2,expection", [
    (1, 0, "error")
    ])
    def test_div_exception(num1, num2, expection):
    with pytest.raises(ZeroDivisionError):
    assert div(num1, num2) == expection

  • 课后作业
    1.找出log中的404 500的记录总共有多少条

    grep -w -c -e 404 -e 405 nginx.log

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

    awk '{print$1}' nginx.log |sort |uniq -c |sort -nr


  • 经常这样

  • 课间练习1

    curl 'https://testerhome.com/' |less |grep -o 'href=".*' |wc -l
  • 65和75和83


  • windows电脑也可以像老师那样设置jemter path吗

  • 课间作业

    python
    def test_testhome(self):
    url = "https://testerhome.com/api/v3/topics.json?limit=2"
    r = requests.get(url)
    print(r.json())
    print(r.json()['topics'][0]['id']) #取出响应中的字段
    # assert r.json()['topics'][0]['id'] == 21162 #可以进行断言
    print(r.json()['topics'][1]['user']['login']) #取出响应中的字段

    def test_xueqiu_search(self):
    url = "https://xueqiu.com/statuses/search.json?sort=relevance&source=all&q=sogo&count=10&page=1"
    headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36"
    }
    cookies = {"xq_r_token":"2b9912fb63f07c0f11e94985018ad64e78cca498",
    "xq_a_token":"87993a504d5d350e6271c337ad8e9ec8809acb79"
    }
    r = requests.get(url, cookies=cookies, headers=headers)
    print(r.json())
    print(r.json()['list'][0]['user']['screen_name'])
  • 作业3
    限速3G