zoukankan      html  css  js  c++  java
  • 写了一个线性的自动化脚本01

    我觉得我我代码没有优化,先写出线性脚本,功能至少先实现了再说

    import unittest
    from time import sleep

    import self as self
    from selenium import webdriver
    from selenium.webdriver.common.by import By

    driver = webdriver.Chrome()
    driver.maximize_window()
    driver.get("https://demo.identityserver.io/Account/Login")
    sleep(1)
    driver.find_element_by_xpath("//input[@id='Username']").send_keys("bob")
    sleep(1)
    driver.find_element_by_xpath("//input[@id='Password']").send_keys("bob")
    driver.find_element_by_xpath("//button[@class='btn btn-primary']").click()
    sleep(1)
    # enter into user profile and click the Here link
    driver.find_element_by_xpath("//div[@Class='welcome-page']/ul/li[2]/a").click()
    # 1do assertion sub
    subResult = driver.find_element_by_css_selector("body > div.container.body-container > div > div.row > div:nth-child(1) > div > div.card-body > dl > dt:nth-child(1)").text
    print(subResult)
    assert u"sub" in subResult
    try:
    assert u"sub" in subResult
    print('Assertion test pass.')
    except Exception as e:
    print('Assertion test Fail.',format(e))

    # 2do assertion name
    nameResult = driver.find_element_by_css_selector("body > div.container.body-container > div > div.row > div:nth-child(1) > div > div.card-body > dl > dt:nth-child(3)").text
    print(nameResult)
    assert u"name" in nameResult
    try:
    assert u"name" in nameResult
    print('Assertion test pass.')
    except Exception as e:
    print('Assertion test Fail.',format(e))

    # 3do assertion idp
    idpResult = driver.find_element_by_css_selector("body > div.container.body-container > div > div.row > div:nth-child(1) > div > div.card-body > dl > dt:nth-child(5)").text
    print(idpResult)
    assert u"idp" in idpResult
    try:
    assert u"idp" in idpResult
    print('Assertion test pass.')
    except Exception as e:
    print('Assertion test Fail.',format(e))

    # 4 do assertion amr
    amrResult = driver.find_element_by_css_selector("body > div.container.body-container > div > div.row > div:nth-child(1) > div > div.card-body > dl > dt:nth-child(7)").text
    print(amrResult)
    assert u"amr" in amrResult
    try:
    assert u"amr" in amrResult
    print('Assertion test pass.')
    except Exception as e:
    print('Assertion test Fail.',format(e))

  • 相关阅读:
    在 ubuntu20 上安装 docker
    在 ubuntu20 上替换原有的源,解决下载软件慢的问题
    thymeleaf 模板语法
    对 spring 中默认的 DataSource 创建进行覆盖
    Spring Security OAuth2 笔记(一)
    对 ThreadLocal 的了解(一)
    解决 docker.io 上拉取 images Get https://registry-1.docker.io/v2/: net/http: TLS handshake timeout
    Spring Security Oauth2 使用 token 访问资源服务器出现异常:Invalid token does not contain resource id (oauth2)
    windows 查看被占用的端口信息
    不写注释的程序员-Models
  • 原文地址:https://www.cnblogs.com/JacquelineQA/p/15515776.html
Copyright © 2011-2022 走看看