批量验证RackShift上物理机Web Console正确打开

最近云平台集成RackShift来批量管理近100台物理机,需要验证一下每台机器从界面能正确打开Console。手工就有点扯了,简单写了下边Selenium脚本来实现

  1. 到物理机列表面
  2. 选择每页100条显示
  3. 循环每台机器打开,并截图
  4. 检查截图显示是否正确
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
import time

URL = 'http://xxx/#/login'
driver = webdriver.Chrome()

# Open system
driver.get(url=URL)
driver.maximize_window()

# Login
driver.find_element_by_xpath('//*[@id="app"]/div/div/div[1]/form/div[5]/div[2]/div/div[1]/input').send_keys('admin')
driver.find_element_by_xpath('//*[@id="app"]/div/div/div[1]/form/div[5]/div[3]/div/div[1]/input').send_keys('admin')
driver.find_element_by_xpath('//*[@id="app"]/div/div/div[1]/form/div[6]/button').click()
time.sleep(2)

# Select page
driver.find_element_by_xpath('//*[@id="pane-bare-metal"]/div[3]/div/span[2]/div/div[1]/input').click()
time.sleep(2)
driver.find_element_by_xpath('//ul[@class="el-scrollbar__view el-select-dropdown__list"]/li[4]').click()

# Open console and capture
for i in range(1, 98):
ip = driver.find_element_by_xpath(f'//table[@class="el-table__body"]/tbody/tr[{i}]/td[4]/div').text

element = driver.find_element_by_xpath(f'//table[@class="el-table__body"]/tbody/tr[{i}]//button')
dropdown = element.get_attribute('aria-controls')

element.click()
time.sleep(2)

xpath = '//ul[@id="' + dropdown + '"]/li[4]'
driver.find_element_by_xpath(xpath).click()
time.sleep(2)

# capture
handles = driver.window_handles

driver.switch_to.window(handles[-1])
ActionChains(driver).send_keys(Keys.ENTER).perform()
time.sleep(2)
driver.get_screenshot_as_file(f'./image/{ip}.png')

driver.close()
driver.switch_to.window(handles[0])

driver.quit()
唐胡璐 wechat
欢迎您扫一扫上面的微信公众号,订阅我的博客!
分享创造价值,您的支持将鼓励我继续前行!