我觉得我我代码没有优化,先写出线性脚本,功能至少先实现了再说
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))