Python script batch add jira users

I just went to work recently. The superiors gave me a request and asked me to make a python script for jira to add users in batches. After referring to the Internet, I summarized it as follows: After
we set up the jira service, Jira-web can be accessed through the browser. We
can manually add a certain number of users to jira through the click of the mouse and the typing of the keyboard . Now we need a script To drive the browser to automatically
add a large number of users that have been added according to a certain format, this will involve the browser’s automated testing framework Selenium
, which is a tool for web application testing. Selenium tests run directly on the browser. In the browser, just like we are really a client
manual operation, the supported browsers include IE (7, 8, 9, 10, 11), Firefox, Safari, Google Chrome,
Opera, etc. The main functions of this tool include: test system Compatibility-Test your application to see if it can work well on different browsers and
operating systems.
The bottom layer of the framework uses JavaScript to simulate the actual operation of the browser by the user. When the test script is executed, the browser automatically performs
operations such as clicking, inputting, opening, and verifying according to the script code , just like what the real user does, from the perspective of the end user Test the application.
It is possible to automate the browser compatibility test, although there are still subtle differences in different browsers.
Simple to use, you can use Java, Python and other languages ​​to write use case scripts.
Install the Selenium module and download the browser's driver executable program.

1 Install the Selenium module: pip install Selenium
2 Download the browser driver, Selenium 3.x calls the browser must have a webdriver driver file
Chrome driver file download: click to download
Firefox driver file download: click to download

Utilize the webdriver function in the Selenium module

from selenium import webdriver
绝对路径导入浏览器驱动可执行文件
# 如是chrome浏览器的驱动
driver = webdirver.Chrome("D:\driver\chromedriver.exe")
# 如果是firefox浏览器的驱动
driver = webdriver.Firefox(executable_path="D:\driver\geckodriver.exe")

# 如果谷歌和火狐浏览器驱动的目录加入了环境变量之中,可以直接下面写代码
# 谷歌浏览器驱动
driver = webdirver.Chrome()
# firefox浏览器驱动
driver = webdirver.Firefox()

Experimental environment: python3.7.6+jira7.12.0+mysql5.7
Below I give all the codes of jira batch adding users:

"""批量创建Jira用户的账号"""
from selenium import webdriver
from time import  sleep
import csv
driver = webdriver.Chrome(r'D:\chromedirver\chromedriver.exe')
driver.get("http://192.168.1.129:8080/login.jsp") #jira的网址
data_set = r'D:\jirauser\userdata.csv'
sleep(5)
# 输入jira web端登陆的用户名和密码
driver.find_element_by_id('login-form-username').send_keys('zhaoyi')
driver.find_element_by_id('login-form-password').send_keys('123')
driver.find_element_by_id('login-form-submit').click()
sleep(3)

driver.find_element_by_id('admin_menu').click()
driver.find_element_by_id('admin_users_menu').click()
driver.find_element_by_id('login-form-authenticatePassword').send_keys('123')
driver.find_element_by_id('login-form-submit').click()
driver.implicitly_wait(3)

# 利用csv模块把csv文件中的所有用户的信息都读取到要给列表中
# 每个用户的信息是列表中一个元素,该元素也是一个拥有完整单个用户信息的列表
reader = csv.reader(open(data_set,encoding='utf-8'))
rows = [row for row in reader]
for i in rows:
   driver.implicitly_wait(1)
   driver.find_element_by_id('create_user').click()
   driver.find_element_by_id('user-create-username').send_keys(i[0])
   driver.find_element_by_id('password').send_keys(i[1])
   driver.find_element_by_id('user-create-fullname').send_keys(i[2])
   driver.find_element_by_id('user-create-email').send_keys(i[3])
   driver.find_element_by_id('user-create-submit').click()
   sleep(10)
driver.close()

Guess you like

Origin blog.csdn.net/weixin_48505120/article/details/106906904