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.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.