Some test cleanup.
authorPriyanka Dhanda <pdhanda@users.mediawiki.org>
Thu, 23 Dec 2010 23:12:31 +0000 (23:12 +0000)
committerPriyanka Dhanda <pdhanda@users.mediawiki.org>
Thu, 23 Dec 2010 23:12:31 +0000 (23:12 +0000)
tests/selenium/SeleniumTestCase.php
tests/selenium/SeleniumTestConstants.php [new file with mode: 0644]
tests/selenium/suites/MediaWikiExtraTestSuite.php
tests/selenium/suites/MyContributionsTestCase.php
tests/selenium/suites/MyWatchListTestCase.php

index 11e1b19..d1a5f44 100644 (file)
@@ -1,4 +1,6 @@
 <?php
+include("SeleniumTestConstants.php");
+
 class SeleniumTestCase extends PHPUnit_Framework_TestCase { // PHPUnit_Extensions_SeleniumTestCase
        protected $selenium;
 
@@ -26,78 +28,100 @@ class SeleniumTestCase extends PHPUnit_Framework_TestCase { // PHPUnit_Extension
                $this->assertRegExp( "/$text/", $innerHTML );
        }
 
-//Common Funtions Added for Selenium Tests
 
-        public function getExistingPage(){
-                $this->open( $this->getUrl() .
+       /**
+        * Create a test fixture page if one does not exist
+        * @param $pageName The fixture page name. If none is supplied, it uses WIKI_INTERNAL_LINK
+        */
+       function createTestPageIfMissing( $pageName = null ) {
+               if ( $pageName == null ) {
+                       $pageName = WIKI_INTERNAL_LINK;         
+               }
+               $this->type( INPUT_SEARCH_BOX, $pageName  );
+               $this->click( BUTTON_SEARCH );
+               $this->waitForPageToLoad( WIKI_TEST_WAIT_TIME );
+               $this->click( LINK_START . $pageName );
+               $this->waitForPageToLoad( WIKI_TEST_WAIT_TIME );
+               $location =  $this->getLocation() . "\n";
+               if ( strpos( $location, '&redlink=1') !== false  ) {
+                       $this->type( TEXT_EDITOR,  "Test fixture page. No real content here" );
+                       $this->click( BUTTON_SAVE );
+                       $this->waitForPageToLoad( WIKI_TEST_WAIT_TIME );
+                       $this->assertTrue( $this->isTextPresent( $pageName ),
+                       $this->getText( TEXT_PAGE_HEADING ) );
+               }
+       }
+       
+       /**
+        * Create a test page using date as part of the name so that it is unique
+        * @param $pagePrefix The prefix to use for the page name. The current date will be appended to this to make it unique
+        * @param $watchThis Whether to add the page to my watchlist. Defaults to false.
+        */
+       function createNewTestPage( $pagePrefix, $watchThis = false ) {
+               $pageName = $pagePrefix . date("Ymd-His");
+               $this->type( INPUT_SEARCH_BOX, $pageName  );
+               $this->click( BUTTON_SEARCH );
+               $this->waitForPageToLoad( WIKI_TEST_WAIT_TIME );
+               $this->click( LINK_START . $pageName );
+               $this->waitForPageToLoad( WIKI_TEST_WAIT_TIME );
+               $location =  $this->getLocation() . "\n";
+               $this->assertContains( '&redlink=1', $location ).
+               $this->type( TEXT_EDITOR,  "Test fixture page. No real content here" );
+               if ( $watchThis ) {
+                       $this->click( "wpWatchthis" );
+               }
+               $this->click( BUTTON_SAVE );
+               $this->waitForPageToLoad( WIKI_TEST_WAIT_TIME );
+               $this->assertTrue( $this->isTextPresent( $pageName ),
+               $this->getText( TEXT_PAGE_HEADING ) );
+               return $pageName;
+       }
+
+       public function getExistingPage(){
+               $this->open( $this->getUrl() .
                        '/index.php?title=Main_Page&action=edit' );
-                $this->type("searchInput", "new" );
-                $this->click("searchGoButton");
-                $this->waitForPageToLoad("30000");
-        }
+               $this->type("searchInput", "new" );
+               $this->click("searchGoButton");
+               $this->waitForPageToLoad("30000");
+       }
 
-        public function getNewPage($pageName){
+       public function getNewPage($pageName){
 
-                $this->open( $this->getUrl() .
+               $this->open( $this->getUrl() .
                        '/index.php?title=Main_Page&action=edit' );
-                $this->type("searchInput", $pageName );
-                $this->click("searchGoButton");
-                $this->waitForPageToLoad("30000");
-                $this->click("link=".$pageName);
-                $this->waitForPageToLoad("600000");
+               $this->type("searchInput", $pageName );
+               $this->click("searchGoButton");
+               $this->waitForPageToLoad("30000");
+               $this->click("link=".$pageName);
+               $this->waitForPageToLoad("600000");
 
 
-        }
-       // Loading the mediawiki editor
-        public function loadWikiEditor(){
-                $this->open( $this->getUrl() .
-                       '/index.php?title=Main_Page&action=edit' );
-        }
-
-        // Clear the content of the mediawiki editor
-        public function clearWikiEditor(){
-                $this->type("wpTextbox1", "");
-        }
-
-        // Click on the 'Show preview' button of the mediawiki editor
-        public function clickShowPreviewBtn(){
-                $this->click("wpPreview");
-        }
-
-        // Click on the 'Save Page' button of the mediawiki editor
-        public function clickSavePageBtn(){
-                $this->click("wpSave");
-        }
-
-        // Click on the 'Edit' link
-        public function clickEditLink(){
-                $this->click("link=Edit");
-                $this->waitForPageToLoad("30000");
-        }
-
-        public function deletePage($pageName){
-                $isLinkPresent  = False;
-                $this->open( $this->getUrl() .
+       }
+       // Loading the mediawiki editor
+       public function loadWikiEditor(){
+               $this->open( $this->getUrl() .
                        '/index.php?title=Main_Page&action=edit' );
-                $this->click("link=Log out");
-                $this->waitForPageToLoad( "30000" );
-                $this->click( "link=Log in / create account" );
-                $this->waitForPageToLoad( "30000" );
-                $this->type( "wpName1", "nadeesha" );
-                $this->type( "wpPassword1", "12345" );
-                $this->click( "wpLoginAttempt" );
-                $this->waitForPageToLoad( "30000" );
-                $this->type( "searchInput", $pageName );
-                $this->click( "searchGoButton");
-                $this->waitForPageToLoad( "30000" );
-
-                $this->click( "link=Delete" );
-                $this->waitForPageToLoad( "30000" );
-                $this->click( "wpConfirmB" );
-                $this->waitForPageToLoad( "30000" );
-
-        }
+       }
+
+       // Clear the content of the mediawiki editor
+       public function clearWikiEditor(){
+               $this->type("wpTextbox1", "");
+       }
 
+       // Click on the 'Show preview' button of the mediawiki editor
+       public function clickShowPreviewBtn(){
+               $this->click("wpPreview");
+       }
 
+       // Click on the 'Save Page' button of the mediawiki editor
+       public function clickSavePageBtn(){
+               $this->click("wpSave");
+       }
+
+       // Click on the 'Edit' link
+       public function clickEditLink(){
+               $this->click("link=Edit");
+               $this->waitForPageToLoad("30000");
+       }
 
 }
diff --git a/tests/selenium/SeleniumTestConstants.php b/tests/selenium/SeleniumTestConstants.php
new file mode 100644 (file)
index 0000000..76af837
--- /dev/null
@@ -0,0 +1,20 @@
+<?php
+define ('WIKI_TEST_WAIT_TIME', "3000"); // Waiting time
+
+//commonly used links
+define ('LINK_MAIN_PAGE',"link=Main page");
+define ('LINK_RANDOM_PAGE',"link=Random article");
+define ('TEXT_PAGE_HEADING',"firstHeading");
+
+define ('LINK_START',"link=");
+define ('TEXT_EDITOR',"wpTextbox1");
+define ('LINK_PREVIEW',"wpPreview");
+define ('LINK_EDIT',"link=Edit");
+
+define ('WIKI_SEARCH_PAGE',"Hair (musical)"); // Page name to search
+define ('WIKI_TEXT_SEARCH',"TV"); // Text to search
+define ('WIKI_INTERNAL_LINK',"Wikieditor-Fixture-Page"); // Exisiting page name to add as an internal tag
+
+define ('INPUT_SEARCH_BOX', "searchInput");
+define ('BUTTON_SEARCH',"mw-searchButton");
+define ('BUTTON_SAVE',"wpSave");
index 929f253..5cd0a34 100644 (file)
@@ -1,20 +1,20 @@
 <?php
 
 class MediaWikiExtraTestSuite extends SeleniumTestSuite {
-    public function setUp() {
-        $this->setLoginBeforeTests( true );
-        parent::setUp();
-    }
-    public function addTests() {
-        $testFiles = array(
-                'tests/selenium/suites/MyContributionsTestCase.php',
-                'tests/selenium/suites/MyWatchListTestCase.php',
-                'tests/selenium/suites/UserPreferencesTestCase.php',
-                'tests/selenium/suites/MovePageTestCase.php',
-                'tests/selenium/suites/PageSearchTestCase.php',
-                'tests/selenium/suites/EmailPasswordTestCase.php',
-                'tests/selenium/suites/CreateAccountTestCase.php'
-        );
-        parent::addTestFiles( $testFiles );
-    }
+       public function setUp() {
+               $this->setLoginBeforeTests( true );
+               parent::setUp();
+       }
+       public function addTests() {
+               $testFiles = array(
+                       'tests/selenium/suites/MyContributionsTestCase.php',
+                       'tests/selenium/suites/MyWatchListTestCase.php',
+                       'tests/selenium/suites/UserPreferencesTestCase.php',
+                       'tests/selenium/suites/MovePageTestCase.php',
+                       'tests/selenium/suites/PageSearchTestCase.php',
+                       'tests/selenium/suites/EmailPasswordTestCase.php',
+                       'tests/selenium/suites/CreateAccountTestCase.php'
+               );
+               parent::addTestFiles( $testFiles );
+       }
 }
index fbbb542..48873dc 100644 (file)
@@ -32,45 +32,32 @@ class MyContributionsTestCase extends SeleniumTestCase {
     // Verify user contributions
     public function testRecentChangesAvailability() {
 
-        $newPage = "mypage999";
-        $displayName = "Mypage999";
-
-        $this->open( $this->getUrl() .
-                '/index.php?title=Main_Page&action=edit' );
-
-        $this->type( "searchInput", $newPage);
-        $this->click( "searchGoButton" );
-        $this->waitForPageToLoad( "60000" );
-        $this->click( "link=".$displayName );
-        $this->waitForPageToLoad( "600000" );
-        $this->type( "wpTextbox1", $newPage." text" );
-        $this->click( "wpSave" );
-        $this->waitForPageToLoad( "60000" );
-
+        $newPage = $this->createNewTestPage( "MyContributionsTest" );
+        
         // Verify My contributions Link available
-        $this->assertTrue($this->isElementPresent( "link=My contributions" ));
+        $this->assertTrue($this->isElementPresent( "link=Contributions" ));
 
-        $this->click( "link=My contributions" );
-        $this->waitForPageToLoad( "30000" );
+        
+        $this->click( "link=Contributions" );
+        $this->waitForPageToLoad( WIKI_TEST_WAIT_TIME );
 
         // Verify recent page adding available on My Contributions list
-        $this->assertEquals( $displayName, $this->getText( "link=".$displayName ));
-
-        $this->type( "searchInput", $newPage );
-        $this->click( "searchGoButton" );
-        $this->waitForPageToLoad( "30000" );
-
-        $this->click( "link=Edit" );
-        $this->waitForPageToLoad( "30000" );
-        $this->type( "wpTextbox1", $newPage." text changed" );
-        $this->click( "wpSave" );
-        $this->waitForPageToLoad( "30000" );
-        $this->click( "link=My contributions" );
-        $this->waitForPageToLoad( "30000" );
+        $this->assertEquals( $newPage, $this->getText( "link=".$newPage ));
+
+        $this->type( INPUT_SEARCH_BOX, $newPage );
+        $this->click( BUTTON_SEARCH );
+        $this->waitForPageToLoad( WIKI_TEST_WAIT_TIME );
+        
+        $this->click( LINK_EDIT );
+        $this->waitForPageToLoad( WIKI_TEST_WAIT_TIME );
+        $this->type( TEXT_EDITOR, $newPage . " text changed" );
+        $this->click( BUTTON_SAVE );
+        $this->waitForPageToLoad( WIKI_TEST_WAIT_TIME );
+        $this->click( "link=Contributions" );
+        $this->waitForPageToLoad( WIKI_TEST_WAIT_TIME );
 
         // Verify recent page changes available on My Contributions
-        $this->assertTrue($this->isTextPresent($displayName." ‎ (top)"));
-        $this->deletePage($newPage);
+        $this->assertTrue( $this->isTextPresent( $newPage ) );
     }
 }
 
index b2cc326..aeaac3f 100644 (file)
@@ -33,41 +33,24 @@ class MyWatchListTestCase extends SeleniumTestCase {
     // Verify user watchlist
     public function testMyWatchlist() {
 
-        $newPage = "mypage";
-        $displayName = "Mypage";
-        $wikiText = "watch page";
-
-        $this->open( $this->getUrl().'/index.php?title=Main_Page' );
-
-        $this->type( "searchInput", $newPage );
-        $this->click( "searchGoButton" );
-        $this->waitForPageToLoad( "30000" );
-        $this->click( "link=".$displayName );
-        $this->waitForPageToLoad( "600000" );
-
-        $this->click( "wpWatchthis" );
-        $this->type( "wpTextbox1",$wikiText );
-        $this->click( "wpSave" );
-        $this->waitForPageToLoad( "30000" );
-
+        $pageName = $this->createNewTestPage( "MyWatchListTest", true );
         // Verify link 'My Watchlist' available
-        $this->assertTrue( $this->isElementPresent( "link=My watchlist" ) );
+        $this->assertTrue( $this->isElementPresent( "link=Watchlist" ) );
 
-        $this->click( "link=My watchlist" );
-        $this->waitForPageToLoad( "30000" );
+        $this->click( "link=Watchlist" );
+        $this->waitForPageToLoad( WIKI_TEST_WAIT_TIME );
 
         // Verify newly added page to the watchlist is available
-        $watchList = $this->getText( "//*[@id='bodyContent']" );
-        $this->assertContains( $displayName, $watchList );
+        $this->assertEquals( $pageName, $this->getText( "link=".$pageName ));
 
-        $this->type( "searchInput", $newPage );
-        $this->click( "searchGoButton" );
-        $this->waitForPageToLoad( "30000" );
-        $this->click("link=Edit");
-        $this->waitForPageToLoad( "30000" );
+        $this->click( "link=".$pageName );
+        $this->waitForPageToLoad( WIKI_TEST_WAIT_TIME );
+        $this->click( LINK_EDIT );
+        $this->waitForPageToLoad( WIKI_TEST_WAIT_TIME );
         $this->click( "wpWatchthis" );
-        $this->click( "wpSave" );
-        $this->deletePage( $newPage );
+        $this->click( BUTTON_SAVE );
+        $this->assertFalse( $this->isElementPresent( "link=".$pageName ) );
+        //todo watch using the dropdown menu
     }
 }