自动化测试工具 Selenium 实际案例

使用 Selenium 登录腾讯开放平台,然后添加区服信息和支付结算:

#!/usr/bin/env python

import os
import time
from selenium import webdriver

chromedriver = "C:\\Users\\37\\AppData\\Local\\Google\\Chrome\\Application\\chromedriver.exe"
os.environ["webdriver.chrome.driver"] = chromedriver
driver = webdriver.Chrome(chromedriver)

# 自定义区服范围
server_range = range(169, 172)

# 登录
driver.get("http://open.qq.com/login")
driver.switch_to.frame("login_frame")
driver.find_element_by_xpath('//span[@id="img_out_xxxxxxxxx"]').click()    //指定使用哪个QQ登录
time.sleep(5)

# 获取并保存cookies信息
cookies = driver.get_cookies()
for cookie in cookies:
    driver.add_cookie(cookie)

# 添加新服
for i in server_range:
    driver.get("http://wlop.ieodopen.qq.com/AddNewNode.php?iAppId=xxxxxx&iDirId=xxxxxx&sName= 公测{0}服".format(i))   //指定AppId、iDirId、区服名
    time.sleep(2)

# 启动新服
driver.get("http://op.open.qq.com/index.php?mod=appinfo&act=main&appid=xxxxxx#area")
time.sleep(3)
driver.switch_to.frame("frame")
driver.find_element_by_xpath('//div[@class="area-manage-button"]//a').click()
time.sleep(3)
driver.find_element_by_id("stopRegOptBtn_67").click()
driver.refresh()
time.sleep(3)
driver.switch_to.frame("frame")
driver.find_element_by_xpath('//div[@class="area-manage-button"]//a').click()
time.sleep(3)
driver.find_element_by_id("startRegOptBtn_67").click()

# 添加支付结算
for i in server_range:
    driver.get("http://op.open.qq.com/index.php?mod=appinfo&act=main&appid=xxxxxx#pay")
    time.sleep(5)
    driver.switch_to.frame("frame")
    driver.find_element_by_xpath('//h2[@class="h_title"]//span//a').click()
    time.sleep(5)
    driver.find_element_by_id("txtSandZoneID").send_keys(i)
    driver.find_element_by_id("txtSandZoneName").send_keys(i)
    driver.find_element_by_id("txtSandProvideServerNameList").click()
    driver.find_element_by_id("fwq_2").click()
    driver.find_element_by_id("fwq_3").click()
    driver.find_element_by_xpath('//div[@id="ssC_frmbtn"]//input[@value="确定"]').click()
    driver.find_element_by_id("txtSandMpServerNameList").click()
    driver.find_element_by_id("fwq_2").click()
    driver.find_element_by_xpath('//div[@id="ssC_frmbtn"]//input[@value="确定"]').click()
    driver.find_element_by_id("txtSandMarketServerNameList").click()
    driver.find_element_by_id("fwq_2").click()
    driver.find_element_by_xpath('//div[@id="ssC_frmbtn"]//input[@value="确定"]').click()
    driver.find_element_by_xpath('//td//button[@onclick="doAdd(0)"]').click()

# 关闭浏览器
time.sleep(10)
driver.quit()

      

猜你喜欢

转载自www.cnblogs.com/pzk7788/p/9134659.html
今日推荐