Python实现Selenium自动化Page模式-创新互联
Selenium是当前主流的web自动化工具,提供了多种浏览器的支持(Chrome,Firefox, IE等等),当然大家也可以用自己喜欢的语言(Java,C#,Python等)来写用例,很容易上手。当大家写完第一个自动化用例的时候肯定感觉”哇...好牛x“,但是大家用余光扫了一下代码后,内心也许是崩溃的,因为太乱了!像这样:

__author__ = 'xua'
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import unittest
class TCRepeatLogin(unittest.TestCase):
def setUp(self):
#webdriver
self.driver = webdriver.Chrome(r'C:\Users\xua\Downloads\chromedriver_win32\chromedriver.exe')
self.driver.implicitly_wait(30)
self.base_url = "http://10.222.30.145:9000/"
def test_(self):
driver = self.driver
driver.get(self.base_url)
#enter username and password
driver.find_element_by_id("username").clear()
driver.find_element_by_id("username").send_keys("sbxadmin")
driver.find_element_by_id("password").clear()
driver.find_element_by_id("password").send_keys("IGTtest1"+Keys.RETURN)
#find dialog and check
dialogTitle = driver.find_element(By.XPATH,'//html/body/div[7]/div/div/div[1]/h4')
self.assertEqual("Sign in",dialogTitle.text)
#find cancel button and click
cancelBtn = driver.find_element(By.XPATH,'//html/body/div[7]/div/div/div[3]/button[2]')
cancelBtn.click()
def tearDown(self):
self.driver.close()
if __name__ == "__main__":
unittest.main()另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
名称栏目:Python实现Selenium自动化Page模式-创新互联
网址分享:http://www.jxjierui.cn/article/csshjp.html


咨询
建站咨询
