• 在搭建一个简单的po框架,有什么方法吗?我自己是先写两个页面测试,提取公共部分。在把用例,和页面分开。我感觉这个方法好像不太行。😬😬

  • ###作业1

    # coding=utf-8
    from time import sleep

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


    class TestUplod():
    def setup_method(self):
    chromeOptions = Options()
    chromeOptions.add_experimental_option("debuggerAddress", "127.0.0.1:9222")
    self.driver = webdriver.Chrome(options=chromeOptions)
    self.driver.implicitly_wait(10)

    def test_uplod(self):
    # <div class="manageTools_cnt_item_desc_title"></div>
    WebDriverWait(self.driver, 10).until(expected_conditions.element_to_be_clickable((By.ID, 'menu_manageTools')))
    self.driver.find_element(By.ID, 'menu_manageTools').click()
    self.driver.find_element(By.PARTIAL_LINK_TEXT, '可将重要常用的素材存放在此').click()
    self.driver.find_element(By.LINK_TEXT, '图片').click()
    self.driver.find_element(By.LINK_TEXT, '添加图片').click()
    self.driver.find_element(By.ID, 'js_upload_input').send_keys(
    r'D:\pychartest\Hogwarts11\selenium11\file\_20200211224832.png')
    size = self.driver.find_element(By.CSS_SELECTOR, '.js_pic_preview_item')
    if (size):
    self.driver.find_element(By.LINK_TEXT, '完成').click()
    else:
    sleep(10)
    self.driver.find_element(By.LINK_TEXT, '完成').click()

  • 课间作业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 TestAaaaa():
    def setup_method(self, method):
    self.driver = webdriver.Firefox()
    self.vars = {}

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

    def test_aaaaa(self):
    self.driver.get("https://testerhome.com/")
    self.driver.set_window_size(1095, 728)
    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()


    可见作业二

    # coding=utf-8
    from selenium.webdriver.common.by import By
    from selenium import webdriver
    from selenium.webdriver.support import expected_conditions
    from selenium.webdriver.support.wait import WebDriverWait


    class TestTop:
    def setup_method(self):
    self.driver = webdriver.Firefox()
    self.driver.get("https://testerhome.com/")
    self.wait = WebDriverWait(self.driver, 10)

    def test_top(self):
    self.driver.find_element_by_link_text('社团')
    self.driver.find_element(By.CSS_SELECTOR, '[title~="MTSC2020"]').click()
    element1 = (By.CSS_SELECTOR, '.toc-container > .btn')
    WebDriverWait(self.driver, 10).until(expected_conditions.presence_of_element_located(element1))
    self.driver.find_element_by_css_selector('.toc-container > .btn').click()
    element2 = (By.LINK_TEXT, '征集议题范围')
    WebDriverWait(self.driver, 10).until(expected_conditions.element_to_be_clickable(element2))
    self.driver.find_element(*element2).click()
    # self.driver.find_element_by_link_text("征集议题范围").click()

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

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

    ##课间作业1

    import pytest

    from hogwarts11.pytest.div import div


    def test_answer5(): # 只是一个方法的话方法名字后面直接跟括号即可。
    assert div("", 3)


    def test_answer6():
    assert div('a', 'b')


    class Test_answer: # 这个是一个类名,如果加一个类,下面的方法括号里面需要加上self
    @pytest.mark.happy
    def test_answer1(self):
    assert div(1, 5) == 0.2

    @pytest.mark.happy
    def test_answer2(self):
    assert div(10, 5) == 2

    @pytest.mark.happy
    def test_answer3(self):
    assert div(0, 1) == 0

    @pytest.mark.sed
    def test_answer4(self):
    assert div(1, 0)

    def test_answer5(self):
    assert div(2.4, 0.000012) == 20000

    def test_answer6(self):
    assert div(100000000, 2) == 50000000

    def test_answer7(self):
    assert div(2, -1) == -2

    def test_answer8(self):
    assert div(4, 22) == 0.1818181818181818

    ##课后作业2

    class TestClass2:

    @pytest.mark.parametrize("number1, number2, expection", {
    (10, 2, 5),
    (10000000, 1, 1000000),
    (10, 3, 3.333),
    (0, 1, 1),
    (2, 0, 'none'),
    (2, -1, -2),
    ('a', 2, 'none'),
    (2, 'a', 'none'),
    (' ', 2, 'none'),
    (2, ' ', 'none')
    })
    def test_div_ans(self, number1, number2, expection): # 所有方法写在类里面的话,第一个参数要是 self,否则会报错。如果直接是方法,
    assert div(number1, number2) == expection # 那么第一个参数就不用是self

  • 课间作业1

    curl 'https://testerhome.com/' | grep -E '^ *<a title.*(topics|articles).*[^>]a>$' | wc -l
           % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
    Dload Upload Total Spent Left Speed
    100 52285 0 52285 0 0 218k 0 --:--:-- --:--:-- --:--:-- 219k
    30

    课件作业2

    less test.txt | grep -o '[0-9, ]*条结果' | awk -F '{print $1}' | sed 's#,##g' | sed -E 's#[0]{4,4} #W#'

    ##课间作业3
    统计404 和500的访问量

    less nginx.log | grep -E '.*HTTP/1.1" (404|500).*' | wc -l

    访问量前三的ip

    less nginx.log | awk -F" " '{print $1}'| sort  | uniq -c | sort -rn | head -n3

    utl前10

    less nginx.log | awk -F" " '{print$7}' |  sed "s#\/[0-9].*#/id#" | sort | uniq -c | sort -rn | head -n10

    答案

    635 /topics/id
    584 /cable
    94 /
    62 /uploads/user/avatar/id
    61 /uploads/photo/id
    55 /_img/uploads/user/avatar/id
    55 /_img/uploads/photo/id
    18 /id
    11 /photo/id
    8 /api/v3/topics/id