学习地址:参考https://blog.youkuaiyun.com/qq_30975321/article/details/77622363 系列
webbrowser的使用
import webbrowser as web
web.open('https://www.baidu.com')
选用自定义的浏览器
chromepath = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
web.register('chrome',None,web.BackgroundBrowser(chromepath))
web.get('chrome').open('https://www.baidu.com')
webbrowser的其他特性:
webbrowser.open(url,new=0,autoraise=True)
-
url
代表要打开的网址 -
new
即打开网址的方式:new=0
:在当前窗口打开网址new=1
:在新浏览器窗口打开new=2
:在当前浏览器的新tab打开
selenium:
#coding:utf-8
'''
Created on 2018年8月6日
@author: linhuajian
'''
from selenium import webdriver
import unittest
from HTMLTestRunner import HTMLTestRunner
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import time
from selenium.webdriver.common.action_chains import ActionChains
class nova(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Chrome()
self.url = "http://care.novaicare.com"
def iscunzai(self):
driver=self.driver
try:
driver.find_element_by_xpath('//*[@id="lableTable"]/tbody/tr[7]/td[2]/a')
return True
except:
return False
def xiansp(self):
u'''埋点自动化测试报告:显示屏列表'''
#登录模块
driver=self.driver
driver.get(self.url)
self.driver.maximize_window()
driver.implicitly_wait(20)
driver.find_element_by_xpath('//*[@id="username"]').clear()
driver.find_element_by_xpath('//*[@id="username"]').send_keys("linhuajian")
driver.find_element_by_xpath('//*[@id="password"]').clear()
driver.find_element_by_xpath('//*[@id="password"]').send_keys("123456")
driver.find_element_by_xpath('//*[@id="loginform"]/button').click()
time.sleep(1)
time.sleep(1)
driver.find_element_by_xpath('/html/body/div[16]/div/div[5]/a[1]').click()
#点击百宝箱
time.sleep(3)
above=driver.find_element_by_xpath('//*[@id="app"]')
ActionChains(driver).move_to_element(above).perform()
#点击显示屏列表
driver.find_element_by_xpath('//*[@id="moreAPPs"]/ul[3]/li[1]/a').click()
###############显示等等
time.sleep(3)
WebDriverWait(driver,10,0.5).until(EC.presence_of_element_located((By.XPATH,'//*[@id="all"]')))
driver.find_element_by_xpath('//*[@id="lableTable"]/tbody/tr[7]/th/input').click()
#选中进行批量编辑
#driver.find_element_by_xpath('//*[@id="all"]').click()
time.sleep(1)
if self.iscunzai():
print 'Exist'
#点击批量删除
#driver.find_element_by_xpath('//*[@id="delete-lable"] ').click()
driver.find_element_by_xpath('//*[@id="delete-lable"]').click()
time.sleep(1)
driver.find_element_by_xpath('//*[@id="myName"]/div/div/div[3]/button[1]').click()
if self.iscunzai():
print 'successfully delete'
#点击取消
#driver.find_element_by_xpath('//*[@id="myName"]/div/div/div[3]/button[2]').click()
#点击显示屏com4
#driver.find_element_by_xpath('//*[@id="lableTable"]/tbody/tr[2]/td[2]/a').click()
def tearDown(self):
self.driver.quit()
if __name__ == "__main__":
testunit=unittest.TestSuite()
testunit.addTest(nova("xiansp"))
fp=open('F:\\result.html','wb')
runner=HTMLTestRunner(stream=fp,
title=u'测试报告',
description=u'自动化测试报告:')
runner.run(testunit)
print 'OK'
fp.close()