2011-05-20 114 views
0

我無法在我的第二個類中調用我的原始硒實例,它有一個函數Ge​​tRows()。有什麼方法可以在我的函數類中獲得硒對象?如何將Selenium對象傳遞給另一個類?

Class test(unittest.TestCase): 
    def setUp(self): 
     self.verificationerrors=[] 
     self.selenium = selenium("localhost",4444,"","http://localhost") 
     self.selenium.start() 

    def test_untitiled(self): 
     pass 

    def teardown(self): 
     pass 

    def Get(self):  
     return self.selenium 

Class Functions: 
    def GetRows(self) 
     selenium.get_xpath_count(path) //Cant call selenium object here! :(
     sel = test().get() // Does not allow me to return self. selenium :(

回答

0

你的第二類擴展或實例化你的「測試」類,它負責創建硒對象

+0

作爲硒核心提交者我不能建議任何人使用SQA StackExchange。 -1 – AutomatedTester 2011-05-21 18:15:38

+1

作爲Selenium Doc的核心成員,我想我沒有做錯任何事情。你見過這個嗎? - http://meta.sqa.stackexchange.com/questions/13/how-would-we-attract-selenium-users-to-ask-question-on-sqa-site-than-on-stackovef最重要的是這可能是將回答標記爲-1的原因嗎? – Tarun 2011-05-22 10:22:54

0

,我會做到這一點是抽象的一切,你需要做的方式你第二類,並有你的測試只是調用。

所以,你的測試類是這樣的

class SearchTests(unittest.TestCase): 

    _count_regex = '^.* (\d+) - (\d+)' 
    _total_count_regex = '^.* \d+ - \d+ of (\d+)' 

    def setUp(self): 
     self.selenium = selenium(server, 
           port, 
           browser, 
           baseurl) 
     self.selenium.start() 
     self.selenium.set_timeout(ConnectionParameters.page_load_timeout) 

    def tearDown(self): 
     self.selenium.stop() 

    def test_that_character_escaping_doesnt_go_into_the_test(self): 
     """ Test for Litmus 4857 
      https://litmus.mozilla.org/show_test.cgi?id=4857""" 
     amo_home_page = AddonsHomePage(self.selenium) 
     amo_search_page = amo_home_page.search_for("personas%20plus") 
     self.assertTrue(amo_search_page.is_text_present("No results found.")) 
     results_count = amo_search_page.results_count 
     self.assertTrue("0 - 0 of 0" in results_count) 

和你的抽象會是這個樣子

class AddonsSearchHomePage(AddonsHomePage): 

    _results_count_header = "css=h3.results-count" 
    _page_counter = "css=div.num-results" 

    def __init__(self, selenium): 
     self.selenium = selenium 

    @property 
    def results_count(self): 
     return self.selenium.get_text(self._results_count_header) 

    @property 
    def page_results_count(self): 
     return self.selenium.get_text(self._page_counter) 

你可以看到整個項目一樣,在https://github.com/AutomatedTester/Addon-Tests

相關問題