页面对象模型实现过程中会发生某些异常.我做错了什么?



我想在我的自动化项目中实现页面对象模型的原则,以便将其变成一个真正的框架。

测试的对象是设备 WEB GUI。此设备 GUI 可以分为多个帧。每个框架都包含一些元素。为了在 POM(页面对象模型(中表示设备 GUI,我计划为 GUI 中的每个帧构建一个单独的文件 (POM(。

这些框架中只有一个会有很多方法,其余的大多包括元素(顺便说一下,我想知道根据 POM 原则实现没有方法的框架是否正确?

在下面的示例中,我开始表征几个帧,并编写了一个将与它们交互的测试用例。我的问题是,在测试用例脚本(Simple_Test.py(的某个时刻,我可能会遇到异常,但我不知道为什么。我已经调试了Simple_Test.py,发现每当我到达Pwr, OSNR = Main_Screen.Get_Rx_Pwr(browser)下一步都会execute_code(i, browser),然后下一步是browser.quit()(在except:下(。

有人可以帮我解决这个问题吗?

以下是相关脚本:

Simple_Test.py

from selenium import webdriver
from WEB_Pages.Login_POM import Login_Page
#from WEB_Pages.Main_Screen_POM.Main_Screen import Get_Rx_Pwr
from WEB_Pages.Main_Screen_POM import *

def main():
i = 0
while True:
i = i +1
profile = webdriver.FirefoxProfile()
profile.accept_untrusted_certs = True
browser = webdriver.Firefox(firefox_profile = profile)
browser.implicitly_wait(20) # Implicit wait
try:
execute_code(i, browser)
browser.quit()
if i == 2:
break
except:
browser.quit()

def execute_code(i, browser):
browser.get('http://10.0.1.131')
login = Login_Page(browser)
login.Login('admin', 'admin')
#    Port = Device_Panel_Frame.Port_19
Pwr, OSNR = Main_Screen.Get_Rx_Pwr(browser)
#    print (Port)
print (Pwr)
print (OSNR)
#    print('The measured Uplink 1 Power is', Pwr)
#    print('The measured Uplink 1 OSNR is', OSNR)
if __name__ == '__main__':
main()

Login_POM.py

from selenium import webdriver
class Login_Page(object):
'''
classdocs
'''
def __init__(self, driver):
'''
Constructor
'''
self.driver = driver
def Login(self, userName, pas):
user_name = self.driver.find_element_by_id('u_name_box')
user_name.send_keys(userName)
password = self.driver.find_element_by_id('u_pass_box')
password.send_keys(pas)
login_button = self.driver.find_element_by_id('login_but')
login_button.click()

Device_Panel_POM.py

from selenium import webdriver

class Device_Panel_Frame(object):
'''
classdocs
'''
def __init__(self, driver):
'''
Constructor
'''
self.driver = driver
self.driver.switch_to.default_content()

self.driver.switch_to.frame('box_menu')
self.driver.switch_to.frame('box_menu')
Port_19 = self.driver.find_element_by_id('Port-19')
Port_19.click()

Main_Screen_POM.py

from WEB_Pages.Device_Panel_POM import Device_Panel_Frame
class Main_Screen(object):
'''
classdocs
'''

def __init__(self, driver):
'''
Constructor
'''
self.driver = driver

def Get_Rx_Pwr(self):
Device_Panel_Frame.__init__(self, self.driver).Port_19
self.driver.switch_to.default_content()
# Show the Optic Module information TAB
self.driver.switch_to.frame('main_body')
CFP2_Info = self.driver.find_element_by_id('tab_XFP')
CFP2_Info.click()
# Collect the Rx Pwr from the CFP2 Info screen
self.driver.switch_to.frame('config_port') # Move to the inner frame that holds all the tables
#browser.find_element_by_class_name('table_round_corner')
Rx_Pwr = self.driver.find_element_by_xpath('html/body/form/div[1]/div/table/tbody/tr[2]/td[2]') # Take the Rx Pwr according to its Xpath
# print (Rx_Pwr.text) # print the Rx Pwr result to screen
RcvPwr = Rx_Pwr.text
# Collect the OSNR measurement from the CFP2 Info screen
OSNR = self.driver.find_element_by_xpath('html/body/form/div[1]/div/table/tbody/tr[4]/td[2]')
OSNR_Lvl = OSNR.text
return RcvPwr, OSNR_Lvl

顺便说一下,脚本:Device_Panel_POM、Login_POM 和 Main_Screen_POM 都在称为 WEB_Pages 的同一个包下。Simple_Test位于称为Test_Cases的单独包中。

我终于设法理解了项目中发生的异常。这个问题与我没有构建(我希望我使用正确的术语(Main_Screen_POM有关,而是我尝试在其中激活一个功能。

另一个错误是,在调用函数期间,我将一个变量(浏览器(导出到Get_Rx_Pwr函数,该函数没有任何参数。

解决这些问题后,我揭示了与Get_Rx_Pwr函数中的第一行相关的另一个问题。那里的初始化没有正确完成。

最新更新