![](/img/trans.png)
[英]Changes to static class variable are not visible from another module
[英]Modify static class variable from a different Class/module
在其他帖子中找不到我的問題的具體答案,所以它就這樣了:
我需要從其他類/模塊修改靜態類變量。 我得到了帶有靜態變量admin的LoginPage類
class LoginPage(BasePage):
#Users
admin = ["testemail1@gmail.com","Password1234!"]
basicUser = ["testemail1@gmail.com", "Password1234!"]
我得到了我的配置文件測試類,它使用了changepassword方法/ test:
class MyProfileTests(BaseTestCase, LoginPage):
def test_change_password(self):
try:
self.loginAs(self.basicUser)
MyProfilePage(self.driver).changePassword('Password007$$')
最后是changepassword方法
def changePassword(self, new_password):
self.driver.find_element_by_xpath(self._change_pw).click()
password_fields = self.driver.find_elements_by_xpath(".//*[@class='form-group']/*/input")
password_fields[1].send_keys(new_password)
self.submit_button.click()
#Changing password for the LoginPage object
self._passwordChange(new_password)
def _passwordChange(self, password):
try:
self.driver.find_element(by=By.XPATH, value = '//*[contains(text(), "Password successfully changed.")]')
LoginPage.admin[1] = password
except NoSuchElementException:
pass
問題是它似乎並沒有更改LoginPage.admin的實際對象。 這里的想法是,每當我使用changePassword方法時,如果我需要登錄以進行其他測試,則不需要手動更新admin / basicuser的密碼
看來我想做的是在LoginPage.py中動態修改一行代碼,該代碼不適用於我的代碼,並且可能需要一些高級知識。 我決定將所有登錄信息保存在單獨的.txt文件中,從而解決了該問題
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.