基于helium自动化测试的方法进行代码仓库梳理和备份

2020-09-16 10:14:29 浏览数 (1)

helium 简介

helium是一款基于 Selenium 实现的网页自动化工具,他的 API 比 Selenium 更简介,当然也因为他是基于 Selenium 之上构建的,因此灵活性会比 Selenium 稍微差一些,不过如果对于一些简单的工作, helium 会更方便。

helium 安装

python-helium 是基于 Python3 的,因此需要在 Python3 的环境下安装,直接用pip安装:

代码语言:javascript复制
pip install helium

代码梳理

代码仓库创建

这里由开发人员梳理出了新旧代码的代码仓库对照表new新旧仓库对照表.xls,需要基于 excel 表先新的gitlab地址下创建代码仓库:

代码语言:javascript复制
from helium import start_chrome, write, press, ENTER, click, kill_browser, go_to, S

import time
import pandas as pd

# login in
def login():
    write('xxxx', into='username')
    write('xxxxx', into='password')
    press(ENTER)

# 自动创建项目
def createProject(name, description, group):
    go_to("https://xxxxxx.com/projects/new")
    click("root")
    write(group, into=S("#s2id_autogen1_search"))
    click(group)
    write(name, into="My awesome project")
    write(description, into="描述格式")
    click("内部")
    click('新建项目')

if __name__ == "__main__":
    driver = start_chrome('https://xxxxx.com/')
    login()
    data = pd.read_excel("new新旧仓库对照表.xls", encoding="gbk")
    group_name = data["group"]
    project_name = data["项目名称"]
    description = data["描述"]
    for i in range(len(data)):
        if project_name.iloc[i] == "" or description.iloc[i] == "" or group_name.iloc[i] == "":
            print("no data, and pass")
            pass
        else:
            print("处理到:" "-"*10,i)
            createProject(project_name.iloc[i], description.iloc[i], group_name.iloc[i])
    time.sleep(2)
    kill_browser()

代码备份

对代码进行备份,将其压缩后上传到阿里云 oss 上:

代码语言:javascript复制
import oss2
import os
import shutil
import pandas as pd

# 代码下载
data = pd.read_excel("newtable.xls")
old_projects = data["原git地址"]
new_projects = data["新git地址"]
group = data["group"]

for i in range(len(data)):
    old_git = old_projects.iloc[i]
    new_git = new_projects.iloc[i]
    group_name = group.iloc[i]
    project_name = old_git.split("/")[-1]
    # 下载代码并压缩成 zip 压缩包
    gitCloneCMD = "git clone --bare %s; tar -zcvf %s.zip %s --remove-files"%(old_git, project_name, project_name)
    print(gitCloneCMD)
    os.system(gitCloneCMD)

    # OSS
    auth = oss2.Auth('xxxxxxxx', 'xxxxxxx')
    bucket = oss2.Bucket(auth, 'http://oss-accelerate.aliyuncs.com', 'xxxxxx')

    # 将代码上传到oss进行备份
    bucket.put_object_from_file('realihub/%s/%s.zip'%(group_name,project_name), '%s.zip'%project_name)

    os.remove('%s.zip'%project_name)
    print(group_name, project_name)
    print("处理到:" "-"*10, i)

print("finish!")

0 人点赞