Index: trunk/phase3/tests/selenium/SeleniumTestCase.php |
— | — | @@ -1,4 +1,6 @@ |
2 | 2 | <?php |
| 3 | +include("SeleniumTestConstants.php"); |
| 4 | + |
3 | 5 | class SeleniumTestCase extends PHPUnit_Framework_TestCase { // PHPUnit_Extensions_SeleniumTestCase |
4 | 6 | protected $selenium; |
5 | 7 | |
— | — | @@ -26,78 +28,100 @@ |
27 | 29 | $this->assertRegExp( "/$text/", $innerHTML ); |
28 | 30 | } |
29 | 31 | |
30 | | -//Common Funtions Added for Selenium Tests |
31 | 32 | |
32 | | - public function getExistingPage(){ |
33 | | - $this->open( $this->getUrl() . |
34 | | - '/index.php?title=Main_Page&action=edit' ); |
35 | | - $this->type("searchInput", "new" ); |
36 | | - $this->click("searchGoButton"); |
37 | | - $this->waitForPageToLoad("30000"); |
38 | | - } |
| 33 | + /** |
| 34 | + * Create a test fixture page if one does not exist |
| 35 | + * @param $pageName The fixture page name. If none is supplied, it uses WIKI_INTERNAL_LINK |
| 36 | + */ |
| 37 | + function createTestPageIfMissing( $pageName = null ) { |
| 38 | + if ( $pageName == null ) { |
| 39 | + $pageName = WIKI_INTERNAL_LINK; |
| 40 | + } |
| 41 | + $this->type( INPUT_SEARCH_BOX, $pageName ); |
| 42 | + $this->click( BUTTON_SEARCH ); |
| 43 | + $this->waitForPageToLoad( WIKI_TEST_WAIT_TIME ); |
| 44 | + $this->click( LINK_START . $pageName ); |
| 45 | + $this->waitForPageToLoad( WIKI_TEST_WAIT_TIME ); |
| 46 | + $location = $this->getLocation() . "\n"; |
| 47 | + if ( strpos( $location, '&redlink=1') !== false ) { |
| 48 | + $this->type( TEXT_EDITOR, "Test fixture page. No real content here" ); |
| 49 | + $this->click( BUTTON_SAVE ); |
| 50 | + $this->waitForPageToLoad( WIKI_TEST_WAIT_TIME ); |
| 51 | + $this->assertTrue( $this->isTextPresent( $pageName ), |
| 52 | + $this->getText( TEXT_PAGE_HEADING ) ); |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + /** |
| 57 | + * Create a test page using date as part of the name so that it is unique |
| 58 | + * @param $pagePrefix The prefix to use for the page name. The current date will be appended to this to make it unique |
| 59 | + * @param $watchThis Whether to add the page to my watchlist. Defaults to false. |
| 60 | + */ |
| 61 | + function createNewTestPage( $pagePrefix, $watchThis = false ) { |
| 62 | + $pageName = $pagePrefix . date("Ymd-His"); |
| 63 | + $this->type( INPUT_SEARCH_BOX, $pageName ); |
| 64 | + $this->click( BUTTON_SEARCH ); |
| 65 | + $this->waitForPageToLoad( WIKI_TEST_WAIT_TIME ); |
| 66 | + $this->click( LINK_START . $pageName ); |
| 67 | + $this->waitForPageToLoad( WIKI_TEST_WAIT_TIME ); |
| 68 | + $location = $this->getLocation() . "\n"; |
| 69 | + $this->assertContains( '&redlink=1', $location ). |
| 70 | + $this->type( TEXT_EDITOR, "Test fixture page. No real content here" ); |
| 71 | + if ( $watchThis ) { |
| 72 | + $this->click( "wpWatchthis" ); |
| 73 | + } |
| 74 | + $this->click( BUTTON_SAVE ); |
| 75 | + $this->waitForPageToLoad( WIKI_TEST_WAIT_TIME ); |
| 76 | + $this->assertTrue( $this->isTextPresent( $pageName ), |
| 77 | + $this->getText( TEXT_PAGE_HEADING ) ); |
| 78 | + return $pageName; |
| 79 | + } |
39 | 80 | |
40 | | - public function getNewPage($pageName){ |
41 | | - |
42 | | - $this->open( $this->getUrl() . |
| 81 | + public function getExistingPage(){ |
| 82 | + $this->open( $this->getUrl() . |
43 | 83 | '/index.php?title=Main_Page&action=edit' ); |
44 | | - $this->type("searchInput", $pageName ); |
45 | | - $this->click("searchGoButton"); |
46 | | - $this->waitForPageToLoad("30000"); |
47 | | - $this->click("link=".$pageName); |
48 | | - $this->waitForPageToLoad("600000"); |
| 84 | + $this->type("searchInput", "new" ); |
| 85 | + $this->click("searchGoButton"); |
| 86 | + $this->waitForPageToLoad("30000"); |
| 87 | + } |
49 | 88 | |
| 89 | + public function getNewPage($pageName){ |
50 | 90 | |
51 | | - } |
52 | | - // Loading the mediawiki editor |
53 | | - public function loadWikiEditor(){ |
54 | | - $this->open( $this->getUrl() . |
| 91 | + $this->open( $this->getUrl() . |
55 | 92 | '/index.php?title=Main_Page&action=edit' ); |
56 | | - } |
| 93 | + $this->type("searchInput", $pageName ); |
| 94 | + $this->click("searchGoButton"); |
| 95 | + $this->waitForPageToLoad("30000"); |
| 96 | + $this->click("link=".$pageName); |
| 97 | + $this->waitForPageToLoad("600000"); |
57 | 98 | |
58 | | - // Clear the content of the mediawiki editor |
59 | | - public function clearWikiEditor(){ |
60 | | - $this->type("wpTextbox1", ""); |
61 | | - } |
62 | 99 | |
63 | | - // Click on the 'Show preview' button of the mediawiki editor |
64 | | - public function clickShowPreviewBtn(){ |
65 | | - $this->click("wpPreview"); |
66 | | - } |
67 | | - |
68 | | - // Click on the 'Save Page' button of the mediawiki editor |
69 | | - public function clickSavePageBtn(){ |
70 | | - $this->click("wpSave"); |
71 | | - } |
72 | | - |
73 | | - // Click on the 'Edit' link |
74 | | - public function clickEditLink(){ |
75 | | - $this->click("link=Edit"); |
76 | | - $this->waitForPageToLoad("30000"); |
77 | | - } |
78 | | - |
79 | | - public function deletePage($pageName){ |
80 | | - $isLinkPresent = False; |
81 | | - $this->open( $this->getUrl() . |
| 100 | + } |
| 101 | + // Loading the mediawiki editor |
| 102 | + public function loadWikiEditor(){ |
| 103 | + $this->open( $this->getUrl() . |
82 | 104 | '/index.php?title=Main_Page&action=edit' ); |
83 | | - $this->click("link=Log out"); |
84 | | - $this->waitForPageToLoad( "30000" ); |
85 | | - $this->click( "link=Log in / create account" ); |
86 | | - $this->waitForPageToLoad( "30000" ); |
87 | | - $this->type( "wpName1", "nadeesha" ); |
88 | | - $this->type( "wpPassword1", "12345" ); |
89 | | - $this->click( "wpLoginAttempt" ); |
90 | | - $this->waitForPageToLoad( "30000" ); |
91 | | - $this->type( "searchInput", $pageName ); |
92 | | - $this->click( "searchGoButton"); |
93 | | - $this->waitForPageToLoad( "30000" ); |
| 105 | + } |
94 | 106 | |
95 | | - $this->click( "link=Delete" ); |
96 | | - $this->waitForPageToLoad( "30000" ); |
97 | | - $this->click( "wpConfirmB" ); |
98 | | - $this->waitForPageToLoad( "30000" ); |
| 107 | + // Clear the content of the mediawiki editor |
| 108 | + public function clearWikiEditor(){ |
| 109 | + $this->type("wpTextbox1", ""); |
| 110 | + } |
99 | 111 | |
100 | | - } |
| 112 | + // Click on the 'Show preview' button of the mediawiki editor |
| 113 | + public function clickShowPreviewBtn(){ |
| 114 | + $this->click("wpPreview"); |
| 115 | + } |
101 | 116 | |
| 117 | + // Click on the 'Save Page' button of the mediawiki editor |
| 118 | + public function clickSavePageBtn(){ |
| 119 | + $this->click("wpSave"); |
| 120 | + } |
102 | 121 | |
| 122 | + // Click on the 'Edit' link |
| 123 | + public function clickEditLink(){ |
| 124 | + $this->click("link=Edit"); |
| 125 | + $this->waitForPageToLoad("30000"); |
| 126 | + } |
103 | 127 | |
104 | 128 | } |
Index: trunk/phase3/tests/selenium/SeleniumTestConstants.php |
— | — | @@ -0,0 +1,20 @@ |
| 2 | +<?php |
| 3 | +define ('WIKI_TEST_WAIT_TIME', "3000"); // Waiting time |
| 4 | + |
| 5 | +//commonly used links |
| 6 | +define ('LINK_MAIN_PAGE',"link=Main page"); |
| 7 | +define ('LINK_RANDOM_PAGE',"link=Random article"); |
| 8 | +define ('TEXT_PAGE_HEADING',"firstHeading"); |
| 9 | + |
| 10 | +define ('LINK_START',"link="); |
| 11 | +define ('TEXT_EDITOR',"wpTextbox1"); |
| 12 | +define ('LINK_PREVIEW',"wpPreview"); |
| 13 | +define ('LINK_EDIT',"link=Edit"); |
| 14 | + |
| 15 | +define ('WIKI_SEARCH_PAGE',"Hair (musical)"); // Page name to search |
| 16 | +define ('WIKI_TEXT_SEARCH',"TV"); // Text to search |
| 17 | +define ('WIKI_INTERNAL_LINK',"Wikieditor-Fixture-Page"); // Exisiting page name to add as an internal tag |
| 18 | + |
| 19 | +define ('INPUT_SEARCH_BOX', "searchInput"); |
| 20 | +define ('BUTTON_SEARCH',"mw-searchButton"); |
| 21 | +define ('BUTTON_SAVE',"wpSave"); |
Index: trunk/phase3/tests/selenium/suites/MyContributionsTestCase.php |
— | — | @@ -32,45 +32,32 @@ |
33 | 33 | // Verify user contributions |
34 | 34 | public function testRecentChangesAvailability() { |
35 | 35 | |
36 | | - $newPage = "mypage999"; |
37 | | - $displayName = "Mypage999"; |
38 | | - |
39 | | - $this->open( $this->getUrl() . |
40 | | - '/index.php?title=Main_Page&action=edit' ); |
41 | | - |
42 | | - $this->type( "searchInput", $newPage); |
43 | | - $this->click( "searchGoButton" ); |
44 | | - $this->waitForPageToLoad( "60000" ); |
45 | | - $this->click( "link=".$displayName ); |
46 | | - $this->waitForPageToLoad( "600000" ); |
47 | | - $this->type( "wpTextbox1", $newPage." text" ); |
48 | | - $this->click( "wpSave" ); |
49 | | - $this->waitForPageToLoad( "60000" ); |
50 | | - |
| 36 | + $newPage = $this->createNewTestPage( "MyContributionsTest" ); |
| 37 | + |
51 | 38 | // Verify My contributions Link available |
52 | | - $this->assertTrue($this->isElementPresent( "link=My contributions" )); |
| 39 | + $this->assertTrue($this->isElementPresent( "link=Contributions" )); |
53 | 40 | |
54 | | - $this->click( "link=My contributions" ); |
55 | | - $this->waitForPageToLoad( "30000" ); |
| 41 | + |
| 42 | + $this->click( "link=Contributions" ); |
| 43 | + $this->waitForPageToLoad( WIKI_TEST_WAIT_TIME ); |
56 | 44 | |
57 | 45 | // Verify recent page adding available on My Contributions list |
58 | | - $this->assertEquals( $displayName, $this->getText( "link=".$displayName )); |
| 46 | + $this->assertEquals( $newPage, $this->getText( "link=".$newPage )); |
59 | 47 | |
60 | | - $this->type( "searchInput", $newPage ); |
61 | | - $this->click( "searchGoButton" ); |
62 | | - $this->waitForPageToLoad( "30000" ); |
| 48 | + $this->type( INPUT_SEARCH_BOX, $newPage ); |
| 49 | + $this->click( BUTTON_SEARCH ); |
| 50 | + $this->waitForPageToLoad( WIKI_TEST_WAIT_TIME ); |
| 51 | + |
| 52 | + $this->click( LINK_EDIT ); |
| 53 | + $this->waitForPageToLoad( WIKI_TEST_WAIT_TIME ); |
| 54 | + $this->type( TEXT_EDITOR, $newPage . " text changed" ); |
| 55 | + $this->click( BUTTON_SAVE ); |
| 56 | + $this->waitForPageToLoad( WIKI_TEST_WAIT_TIME ); |
| 57 | + $this->click( "link=Contributions" ); |
| 58 | + $this->waitForPageToLoad( WIKI_TEST_WAIT_TIME ); |
63 | 59 | |
64 | | - $this->click( "link=Edit" ); |
65 | | - $this->waitForPageToLoad( "30000" ); |
66 | | - $this->type( "wpTextbox1", $newPage." text changed" ); |
67 | | - $this->click( "wpSave" ); |
68 | | - $this->waitForPageToLoad( "30000" ); |
69 | | - $this->click( "link=My contributions" ); |
70 | | - $this->waitForPageToLoad( "30000" ); |
71 | | - |
72 | 60 | // Verify recent page changes available on My Contributions |
73 | | - $this->assertTrue($this->isTextPresent($displayName." (top)")); |
74 | | - $this->deletePage($newPage); |
| 61 | + $this->assertTrue( $this->isTextPresent( $newPage ) ); |
75 | 62 | } |
76 | 63 | } |
77 | 64 | |
Index: trunk/phase3/tests/selenium/suites/MyWatchListTestCase.php |
— | — | @@ -33,41 +33,24 @@ |
34 | 34 | // Verify user watchlist |
35 | 35 | public function testMyWatchlist() { |
36 | 36 | |
37 | | - $newPage = "mypage"; |
38 | | - $displayName = "Mypage"; |
39 | | - $wikiText = "watch page"; |
40 | | - |
41 | | - $this->open( $this->getUrl().'/index.php?title=Main_Page' ); |
42 | | - |
43 | | - $this->type( "searchInput", $newPage ); |
44 | | - $this->click( "searchGoButton" ); |
45 | | - $this->waitForPageToLoad( "30000" ); |
46 | | - $this->click( "link=".$displayName ); |
47 | | - $this->waitForPageToLoad( "600000" ); |
48 | | - |
49 | | - $this->click( "wpWatchthis" ); |
50 | | - $this->type( "wpTextbox1",$wikiText ); |
51 | | - $this->click( "wpSave" ); |
52 | | - $this->waitForPageToLoad( "30000" ); |
53 | | - |
| 37 | + $pageName = $this->createNewTestPage( "MyWatchListTest", true ); |
54 | 38 | // Verify link 'My Watchlist' available |
55 | | - $this->assertTrue( $this->isElementPresent( "link=My watchlist" ) ); |
| 39 | + $this->assertTrue( $this->isElementPresent( "link=Watchlist" ) ); |
56 | 40 | |
57 | | - $this->click( "link=My watchlist" ); |
58 | | - $this->waitForPageToLoad( "30000" ); |
| 41 | + $this->click( "link=Watchlist" ); |
| 42 | + $this->waitForPageToLoad( WIKI_TEST_WAIT_TIME ); |
59 | 43 | |
60 | 44 | // Verify newly added page to the watchlist is available |
61 | | - $watchList = $this->getText( "//*[@id='bodyContent']" ); |
62 | | - $this->assertContains( $displayName, $watchList ); |
| 45 | + $this->assertEquals( $pageName, $this->getText( "link=".$pageName )); |
63 | 46 | |
64 | | - $this->type( "searchInput", $newPage ); |
65 | | - $this->click( "searchGoButton" ); |
66 | | - $this->waitForPageToLoad( "30000" ); |
67 | | - $this->click("link=Edit"); |
68 | | - $this->waitForPageToLoad( "30000" ); |
| 47 | + $this->click( "link=".$pageName ); |
| 48 | + $this->waitForPageToLoad( WIKI_TEST_WAIT_TIME ); |
| 49 | + $this->click( LINK_EDIT ); |
| 50 | + $this->waitForPageToLoad( WIKI_TEST_WAIT_TIME ); |
69 | 51 | $this->click( "wpWatchthis" ); |
70 | | - $this->click( "wpSave" ); |
71 | | - $this->deletePage( $newPage ); |
| 52 | + $this->click( BUTTON_SAVE ); |
| 53 | + $this->assertFalse( $this->isElementPresent( "link=".$pageName ) ); |
| 54 | + //todo watch using the dropdown menu |
72 | 55 | } |
73 | 56 | } |
74 | 57 | |
Index: trunk/phase3/tests/selenium/suites/MediaWikiExtraTestSuite.php |
— | — | @@ -1,20 +1,20 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | class MediaWikiExtraTestSuite extends SeleniumTestSuite { |
5 | | - public function setUp() { |
6 | | - $this->setLoginBeforeTests( true ); |
7 | | - parent::setUp(); |
8 | | - } |
9 | | - public function addTests() { |
10 | | - $testFiles = array( |
11 | | - 'tests/selenium/suites/MyContributionsTestCase.php', |
12 | | - 'tests/selenium/suites/MyWatchListTestCase.php', |
13 | | - 'tests/selenium/suites/UserPreferencesTestCase.php', |
14 | | - 'tests/selenium/suites/MovePageTestCase.php', |
15 | | - 'tests/selenium/suites/PageSearchTestCase.php', |
16 | | - 'tests/selenium/suites/EmailPasswordTestCase.php', |
17 | | - 'tests/selenium/suites/CreateAccountTestCase.php' |
18 | | - ); |
19 | | - parent::addTestFiles( $testFiles ); |
20 | | - } |
| 5 | + public function setUp() { |
| 6 | + $this->setLoginBeforeTests( true ); |
| 7 | + parent::setUp(); |
| 8 | + } |
| 9 | + public function addTests() { |
| 10 | + $testFiles = array( |
| 11 | + 'tests/selenium/suites/MyContributionsTestCase.php', |
| 12 | + 'tests/selenium/suites/MyWatchListTestCase.php', |
| 13 | + 'tests/selenium/suites/UserPreferencesTestCase.php', |
| 14 | + 'tests/selenium/suites/MovePageTestCase.php', |
| 15 | + 'tests/selenium/suites/PageSearchTestCase.php', |
| 16 | + 'tests/selenium/suites/EmailPasswordTestCase.php', |
| 17 | + 'tests/selenium/suites/CreateAccountTestCase.php' |
| 18 | + ); |
| 19 | + parent::addTestFiles( $testFiles ); |
| 20 | + } |
21 | 21 | } |