2013-10-31 108 views
0

我正在使用Selenium2TestCase對象在網站上運行一些測試。我試圖模塊化這些測試,以方便編寫和新的測試和可讀性。由於我對Selenium WD和PHPUnit的瞭解有限,以及在線提供的有用信息明顯缺乏,我跳入內存中,開始將測試分解爲單獨的「頁面」對象。我不知道這是最好的解決方案還是技術上可行的。模塊化PHPUnit Selenium2測試的最佳方式是什麼?

這是我目前所面對的簡化版本...

class Selenium2TestCase_Extension extends PHPUnit_Extensions_Selenium2TestCase 
{ 
    public function testPages(){ 

     $pages = array('about', 'contact'); 

     foreach($pages as $page){ 

      // Can I instantiate and run the tests in About_Test from here??? 
     } 
    } 
} 

class About_Test extends PHPUnit_Extensions_Selenium2TestCase 
{ 
    public function testTitle(){ 
     $this->url('/about'); 

     $this->assertEquals("About Us", $this->title()); 
    } 

} 

class Home_Test extends PHPUnit_Extensions_Selenium2TestCase 
{ 
    public function testTitle(){ 
     $this->url('/home'); 

     $this->assertEquals("Welcome", $this->title()); 
    } 

} 

我不知道如果我試圖在這裏是不可能的或者什麼,所以任何幫助,將不勝感激!

+0

看來你基本上試圖重新發明車輪;已經有一些選項可以組織您的測試: - 按照它們在文件系統上的位置 - 使用您在xml 中配置的測試套件 - 使用\ @group/\ @ author註釋或\ @small,\ @中等,\ @大註釋 (SO不允許我發佈這些註釋而不逃避它們,不考慮反斜槓) – ilias

回答

0

是的,你可以用execsystem或類似的東西。但似乎不是正確的方法。

XY problem

你可以

  1. 使用groups用於啓動一些試驗。
  2. 將這些測試存儲在一個單獨的文件夾中,並使用command-line interface對其進行測試。
  3. 使用command-line interface只運行想要的測試。
  4. (在你的情況下)使用data provider並只寫一個測試。
+0

謝謝你。我認爲你是對的,但是我對Selenium和PHPUnit都很陌生,所以我很難在這方面找到任何信息。 – jonadams51

相關問題