Changeset 26114

Show
Ignore:
Timestamp:
16.08.2012 13:55:30 (7 years ago)
Author:
sjm84
Message:

Updating the tests so that more useful error messages are displayed

Location:
main/trunk/greenstone3/web/sites/localsite/collect/lucene-jdbm-demo/tests
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/web/sites/localsite/collect/lucene-jdbm-demo/tests/src/gstests/TestClass.java

    r26109 r26114  
    3636    public void init() 
    3737    { 
    38         _driver.get("http://localhost:8487/greenstone3/library"); 
     38        _driver.get(System.getProperty("SERVERURL")); 
    3939    } 
    4040 
     
    4646    public void testHomePage() 
    4747    { 
    48         Assert.assertNotNull(GSTestingUtil.findElementByXPath(_driver, "//div[@id='collectionLinks']/a[@title='Demonstration collection containing a few books from the Humanitarian and Development Libraries. Uses Lucene and JDBM.']")); 
     48        Assert.assertNotNull("The Demo Collection is not available", GSTestingUtil.findElementByXPath(_driver, "//div[@id='collectionLinks']/a[descendant::text()='Demo Collection']")); 
    4949    } 
    5050 
     
    5757        WebElement demoTitleElem = GSTestingUtil.findElementByXPath(_driver, "//div[@id='titlearea']/h2"); 
    5858        String title = demoTitleElem.getText(); 
    59         Assert.assertTrue(title.equals("Demo Collection")); 
     59        Assert.assertTrue("The title is incorrect", title.equals("Demo Collection")); 
    6060 
    6161        //Check we have four browsing classifiers 
    6262        List<WebElement> classifierLinks = GSTestingUtil.findElementsByXPath(_driver, "//ul[@id='gs-nav']/li"); 
    63         Assert.assertEquals(classifierLinks.size(), NUMBER_OF_CLASSIFIERS); 
     63        Assert.assertEquals("There should be " + NUMBER_OF_CLASSIFIERS + " classifiers but there were " + classifierLinks.size(), classifierLinks.size(), NUMBER_OF_CLASSIFIERS); 
    6464 
    6565        //Check we have 3 search types 
    6666        List<WebElement> searchTypes = GSTestingUtil.findElementsByXPath(_driver, "//div[@id='quicksearcharea']/ul/li"); 
    67         Assert.assertEquals(searchTypes.size(), NUMBER_OF_SEARCH_TYPES); 
     67        Assert.assertEquals("There should be " + NUMBER_OF_SEARCH_TYPES + " search types but there were " + searchTypes.size(), searchTypes.size(), NUMBER_OF_SEARCH_TYPES); 
    6868 
    6969        //Check we have 5 search indexes 
    7070        List<WebElement> searchIndexes = GSTestingUtil.findElementsByXPath(_driver, "//div[@id='quicksearcharea']/form/span[@class='textselect']/select/option"); 
    71         Assert.assertEquals(searchIndexes.size(), NUMBER_OF_SEARCH_INDEXES); 
     71        Assert.assertEquals("There should be " + NUMBER_OF_SEARCH_INDEXES + " search indexes but there were " + searchIndexes.size(), searchIndexes.size(), NUMBER_OF_SEARCH_INDEXES); 
    7272    } 
    7373 
     
    8282        //Check that we have 11 documents 
    8383        List<WebElement> documents = GSTestingUtil.findElementsByXPath(_driver, "//table[@id='classifiernodelist']/tbody/tr"); 
    84         Assert.assertEquals(documents.size(), TITLE_CLASSIFIER_SIZE); 
     84        Assert.assertEquals("There should be " + TITLE_CLASSIFIER_SIZE + " documents in the titles classifier but there were " + documents.size(), documents.size(), TITLE_CLASSIFIER_SIZE); 
    8585    } 
    8686 
     
    9595        //Check that we have 7 subjects 
    9696        List<WebElement> subjectElems = GSTestingUtil.findElementsByXPath(_driver, "//table[@id='classifiernodelist']/tbody/tr"); 
    97         Assert.assertEquals(subjectElems.size(), SUBJECT_CLASSIFIER_SIZE); 
     97        Assert.assertEquals("There should be " + SUBJECT_CLASSIFIER_SIZE + " documents in the subjects classifier but there were " + subjectElems.size(), subjectElems.size(), SUBJECT_CLASSIFIER_SIZE); 
    9898 
    9999        //Get all of the subject expand images 
     
    107107        String sectionNumber = randomSubject.getAttribute("id").substring(6); 
    108108        GSTestingUtil.waitForXPath(_driver, "//table[@id='div" + sectionNumber + "']"); 
    109         Assert.assertNotNull(GSTestingUtil.findElementByXPath(_driver, "//table[@id='div" + sectionNumber + "']")); 
     109        Assert.assertNotNull("The subjects classifier did not open correctly", GSTestingUtil.findElementByXPath(_driver, "//table[@id='div" + sectionNumber + "']")); 
    110110    } 
    111111 
     
    120120        //Check that we have 5 organisations 
    121121        List<WebElement> orgElems = GSTestingUtil.findElementsByXPath(_driver, "//table[@id='classifiernodelist']/tbody/tr"); 
    122         Assert.assertEquals(orgElems.size(), ORGANISATIONS_CLASSIFIER_SIZE); 
     122        Assert.assertEquals("There should be " + ORGANISATIONS_CLASSIFIER_SIZE + " documents in the organisations classifier but there were " + orgElems.size(), orgElems.size(), ORGANISATIONS_CLASSIFIER_SIZE); 
    123123 
    124124        //Get all of the subject expand images 
     
    132132        String sectionNumber = randomOrganisation.getAttribute("id").substring(6); 
    133133        GSTestingUtil.waitForXPath(_driver, "//table[@id='div" + sectionNumber + "']"); 
    134         Assert.assertNotNull(GSTestingUtil.findElementByXPath(_driver, "//table[@id='div" + sectionNumber + "']")); 
     134        Assert.assertNotNull("The organisations classifier did not open correctly", GSTestingUtil.findElementByXPath(_driver, "//table[@id='div" + sectionNumber + "']")); 
    135135    } 
    136136 
     
    152152        //Check the number of results on the page 
    153153        List<WebElement> results = GSTestingUtil.findElementsByXPath(_driver, "//table[@id='resultsTable']/tbody/tr"); 
    154         Assert.assertEquals(results.size(), HITS_PER_PAGE); 
     154        Assert.assertEquals("The number of results on the page should have been " + HITS_PER_PAGE + " but it was " + results.size(), results.size(), HITS_PER_PAGE); 
    155155 
    156156        //Check the term info has the correct values 
    157157        WebElement termInfo = GSTestingUtil.findElementByXPath(_driver, "//p[@class='termList']/span[@class='termInfo']"); 
    158         Assert.assertTrue(termInfo.getText().equals("snails occurs " + SNAILS_OCCURENCE_COUNT + " times in " + SNAILS_RESULT_COUNT + " sections")); 
     158        Assert.assertTrue("The term information was incorrect, it should have been \"" + "snails occurs " + SNAILS_OCCURENCE_COUNT + " times in " + SNAILS_RESULT_COUNT + " sections" + "\" but was \"" + termInfo.getText() + "\"", termInfo.getText().equals("snails occurs " + SNAILS_OCCURENCE_COUNT + " times in " + SNAILS_RESULT_COUNT + " sections")); 
    159159 
    160160        //Check the search results status bar 
    161161        WebElement searchStatus = GSTestingUtil.findElementByXPath(_driver, "//td[@id='searchResultsStatusBar']"); 
    162         Assert.assertTrue(searchStatus.getText().equals("Displaying 1 to " + HITS_PER_PAGE + " of " + SNAILS_RESULT_COUNT + " sections")); 
     162        Assert.assertTrue("The search status was incorrect, it should have been \"" + "Displaying 1 to " + HITS_PER_PAGE + " of " + SNAILS_RESULT_COUNT + " sections" + "\" but it was \"" + searchStatus.getText() + "\"", searchStatus.getText().equals("Displaying 1 to " + HITS_PER_PAGE + " of " + SNAILS_RESULT_COUNT + " sections")); 
    163163 
    164164        //Click the next button 
     
    168168        //Check the search results status bar on the new page 
    169169        searchStatus = GSTestingUtil.findElementByXPath(_driver, "//td[@id='searchResultsStatusBar']"); 
    170         Assert.assertTrue(searchStatus.getText().equals("Displaying " + (HITS_PER_PAGE + 1) + " to " + (HITS_PER_PAGE * 2) + " of " + SNAILS_RESULT_COUNT + " sections")); 
     170        Assert.assertTrue("The search status was incorrect, it should have been \"" + "Displaying " + (HITS_PER_PAGE + 1) + " to " + (HITS_PER_PAGE * 2) + " of " + SNAILS_RESULT_COUNT + " sections" + "\" but it was \"" + searchStatus.getText() + "\"", searchStatus.getText().equals("Displaying " + (HITS_PER_PAGE + 1) + " to " + (HITS_PER_PAGE * 2) + " of " + SNAILS_RESULT_COUNT + " sections")); 
    171171 
    172172        //Click the previous button 
     
    179179 
    180180        //Generate a search that will fail 
     181        String randomSearchTerm = GSTestingUtil.generateRandomString(20); 
     182 
    181183        quickSearchInput = GSTestingUtil.findElementByXPath(_driver, "//div[@id='quicksearcharea']//input[@name='s1.query']"); 
    182184        quickSearchInput.clear(); 
    183         quickSearchInput.sendKeys(GSTestingUtil.generateRandomString(20)); 
     185        quickSearchInput.sendKeys(randomSearchTerm); 
    184186        quickSearchSubmitButton = GSTestingUtil.findElementByXPath(_driver, "//input[@id='quickSearchSubmitButton']"); 
    185187        quickSearchSubmitButton.click(); 
     
    187189        //Make sure that no documents match 
    188190        WebElement contentElem = GSTestingUtil.findElementByXPath(_driver, "//div[@id='gs_content']"); 
    189         Assert.assertTrue(contentElem.getText().equals("No documents matched the query.")); 
     191        Assert.assertTrue("No results should have been found for \"" + randomSearchTerm, contentElem.getText().equals("No documents matched the query.")); 
    190192    } 
    191193 
     
    201203        //Make sure we are logged in correctly 
    202204        WebElement userListTable = GSTestingUtil.findElementByXPath(_driver, "//table[@id='userListTable']"); 
    203         Assert.assertNotNull(userListTable); 
     205        Assert.assertNotNull("Administrator failed to log in", userListTable); 
    204206 
    205207        //Go to the add new user page 
     
    241243            { 
    242244                found = true; 
    243                 Assert.assertTrue(columns.get(1).getText().equals("enabled")); 
    244                 Assert.assertTrue(columns.get(2).getText().equals("TestGroup")); 
    245                 Assert.assertTrue(columns.get(3).getText().equals("A user added for testing purposes")); 
    246                 Assert.assertTrue(columns.get(4).getText().equals(randomUsername + "@testusername.co.nz")); 
     245                Assert.assertTrue("The new user enabled status was incorrect", columns.get(1).getText().equals("enabled")); 
     246                Assert.assertTrue("The new user group was incorrect", columns.get(2).getText().equals("TestGroup")); 
     247                Assert.assertTrue("The new user comment was incorrect", columns.get(3).getText().equals("A user added for testing purposes")); 
     248                Assert.assertTrue("The new user email was incorrect", columns.get(4).getText().equals(randomUsername + "@testusername.co.nz")); 
    247249            } 
    248250        } 
    249         Assert.assertTrue(found); 
     251        Assert.assertTrue("The new user was not found", found); 
    250252 
    251253        //Log in as the new user 
     
    255257        //Check the log in worked 
    256258        WebElement menuButton = GSTestingUtil.findElementByXPath(_driver, "//li[@id='userMenuButton']/a"); 
    257         Assert.assertTrue(menuButton.getText().equals(randomUsername)); 
     259        Assert.assertTrue("The new user was not able to log in correctly", menuButton.getText().equals(randomUsername)); 
    258260 
    259261        //Go to the home page 
     
    310312        //Check the cover image is loaded 
    311313        WebElement coverImage = GSTestingUtil.findElementByXPath(_driver, "//div[@id='coverImage']/img"); 
    312         Assert.assertTrue(GSTestingUtil.isImageLoaded(_driver, coverImage)); 
     314        Assert.assertTrue("The cover image of the document did not load correctly", GSTestingUtil.isImageLoaded(_driver, coverImage)); 
    313315    } 
    314316