import argparse
import logging
import psycopg2
import datetime,time
import os,sys
from selenium import webdriver
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support.ui import Select
from concurrent import futures logging.basicConfig(level=logging.INFO, format='%(asctime)s-[%(filename)s:%(lineno)s]-[%(threadName)s]- %(message)s',datefmt='%a, %d %b %Y %H:%M:%S')
pool = futures.ThreadPoolExecutor(max_workers=10)
WAIT_TIME=30 def query_postgres(all_args,sql):
pg_conn=None
try:
pg_conn = psycopg2.connect(database=all_args.database, user=all_args.user, password=all_args.password, host=all_args.host, port=all_args.port)
cur = pg_conn.cursor()
cur.execute(sql)
return cur.fetchall()
except Exception as e:
logging.error("Query Postgresql Failed , %s",e)
finally:
if pg_conn:
pg_conn.close() def get_org_user_list(all_args):
if not all_args.org:
orgIds=[r[0] for r in query_postgres(all_args,"""select (info->>'_id') as orgId from "sxacc-organizations" ;""")]
else:
orgIds=all_args.org.split(',')
#logging.info("Need Verify Orgs: %s",orgIds)
sql="select username,organization_id from calixuser where organization_id in ("+(','.join(r for r in orgIds))+") and (username like 'mig-admin@%' or username like 'implementation@%'); "
result=[]
org_map={}
for r in query_postgres(all_args,sql):
if not org_map.has_key(r[1]):
result.append({"orgId":str(r[1]),"username":r[0],"password":("Migration%s"%r[1] if str(r[0]).startswith("mig-admin") else "Impl%s"%r[1])})
org_map[r[1]]=r[0]
return result def screen_shapshoot(driver,orgId,name,str_date):
screen_dir=os.path.join("screen",str_date)
if not os.path.isdir("screen"):
os.mkdir("screen")
if not os.path.isdir(screen_dir):
os.mkdir(screen_dir)
screen_dir=os.path.join("screen",str_date,str(orgId))
if not os.path.isdir(screen_dir):
os.mkdir(screen_dir)
file_name=os.path.join(screen_dir,"%s.png"%(name))
driver.get_screenshot_as_file(file_name) def get_call_adv_reports(driver,orgId,str_date):
driver.get("https://xxx/support/")
locator = (By.ID, "netops")
WebDriverWait(driver, WAIT_TIME).until(EC.presence_of_element_located(locator))
time.sleep(5)
try:
driver.find_element_by_id('reportops').click()
i=0
for s in driver.find_elements_by_class_name('report-summary'):
name=driver.find_elements_by_class_name('name')[i].text
s.click()
time.sleep(10)
screen_shapshoot(driver,orgId,'call_adv_%s'%str(name).lstrip(),str_date)
i+=1
except Exception as e:
logging.error("call adv error, %s",e)
logging.error("org %s has no call adv report",orgId) def get_checked_device(driver,orgId,str_date):
driver.find_element_by_id('netops').click()
driver.find_element_by_id('deviceReports').click()
s1=Select(driver.find_element_by_id('device_report_type'))
s1.select_by_value("checkInDeviceReport")
s2=Select(driver.find_element_by_id('time_period'))
s2.select_by_value("1")
driver.find_element_by_id('query-report-btn').click()
locator = (By.TAG_NAME, "th")
WebDriverWait(driver, WAIT_TIME).until(EC.presence_of_element_located(locator))
screen_shapshoot(driver,orgId,"DeviceReportList",str_date)
sn=driver.find_element_by_class_name('serialnumber').text
driver.get("https://xxx/support/cpe-troubleshooting?serialNumber=%s"%sn)
locator=(By.CLASS_NAME,"table-responsive")
WebDriverWait(driver,WAIT_TIME).until(EC.presence_of_element_located(locator))
locator=(By.CLASS_NAME,"fa-spinner")
WebDriverWait(driver,WAIT_TIME).until_not(EC.presence_of_element_located(locator))
time.sleep(5)
screen_shapshoot(driver,orgId,'cpeTroubleshooting',str_date)
driver.find_element_by_id('ccl_support_smartcheck_tab').click()
locator=(By.CLASS_NAME,"smartcheck-btn-details")
WebDriverWait(driver,WAIT_TIME).until(EC.presence_of_element_located(locator))
locator=(By.CLASS_NAME,"fa-spinner")
WebDriverWait(driver,WAIT_TIME).until_not(EC.presence_of_element_located(locator))
try:
for s in driver.find_elements_by_class_name('refresh'):
s.click()
time.sleep(5)
time.sleep(10)
locator=(By.CLASS_NAME,"fa-spinner")
WebDriverWait(driver,WAIT_TIME).until_not(EC.presence_of_element_located(locator))
screen_shapshoot(driver,orgId,'smartcheck',str_date)
for i in range(0,4):
print driver.find_elements_by_class_name('type')[i].text
if i<3:
driver.find_elements_by_class_name('smartcheck-btn-details')[i].click()
else:
driver.find_elements_by_class_name('smartcheck-btn-details')[2].click()
time.sleep(10)
screen_shapshoot(driver,orgId,'smartcheck_%s'%str(driver.find_elements_by_class_name('type')[i].text).lstrip(),str_date)
driver.find_element_by_id("detail-close").click()
except Exception as e:
logging.error("refresh smart check failed,%s",e) def verify_csc_details(driver,orgId,str_date):
get_checked_device(driver,orgId,str_date)
get_call_adv_reports(driver,orgId,str_date) def close_terms_of_service_page(driver):
try:
driver.find_element_by_class_name('close').click()
except Exception as e:
logging.error("Close Button not exists") def test_cmc_functions(driver,orgId,str_date):
driver.get("https://xxx/marketing/insights")
WebDriverWait(driver, WAIT_TIME).until(EC.title_contains("Marketing"))
close_terms_of_service_page(driver)
time.sleep(5)
for item in ['past_28_days','past_month','past_2_months']:
driver.find_element_by_id(item).click()
time.sleep(10)
screen_shapshoot(driver,orgId,'cmc_insights_%s'%item,str_date)
return def test_cloud_login(orgId,username,password,str_date,driver):
driver.get("https://calixcloud.calix.com/login")
driver.find_element_by_name('userName').send_keys(username)
driver.find_element_by_name('password').send_keys(password)
driver.find_element_by_class_name('btn').click()
try:
WebDriverWait(driver, WAIT_TIME).until(EC.title_contains("Support"))
close_terms_of_service_page(driver)
locator = (By.ID, "netops")
WebDriverWait(driver, WAIT_TIME).until(EC.presence_of_element_located(locator))
screen_shapshoot(driver,orgId,"Login_Success",str_date)
logging.info("org:%s verify Successed",orgId)
except Exception as e:
screen_shapshoot(driver,orgId,"Login_Faild",str_date)
logging.error("Login to org: %s failed , exception: %s",orgId,e)
logging.error("org:%s verify Failed",orgId) def test_cloud(orgId,username,password,str_date):
logging.info("Begin verify org:%s",orgId)
driver = webdriver.Firefox()
#driver = webdriver.Chrome()
try:
test_cloud_login(orgId,username,password,str_date,driver)
verify_csc_details(driver,orgId,str_date)
test_cmc_functions(driver,orgId,str_date)
except Exception as e:
logging.error("test cloud faild :%s",e)
finally:
driver.close()
return def main():
parser = argparse.ArgumentParser()
parser.add_argument('-d', '--database', help='database for postgres', default='postgres')
parser.add_argument('-u', '--user', help='user for postgres', default='postgres')
parser.add_argument('-p', '--password', help='password for postgres', default='postgres')
parser.add_argument('-n', '--host', help='host for postgres', default='127.0.0.1')
parser.add_argument('-P', '--port', help='port for postgres', default='5432')
parser.add_argument('-o', '--org', help="orgs list,split by ,")
all_args = parser.parse_args() pool = futures.ThreadPoolExecutor(max_workers=3)
#driver = webdriver.Firefox()
#all_args.org='7583'
for i in range(1):
str_date=datetime.datetime.now().strftime('%Y_%m_%d_%H_%M_%S')
for r in get_org_user_list(all_args):
#test_csc_functions(r['orgId'],r['username'],r['password'],str_date,driver)
pool.submit(test_cloud,r['orgId'],r['username'],r['password'],str_date)
time.sleep(60) if __name__ == '__main__':
main()

  

