• 问题求教

    关于send_keys()输入字符串的问题?
    打开的是一个electron的win桌面应用

    options = webdriver.ChromeOptions()
    options.add_argument("--remote-debugging-port=9222")
    options.set_capability('platform', 'WINDOWS')
    options.set_capability('version', '10')
    options.binary_location = app_path
    driver = webdriver.Chrome(options=options)

    driver.delete_all_cookies()

    user = app.find_element_by_css_selector('#user-mobile')
    app.execute_script('document.querySelector("#user-mobile").value="";')
    user.send_keys('12333333456')

    代码输入的与实际输入的内容不符,会少一些;使用了PyKeyboard.type_string()也会这样;只能一个一个字符输入。
    应该不是selenium的问题,但找不出具体原因来,不知道老师知不知道是什么原因。

  • 课间作业1

    from selenium import webdriver

    class TestSelenium:

    @classmethod
    def setup_class(cls):
    cls.driver = webdriver.Chrome()

    @classmethod
    def teardown_class(cls):
    cls.driver.quit()

    def test_testerhome(self):
    self.driver.get('https://testerhome.com')

    teams = self.driver.find_element_by_link_text('社团')
    teams.click()

    hogwarts = self.driver.find_element_by_link_text('霍格沃兹测试学院')
    hogwarts.click()

    topics = self.driver.find_elements_by_xpath('//div[@class="panel-body"]/a[contains(@href, "/topics")]')
    topics[0].click()

    课间作业2

    def test_2(self):
    self.driver.get('https://testerhome.com')

    topic_element = self.driver.find_element_by_css_selector('a[title="MTSC2020 中国互联网测试开发大会议题征集"]')
    topic_element.click()

    dir_btn_element = self.driver.find_element_by_css_selector('.toc-container button')
    dir_btn_element.click()

    time.sleep(3)
    element = self.driver.find_element_by_xpath('//li[contains(@class,"toc-item")]/a[text()="征集议题范围"]')
    element.click()

    课后作业3

    import os
    import sys
    import yaml
    from selenium import webdriver
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    from selenium.webdriver.common.by import By


    project_dir = os.getcwd()
    sys.path.append(project_dir)
    with open(project_dir + r'\test_selenium.yml', 'rb') as f:
    config = yaml.load(f, Loader=yaml.FullLoader)


    class TestSelenium:
    def setup_class(self):
    options = webdriver.ChromeOptions()
    # close all chrome window, and cmd: chrome.exe --remote-debugging-port=9222
    # options.debugger_address = config['debugger_address']
    self.driver = webdriver.Chrome(options=options)

    self.driver.implicitly_wait(5)

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

    def wait_element(self, timeout, method):
    return WebDriverWait(self.driver, timeout=timeout).until(method)

    def element(self, by, value):
    if by == 'css_selector':
    return self.driver.find_element_by_css_selector(value)
    elif by == 'xpath':
    return self.driver.find_element_by_xpath(value)
    else:
    raise BaseException('no such find element method [%s]' % by)

    def login_work_wexin(self):
    work_wexin = config['test_work_wexin']
    cookies = work_wexin['cookies']
    login_url = work_wexin['wexin_login']

    # open work.wexin
    self.driver.get(login_url)

    # cookies = self.driver.get_cookies()
    # {
    # 'domain': cookie['domain'],
    # 'name': cookie['name'],
    # 'value': cookie['value'],
    # 'path': '/',
    # 'expires': None
    # }

    # use cookies login
    self.driver.delete_all_cookies()
    for cookie in cookies:
    self.driver.add_cookie(cookie)

    self.driver.refresh()

    # @pytest.mark.parametrize('member', config['test_work_wexin']['add_member']) # 若使用参数化则不用for循环,但每次都需要重新打开一次urladd页面
    def test_work_wexin_add_member(self):
    # login work wexin
    self.login_work_wexin()

    members = config['test_work_wexin']['add_member']

    # add member page
    self.driver.find_element_by_css_selector('[node-type="addmember"]').click()

    # write member info
    last_member_index = len(members) - 1
    for index, member in enumerate(members):
    self.element('css_selector', '#username').send_keys(member['name'])
    self.element('css_selector', '#memberAdd_acctid').send_keys(member['id'])
    self.element('css_selector', 'input[name="gender"][value="%s"]' % member['gender']).click()
    self.element('css_selector', '#memberAdd_phone').send_keys(member['mobile'])
    self.element('css_selector', '#memberEdit_address').send_keys(member['address'])
    self.element('css_selector', '#memberAdd_title').send_keys(member['title'])

    # save member
    if last_member_index != index:
    save = EC.element_to_be_clickable((By.XPATH, '//div[contains(@class,"member_colRight_operationBar")]/a[text()="保存并继续添加"]'))
    else:
    save = EC.element_to_be_clickable((By.XPATH, '//div[contains(@class,"member_colRight_operationBar")]/a[text()="保存"]'))
    self.wait_element(10, save).click()

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

    课后作业2

    import os
    import pytest
    import shutil
    import subprocess
    import logging


    logging.basicConfig(level=logging.DEBUG)
    log = logging.getLogger('TestDiv')


    def div(a, b):
    return a/b


    def teardown_module(module):
    '''generate allure report'''
    log.info('\n-------tear down generate report-------\n')

    if os.path.exists('unit/report/allure_html'):
    shutil.rmtree('unit/report/allure_html')

    build_html_cmd = 'allure generate unit/report/allure_results/ -o unit/report/allure_html'
    build_open_cmd = 'allure serve unit/report/allure_results/'

    build_html = subprocess.Popen(build_open_cmd, shell=True, stdout=subprocess.PIPE)
    build_html.wait()


    class TestDiv:

    @pytest.mark.p0
    @pytest.mark.parametrize('a, b, expected', [
    (2, 1, 2),
    (1, 2, 0.5),
    (3, 9, 0.334),
    (-1, -2, 0.5),
    (2147483647, 2, 1073741823.5),
    (-2147483648, -2, 1073741824.0),
    ])
    def test_type_int(self, a, b, expected):
    '''
    test Integer division
    '''
    assert div(a, b) == expected

    @pytest.mark.p0
    @pytest.mark.parametrize('a, b, expected', [
    (1.5, 1, 1.5),
    (2, 0.5, 4),
    (2.25, 0.5, 4.5),
    (2, -0.5, -4),
    (1.7976931348623157e+308, 2, 8.988465674311579e+307),
    (2.2250738585072014e-308, -1, -2.2250738585072014e-308),
    ])
    def test_type_float(self, a, b, expected):
    '''
    test division value has float
    '''
    assert div(a, b) == expected

    @pytest.mark.p1
    @pytest.mark.parametrize('a, b', [
    ('2', 1),
    ('a', 5),
    (2, (1,)),
    ([2], 5),
    (5, {'a': 1}),
    (5, None),
    (False, 5),
    (2, True),
    ])
    def test_type_error(self, a, b):
    '''
    test division value has type not digital
    '''
    with pytest.raises(TypeError):
    div(a, b)

    @pytest.mark.p1
    @pytest.mark.parametrize('a, b', [
    (2, 0)
    ])
    def test_dividend_zero(self, a, b):
    '''
    test divisor of 0
    '''
    with pytest.raises(ZeroDivisionError):
    div(a, b)

    @pytest.mark.p2
    @pytest.mark.parametrize('a, b', [
    (2, 2147483648),
    (-2147483649, -2),
    (2, 1.7976931348623157e+307),
    (-2, 2.2250738585072014e-309),
    ])
    def test_over_digital_length(self, a, b):
    '''
    test int and float over max/min length
    '''
    assert div(a, b) is None

    allure报告

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

    课件作业1

    def test_div():
    a = 1.5
    b = 2

    assert a/b == div(a, b)

    def test_div_more():
    for x in range(10):
    a = x
    b = x + 1
    assert a/b == div(a, b)
  • 1.jvmPath没有问题;
    2.路径我换成了绝对路径;
    3.用这种方式加绝对路径就成功了!
    太感谢啦!,不过为什么使用startJVM(jvmpath=jvmPath, classpath="-Djava.class.path=test.jar", convertStrings=False),参数带key的方式就会失败呢?

  • get👏 就是这个时间机票正好上涨>_<

  • 直接java -jar运行这个jar包是可以的,jdk版本也是一致的,META-INF里面

    Manifest-Version: 1.0
    Created-By: 1.8.0_66 (Oracle Corporation)
    Main-Class: test.test

    应该也是没有问题的;
    我还试了另外一个可以在jmeter里面用的jar包,不过META-INF里面没有jdk版本号,也不行;

    META-INF这个东西不太懂,里面需要什么一定有的东西吗

  • 谢谢回复,不过这个也试过了不行

  • 你是说JClass("test.test")还是JPackage('test')?我都试过没有用😂

  • 课后作业

    1.统计404、500记录

    awk 'BRGIN{FS=" ";RS="\n";count_a=0;count_b=0}{if ($9==404)count_a++;else if ($9==500)count_b++;}END{print "code  count\n""404   " count_a "\n500   " count_b "\n\ntotal: "count_a+count_b}' nginx.log
    code  count
    404 266
    500 1

    total: 267

    2.访问量最高ip前三

    awk '{ip_count[$1]++;}END{for (c in ip_count)print c"  "ip_count[c]}'  nginx.log | sort -r -n -k2 | head -3
    216.244.66.241  282
    136.243.151.90 130
    127.0.0.1 110

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

    awk 'BRGIN{FS=" ";RS="\n";}{print $7}' nginx.log | sed -E 's#\?.*##;s#/[0-9]{3,6}/#/id/#g;s#/[0-9]{3,6}$#/id#g;' | awk '{route[$1]++;}END{for(r in route)print r"  "route[r]}' | sort -rn -k2 |head -10
    /cable  584
    /topics/id 372
    /topics/id/replies/id/edit 147
    / 94
    /topics/id/replies/id/reply_suggest 49
    /topics/id/show_wechat 41
    /topics/id/replies/id/reply_to 25
    /api/v3/topics.json 7
    /account/sign_in 7
    /topics/feed 6