Changeset 32705


Ignore:
Timestamp:
2018-12-17T23:33:18+13:00 (5 years ago)
Author:
ak19
Message:
  1. Implemented (and testing as I implement) more of the GSGUITestingUtil helper functions. Most of the File Menu is done. Unfortunately can't yet commit the EDT corrections in GLI as at least one of them requires a more complex solution, possibly with a SwingWorker as there's conflict with the ProgressBar. 2. infrastructure for JUnit reports. Not working yet despite the inclusion of necessary jar, will investigate this later.
Location:
gs3-extensions/testing/trunk/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • gs3-extensions/testing/trunk/src/build.xml

    r32694 r32705  
    66
    77  <property name="gli.home" value="${env.GSDL3SRCHOME}/gli"/>
     8
     9  <!-- define ext.test.folder so we can move some targets into toplevel GS3 ant build file -->
     10  <property name="ext.test.folder" value="${basedir}" />
     11 
     12  <!-- where the reports will go -->
     13  <property name="test.reports" value="${ext.test.folder}/reports" />
    814 
    915  <target name="build-util-jar" depends="needs-gs3-setup, needs-make-gli-jar">
    10     <mkdir dir="${basedir}/build"/>
    11     <javac srcdir="${basedir}/src"
    12        destdir="${basedir}/build"
     16    <mkdir dir="${ext.test.folder}/build"/>
     17    <javac srcdir="${ext.test.folder}/src"
     18       destdir="${ext.test.folder}/build"
    1319       includeantruntime="${compile.includeantruntime}">
    1420      <classpath>
    15     <fileset dir="${basedir}/lib/java">
     21    <fileset dir="${ext.test.folder}/lib/java">
    1622      <include name="*.jar"/>
    1723    </fileset>
     
    2228      <include name="org/greenstone/gsdl3/testing/*.java"/>         
    2329    </javac>
    24     <jar destfile="${basedir}/lib/java/GSTestingUtil.jar">
    25       <fileset dir="${basedir}/build">
     30    <jar destfile="${ext.test.folder}/lib/java/GSTestingUtil.jar">
     31      <fileset dir="${ext.test.folder}/build">
    2632    <include name="org/greenstone/gsdl3/testing/**"/>             
    2733      </fileset>
     
    5864<target name="compile-tutorials-tests" depends="needs-gs3-setup, needs-make-gli-jar">
    5965
    60   <mkdir dir="${basedir}/build"/>
     66  <mkdir dir="${ext.test.folder}/build"/>
    6167  <javac
    62       srcdir="${basedir}/src"
    63       destdir="${basedir}/build"
     68      srcdir="${ext.test.folder}/src"
     69      destdir="${ext.test.folder}/build"
    6470      includeantruntime="${compile.includeantruntime}">
    6571    <classpath>
    66       <fileset dir="${basedir}/lib/java">
     72      <fileset dir="${ext.test.folder}/lib/java">
    6773    <include name="*.jar"/>
    6874      </fileset>
     
    7379    <include name="gstests/tutorials/*.java"/>
    7480  </javac>
    75   <jar destfile="${basedir}/tutorial-tests.jar">
    76     <fileset dir="${basedir}/build">
     81  <jar destfile="${ext.test.folder}/tutorial-tests.jar">
     82    <fileset dir="${ext.test.folder}/build">
    7783      <include name="gstests/tutorials/**"/>
    7884    </fileset>
     
    8490
    8591<!-- https://stackoverflow.com/questions/10704324/how-to-add-to-classpath-all-classes-from-set-of-directories-in-ant -->
    86 <path id="tutorials.path"> 
    87   <fileset dir="${basedir}/lib/java">
     92<path id="tutorials.path">
     93
     94  <!-- Includes ant-nodeps-1.8.1 from 2010 that replaces 2005's optional.jar of ant
     95       for generating reports -->
     96  <fileset dir="${ext.test.folder}/lib/java">
    8897    <include name="*.jar"/>
    8998  </fileset>
    90   <!--<fileset dir="${basedir}/build">     
     99  <!--<fileset dir="${ext.test.folder}/build">     
    91100    <include name="gstests/tutorials/**/*.class"/>
    92101  </fileset>-->
    93   <files includes="${basedir}/tutorial-tests.jar"/>
     102  <files includes="${ext.test.folder}/tutorial-tests.jar"/>
    94103
    95104  <!-- To run GLI, need GLI.jar and its help jars and folder: classes folder, apache.jar, jna.jar, jna-platform.jar, qfslib.jar, rsyntaxtextarea.jar -->
     
    114123  <java classname="org.junit.runner.JUnitCore" dir="${gli.home}" fork="true" maxmemory="256m" classpathref="tutorials.path">
    115124    <!--https://stackoverflow.com/questions/38676719/selenium-using-java-the-path-to-the-driver-executable-must-be-set-by-the-webdr-->
    116     <sysproperty key="webdriver.gecko.driver" path="${basedir}/geckodriver"/>
     125    <sysproperty key="webdriver.gecko.driver" path="${ext.test.folder}/geckodriver"/>
    117126    <arg value="gstests.tutorials.RunGLITest"/>
    118127    <!-- TODO: for now hardcoding the GS3 URL. Toplevel build.xml can properly construct this
     
    120129    <jvmarg value="-DSERVERURL=http://127.0.0.1:8383/greenstone3/library "/>
    121130  </java>
    122  
    123  
     131
     132  <!-- create reports dir if it doesn't exist -->
     133  <mkdir dir="${test.reports}"/>
     134  <!--
     135      https://junit.org/junit4/faq.html#running_6
     136      How do I use Ant to create HTML test reports?
     137  -->
     138  <junitreport todir="${test.reports}">
     139    <fileset dir="${test.reports}">
     140      <include name="TEST-*.xml" />
     141    </fileset>
     142    <report todir="${test.reports}" />
     143  </junitreport>
    124144</target>
     145
     146<!-- TODO: check if after testing GLI we may need to ensure tomcat stopped? -->
    125147
    126148</project>
  • gs3-extensions/testing/trunk/src/src/gstests/tutorials/RunGLITest.java

    r32701 r32705  
    1313- https://web.archive.org/web/20120526191520/http://alexruiz.developerblogs.com/?p=160
    1414- https://web.archive.org/web/20130218063544/http://weblogs.java.net/blog/alexfromsun/archive/2006/02/debugging_swing.html
     15- https://stackoverflow.com/questions/2829364/java-difference-between-swingworker-and-swingutilities-invokelater
    1516
    1617Got AssertJ Swing from Maven Central Repository:
     
    117118
    118119     
    119       // waiting 2 seconds for window, so we can see it
    120       try{
    121     Thread.sleep(5000);
    122       } catch(Exception e) {
    123       e.printStackTrace();
    124       }
     120      // waiting a few seconds for window, so we can see it
     121      PAUSE(2);
    125122     
    126123   
     
    131128
    132129      window = findFrame("GUIManager").using(robot());
    133        
    134     String gatherPaneLabel = Dictionary.get("GUI.Gather");
    135     System.err.println("@@@ Expecting label: " + gatherPaneLabel);
     130     
     131      String gatherPaneLabel = Dictionary.get("GUI.Gather");
     132      System.err.println("@@@ Expecting label: " + gatherPaneLabel);
     133     
     134      System.err.println("@@@ Second test: that Gather panel is selected and has right title");
     135     
     136      JTabbedPaneFixture tab = window.tabbedPane("GUIManager.tab_pane");
     137     
     138     
     139      tab.requireSelectedTab(Index.atIndex(1));
     140      tab.requireTitle(gatherPaneLabel, Index.atIndex(1));
     141     
     142      // attempt to switch to enrich pane, uses static methods of GSGUITestingUtil
     143      // through static import of that class
     144      switchToPane(window, DOWNLOAD_PANE);
    136145
    137     System.err.println("@@@ Second test: that Gather panel is selected and has right title");
     146      // For testing, want GLI to be in librarian mode by default
     147      changeUserMode(window, "librarian");
    138148
    139     JTabbedPaneFixture tab = window.tabbedPane("GUIManager.tab_pane");
     149      switchToPane(window, GATHER_PANE);
     150     
     151      loadCollection(window, "lucene-jdbm-demo");
    140152
    141    
    142     tab.requireSelectedTab(Index.atIndex(1));
    143     tab.requireTitle(gatherPaneLabel, Index.atIndex(1));
     153      // wait a couple of seconds again?
     154      PAUSE(2);     
     155      closeCollection(window);
     156     
     157      createCollection(window, "pinky", "Pinky was here", null);
     158      closeCollection(window); // collection must be closed in order to be deleted
     159      deleteCollection(window, "pinky");
     160      // wait a few of seconds again?
     161      PAUSE(2);
     162     
     163      exportCollection(window, "GreenstoneMETS", "lucene-jdbm-demo");
    144164
    145     // attempt to switch to enrich pane, uses static methods of GSGUITestingUtil
    146     // through static import of that class
    147     switchToPane(window, DOWNLOAD_PANE);
    148 
    149     loadCollection(window, "lucene-jdbm-demo");
    150 
    151     // wait a couple of seconds again?
    152      try{
    153          Thread.sleep(5000);
    154      } catch(Exception e) {
    155          e.printStackTrace();
    156      }
     165      // Reset GLI to expert mode for regular GLI use
     166      changeUserMode(window, "expert");
    157167     
    158    
     168      PAUSE(5);
     169      //exitGLI(window);
     170     
     171      switchToPane(window, GATHER_PANE);
    159172  }
    160173
     
    165178    {
    166179    _driver.quit();
     180   
    167181    }
    168182}
  • gs3-extensions/testing/trunk/src/src/org/greenstone/gsdl3/testing/GSGUITestingUtil.java

    r32701 r32705  
    11package org.greenstone.gsdl3.testing;
    22
     3import java.io.File;
    34import java.util.Map;
     5import java.util.regex.*;
    46import java.awt.Component;
    57
     
    79import org.junit.Assert;
    810import org.assertj.swing.fixture.*;
     11import org.assertj.swing.timing.Timeout ;
     12       
    913
    1014// GLI imports
     
    1822
    1923public class GSGUITestingUtil
    20 {
     24{
     25    public static final boolean PAUSE_ON = true;
     26   
     27    public static final int SECOND = 1000; // 1000 ms
     28   
    2129    public static final String DOWNLOAD_PANE = "Download";
    2230    public static final String GATHER_PANE = "Gather";
     
    3341
    3442    /************************ GENERAL *******************************/
     43    public static void PAUSE() {   
     44    PAUSE(5);
     45    }
     46    public static void PAUSE(int seconds) {
     47    if(!PAUSE_ON) return; // ignore calls to PAUSE
     48   
     49    // wait a couple of seconds again?
     50     try{
     51         Thread.sleep(seconds*SECOND);
     52     } catch(Exception e) {
     53         e.printStackTrace();
     54     }
     55    }
     56   
     57   
    3558    //https://joel-costigliola.github.io/assertj/swing/api/org/assertj/swing/fixture/FrameFixture.html
    3659    public static void switchToPane(FrameFixture window, String pane) {
     
    4972    }
    5073
     74    /*
     75    public static void stealAnyLock(FrameFixture window) {
     76    DialogFixture dialog = window.dialog("LockFileDialog");
     77    if(dialog != null) {
     78        dialog.button("LockFileDialog.ok_button").click();
     79    }
     80    }*/
     81
     82   
    5183    // e.g. pane = Enrich,view=collection; pane = Gather, view = workspace (or collection)
    5284    public static void getFolderPath(String pane, String view, String folderPath) {}
     
    5486   
    5587    /**********************FILE MENU*******************************/
    56     public static void setPrefs(String tab, Map params) {}
    57     // mode e.g. librarian, expert
    58     public static void changeUserMode(String mode) {}
    59    
    60     public static void deleteCollection(){}
    61     public static void saveCollection(){}
    62     public static void closeCollection(){}   
    63     public static void createCollection(String basedOn) {}   
    64     public static void loadCollection(FrameFixture window, String colName) {
     88    public static void setPrefs(FrameFixture window, String tab, Map params) {
     89    openMenuItem(window, "file", "options");
     90
     91    }
     92   
     93    /**
     94     * @param toMode must be the dictionary key for Preferences mode.
     95     * Choose from Preferences.Mode.Assistant, Preferences.Mode.Librarian, Preferences.Mode.Expert
     96     */
     97    public static void changeUserMode(FrameFixture window, String toMode) {
     98    openMenuItem(window, "file", "options"); // click MenuBar.file -> MenuBar.file_options
     99
     100    // switch to Mode tab
     101    String paneLabel = Dictionary.get("Preferences.Mode");
     102    DialogFixture dialog = window.dialog("Preferences");
     103    JTabbedPaneFixture tab = window.tabbedPane("Preferences.tab_pane");
     104    tab.selectTab(paneLabel); // select tab by its title
     105
     106    String mode = "assistant"; // library assistant
     107    if(toMode.contains("xpert")) {
     108        mode = "expert";
     109    } else if (toMode.endsWith("ibrarian")) {
     110        mode = "librarian";
     111    }
     112    dialog.radioButton("Preferences."+mode+"_mode_radio_button").check(true);
     113
     114    // apply and close dialog
     115    dialog.button("Preferences.apply_button").click();
     116    dialog.button("Preferences.ok_button").click();
     117    }
     118
     119    public static void exitGLI(FrameFixture window) {
     120    openMenuItem(window, "file", "exit");
     121    PAUSE(5);
     122    }
     123   
     124    public static void closeCollection(FrameFixture window){
     125    // Through componennt names, clicks on MenuBar.file then MenuBar.file_close
     126    openMenuItem(window, "file", "close");
     127    }
     128
     129    public static void deleteCollection(FrameFixture window, String collName) {
     130    openMenuItem(window, "file", "delete");
     131    DialogFixture dialog = window.dialog("DeleteCollectionPrompt"); // could call window.dialg() too as there will be only one, unless GLI run in debug mode?
     132   
     133    JListFixture collection_list = dialog.list("DeleteCollectionPrompt.list");
     134   
     135    Pattern collNameRegex = Pattern.compile(".*"+collName+".*");
     136    collection_list.selectItem(collNameRegex);
     137   
     138    collection_list.requireSelection(collNameRegex); // assert it exists and is selectable. Can't select (or delete) coll if it's open
     139   
     140    dialog.checkBox("DeleteCollectionPrompt.confirmation").check(true); // check checkbox to be sure to delete
     141    dialog.button("DeleteCollectionPrompt.ok_button").click(); // delete button
     142
     143    // A close confirmation optionPane dialog appears - click OK in it
     144    dialog.optionPane().okButton().click();
     145   
     146    dialog.button("DeleteCollectionPrompt.close_button").click(); // close deleteColl dialog
     147    }
     148   
     149    public static void saveCollection(FrameFixture window) {
     150    openMenuItem(window, "file", "save"); // MenuBar.file -> MenuBar.file_save
     151    }
     152
     153    public static void createCollection(FrameFixture window,
     154                    String collTitle, String collDescription, String baseColl)
     155    {
     156    openMenuItem(window, "file", "new");
     157    DialogFixture dialog = window.dialog("col"); // GLI is unable to setName() of this dialog
     158    // to NewCollectioNDetailsPrompt. Not sure why.
     159
     160    dialog.textBox("NewCollectionDetailsPrompt.title").enterText(collTitle); // JTextField
     161    if(collDescription != null && !collDescription.equals("")) {
     162        // JTextArea description
     163        dialog.textBox("NewCollectionDetailsPrompt.description").enterText(collDescription);
     164    }
     165
     166    // JComboBox base_collection
     167    if(baseColl != null && !baseColl.equals("")) {
     168        JComboBoxFixture baseCollBox = dialog.comboBox("NewCollectionDetailsPrompt.base_collection");
     169        Pattern collNameRegex = Pattern.compile(".*"+baseColl+".*"); // comboBox should CONTAIN this string
     170        baseCollBox.selectItem(collNameRegex);
     171        baseCollBox.requireSelection(collNameRegex); // assert the baseColl name exists     
     172    }
     173    dialog.button("NewCollectionDetailsPrompt.create_button").click();
     174    }
     175
     176    public static void loadCollection(FrameFixture window, String collName) {
    65177    openMenuItem(window, "file", "open");
    66    
    67     }
    68 
    69     // only for GS2?
    70     public static void exportCollection() {}
     178    DialogFixture dialog = window.dialog("OpenCollectionDialog");
     179    JListFixture collection_list = dialog.list("OpenCollectionDialog.collection_list");
     180
     181    // See section 4.2 of http://www.vogella.com/tutorials/JavaRegularExpressions/article.html
     182    // Apparently, testing Pattern "collName" expects it to match in entirety
     183    // whereas testing ".*collName.*" will test the string contains this Pattern
     184    Pattern collNameRegex = Pattern.compile(".*"+collName+".*");
     185   
     186    /*String[] items = collection_list.contents();
     187    for(String item : items) {
     188        System.err.println("@@@ ITEM: " + item);
     189        }*/
     190   
     191
     192    //JListItemFixture collItem = collection_list.item(collNameRegex);
     193    //collItem.click();
     194    //collection_list.requireSelection(collNameRegex); // assert that the requested collection exists
     195    //collItem.doubleClick();
     196    collection_list.selectItem(collNameRegex);
     197    collection_list.requireSelection(collNameRegex); // assert that the requested collection exists
     198
     199   
     200    /*String[] selections = collection_list.selection();
     201    for(String s : selections) {
     202        System.err.println("@@@ opening collection " + s);
     203        }*/
     204
     205    JListItemFixture selectedColl = collection_list.item(collNameRegex);
     206    //collection_list.doubleClick(); // will double-click on last item regardless of what's selected
     207    selectedColl.doubleClick();
     208
     209    //steal any lock
     210    /*
     211    DialogFixture dialog = window.dialog("LockFileDialog");
     212    if(dialog != null) {
     213        dialog.button("LockFileDialog.ok_button").click();
     214    }
     215    */
     216    }
     217
     218    /**
     219     * @param exportColl has to be internal GS collection name, e.g. lucene-jdbm-demo
     220     * not public collection name like "Demo Collection".
     221     */
     222    public static void exportCollection(FrameFixture window, String exportToFormat, String exportColl)
     223    {
     224    openMenuItem(window, "file", "exportas"); // Clicks MenuBar.file -> MenuBar.file_exportas
     225
     226    DialogFixture dialog = window.dialog("ExportAsPrompt");
     227    dialog.comboBox("ExportAsPrompt.saveas_combobox").selectItem(exportToFormat);
     228   
     229    Pattern collNameRegex = Pattern.compile(".*"+exportColl+".*");
     230    JListFixture collection_list = dialog.list("ExportAsPrompt.list");
     231    collection_list.selectItem(collNameRegex); //JList of collections
     232    collection_list.requireSelection(collNameRegex); // check it exists
     233
     234    dialog.button("ExportAsPrompt.ok_button").click(); // do export
     235
     236    // first we see a progress dialog
     237   
     238    // Wait for subsequent export complete dialog
     239    DialogFixture exportCompleteDialog = window.dialog("SimpleResultDialog", Timeout.timeout(30*SECOND));
     240
     241    // non-modal dialog, so give it focus, so we can close it through its Close button
     242    exportCompleteDialog.focus();
     243   
     244    //exportCompleteDialog.button().click();
     245    exportCompleteDialog.button("SimpleResultDialog.GLIButton."+Dictionary.get("General.Close")).click(); // it only has a single button: "Close", still want to future proof if more buttons get added by specifying the particular button
     246
     247
     248    // Close outer dialog too - cancel doubles as close button now that export is complete
     249    dialog.button("ExportAsPrompt.cancel_button").click();
     250   
     251    File file = new File(System.getenv("GSDLHOME") + File.separator + "tmp" + File.separator + "exported_"+exportColl+"_"+exportToFormat);
     252
     253    Assert.assertTrue(file.exists());
     254    Assert.assertTrue(file.isDirectory()); 
     255    }
    71256   
    72257    /*************** DESIGN ******************************/
Note: See TracChangeset for help on using the changeset viewer.