利用selenium自动化测试样例一的更多相关文章

  1. 利用Selenium自动化测试android wap页

    http://blogs.360.cn/360qtest/2014/04/01/%E5%88%A9%E7%94%A8selenium%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5% ...

  2. Android利用Volley异步载入数据完整具体演示样例(二)

    MainActivity例如以下: package cc.y; import android.app.Activity; import android.content.Context; import ...

  3. Qt 鼠标样式特效探索样例(一)——利用时间器调用QWidget.move()函数

    Qt 鼠标样式特效探索样例(一)       心血来潮,突然想在Qt里玩一把鼠标样式,想到在浏览网页时,经常看到漂亮的鼠标动画,于是今天摸索着乱写个粗糙的demo,来满足自己的好奇心. 效果图 方案要 ...

  4. 【阿菜做实践】利用go语言写一个简单的Pow样例

    本篇博客的主要内容是用go写一个简单的Proof-of-Work共识机制,不涉及到网络通信环节,只是一个本地的简单demo.开发IDE用的是JB Golang. 整个项目的文件结构如下: PoWdem ...

  5. 利用Selenium自动化web测试

    简介: Selenium 是一个没有正式指导手册的开源项目,这让测试人员的问题调查很费时间.本文为基于 Selenium 1.0(发布于 2009 年 6 月)的测试期间的常见问题提供最佳实践. 简介 ...

  6. [持续交付实践] pipeline使用:项目样例

    项目说明 本文将以一个微服务项目的具体pipeline样例进行脚本编写说明.一条完整的pipeline交付流水线通常会包括代码获取.单元测试.静态检查.打包部署.接口层测试.UI层测试.性能专项测试( ...

  7. Selenium自动化测试框架入门整理

    ​​关注嘉为科技,获取运维新知 本文主要针对Selenium自动化测试框架入门整理,只涉及总体功能及框架要点介绍说明,以及使用前提技术基础要求整理说明.作为开发人员.测试人员入门参考. 本文参考:Se ...

  8. Selenium自动化测试Python五:WebDriver设计模式

    WebDriver 设计模式 欢迎阅读WebDriver进阶讲义.本篇讲义将会重点介绍Selenium WebDriver 自动化框架的设计,着重使用Page Object设计模式,以及使用HTML测 ...

  9. Selenium自动化测试Python一:Selenium入门

    Selenium入门 欢迎阅读Selenium入门讲义,本讲义将会重点介绍Selenium的入门知识以及Selenium的前置知识. 自动化测试的基础 在Selenium的课程以前,我们先回顾一下软件 ...

随机推荐

  1. mybatis xml动态语句写法

    mapper.java: /** * @Description: 根据摄像机Id查询出入记录 * @Param: * name 姓名 * monitorId 布控ID * starttime 开始时间 ...

  2. 在 FR 网络配置 OSPF

    一.环境准备 1. 软件:GNS3 2. 路由:c7200 二.实验操作 实验要求: 1.掌握配置帧中继的基本方法. 2.掌握在路由器中模拟帧中继交换机的方法. 3.掌握 NBMA 网络中 OSPF  ...

  3. 020 Android 常用颜色对应表

    1.Android colors.xml常用颜色汇总 <?xml version="1.0" encoding="utf-8"?> <reso ...

  4. [.Net Core] - Asp.Net Core 编译成功,发布失败之解决

    背景 Asp.Net Core 项目编译成功,发布失败. 错误 Assets file 'D:\……\obj\project.assets.json' doesn't have a target fo ...

  5. 简单的鼠标操作<一个填充格子的小游戏>

    #include "graphics.h" #include "conio.h" void main(){ // 初始化界面 initgraph(, ); ; ...

  6. Python开发【第二章】:数据类型

    基本数据类型 一.整型 如: 18.73.84 整型具备如下功能: class int(object): """ int(x=0) -> int or long i ...

  7. php 判断请求是否是json

    $object =file_get_contents("php://input"); $arr = is_json($object); if($arr){ var_dump($ar ...

  8. google mock C++单元测试框架

    转:google mock C++单元测试框架 2012-03-12 09:33:59 http://blog.chinaunix.net/uid-25748718-id-3129590.html G ...

  9. 无重复字符串的最长子串 python

    给定一个字符串,请你找出其中不含有重复字符的 最长子串 的长度. 示例 1: 输入: "abcabcbb" 输出: 3 解释: 因为无重复字符的最长子串是 "abc&qu ...

  10. iOS - 总结适配IOS10需要注意的问题

    1.自动管理证书 首先要说的就是Xcode8.打开Xcode8最明显的就是Targets-->General下的自动管理证书模块.以前对于新手来说无论是开发还是打包都必须要被苹果的开发签名系统虐 ...