簡體   English   中英

在頁面對象模型實現期間會發生某些異常。 我究竟做錯了什么?

[英]Certain exception occurs during Page Object Model implementation. What am I doing wrong?

我想在自動化項目中實現頁面對象模型的原理,以便將其變成一個真正的框架。

被測試的對象是設備的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都在同一個Package(稱為WEB_Pages)下。 Simple_Test在單獨的軟件包中,稱為Test_Cases。

我終於設法了解了我的項目中發生的異常。 問題與以下事實有關:我沒有構造Main_Screen_POM(希望我使用正確的術語),而是嘗試在其中激活一個功能。

另一個錯誤是在調用函數期間,我將變量(瀏覽器)導出到沒有任何參數的Get_Rx_Pwr函數。

解決這些問題后,我發現了另一個與Get_Rx_Pwr函數的第一行有關的問題。 初始化未正確完成。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM