简体   繁体   English

硒自动化测试

[英]automation testing by selenium

i have too many usernames and passwords in a txt file and i want to use them in a test script , the password many contain (:) and the error is (ValueError: too many values to unpack (expected 2)) how to fix this and how to get the data from the txt file and use them in the test . 我在txt文件中有太多的用户名和密码,我想在测试脚本中使用它们,许多密码包含(:),错误是(ValueError:太多的值无法解包(预期2))如何解决此问题以及如何从txt文件中获取数据并在测试中使用它们。

the txt look like this txt看起来像这样

user1:pass1
user2:pass2
user3:password
username5:password6
testit:passtest

etc 等等

i tried many codes to read the txt file and use it to login no luck . 我尝试了许多代码来读取txt文件,并使用它登录时没有运气。

login do some tasks and logout and repeat the process with the rest accounts 登录执行一些任务并注销,然后使用其余帐户重复该过程

from selenium import webdriver
    from time import sleep
    from getpass import getpass
    import time

#login username & password

with open('accounts.txt', 'r') as file:
    for line in file:
        user, password = line.split(':')


#define what browser & website
browser = webdriver.Firefox()
browser.get(('https://example.com'))
elem = browser.find_element_by_xpath("//*[@id='loginRegisterTabs']/ul/li[1]")
elem.click()

emailelement = browser.find_element_by_xpath("//*[@id='loginForm']/div[1]/div/input")
emailelement.send_keys('user')
passelement = browser.find_element_by_xpath("//*[@id='loginForm']/div[2]/div/input")
passelement.send_keys('password')
elem = browser.find_element_by_xpath("//*[@id='loginForm']/p/button[1]/span")
elem.click()

#server login
time.sleep(1)
elem = browser.find_element_by_xpath("//*[@id='joinGame']/button/span[1]")
elem.click()

#Active Daily
time.sleep(1)
elem = browser.find_element_by_xpath("//*[@id='multiPopup']/div[2]/div[2]/a")
elem.click()


#menu
time.sleep(4)
browser.switch_to.window(browser.window_handles[1])
elem = browser.find_element_by_xpath("//*//*[@id='GF_toolbar']/ul/li[5]/a")
elem.click()

#Vmod Menu
time.sleep(2)
elem = browser.find_element_by_xpath("//*[@id='vacationMode']/div[1]/div/a")
elem.click()

#Active Vmod
time.sleep(2)
elem = browser.find_element_by_xpath("//*[@id='options_umod_confirm']/div[2]/div[2]/div[2]/div[1]/div[1]/a")
elem.click()
  1. Limit number of splits in user/password strings: 限制用户/密码字符串分割的数量:

    user, password = line.split(':', 1)

  2. Move everything under this line under the for loop (iterating over the file lines) 将所有内容移动到for循环下的该行下(遍历文件行)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM