1515 */
1616package org .labkey .test .pages .assay ;
1717
18+ import org .apache .commons .lang3 .StringUtils ;
19+ import org .jetbrains .annotations .Nullable ;
1820import org .labkey .test .Locator ;
21+ import org .labkey .test .components .assay .AssayConstants ;
1922import org .labkey .test .components .html .Input ;
2023import org .labkey .test .components .html .RadioButton ;
2124import org .labkey .test .components .html .OptionSelect ;
2629
2730import java .io .File ;
2831
29-
3032public class AssayImportPage extends LabKeyPage <AssayImportPage .Elements >
3133{
3234 public AssayImportPage (WebDriver driver )
@@ -50,43 +52,83 @@ public AssayImportPage selectNamedFieldOption(String name, String text)
5052
5153 public AssayImportPage setNamedTextAreaValue (String name , String text )
5254 {
53- WebElement input = Locator .xpath ( "// textarea[@ name='" + name + "']" ).findElement (getDriver ());
55+ WebElement input = Locator .textarea ( name ).findElement (getDriver ());
5456 setFormElement (input , text );
5557 return this ;
5658 }
5759
60+ public AssayImportPage setFileField (String name , File file )
61+ {
62+ setFormElement (Locator .input (name ), file );
63+ return this ;
64+ }
65+
5866 public AssayImportPage setDataText (String text )
5967 {
6068 selectTSVRadioButton ();
61- setTextInputField (text );
62- return this ;
69+ return setTextInputField (text );
6370 }
6471
6572 private void selectTSVRadioButton ()
6673 {
6774 elementCache ().pasteTSVButton .check ();
6875 }
6976
70- private void setTextInputField (String text )
77+ private AssayImportPage setTextInputField (String text )
7178 {
7279 elementCache ().inputRunDataField .setValue (text );
80+ return this ;
7381 }
7482
75- public void setDataFile (File uploadFile )
83+ public AssayImportPage setDataFile (File uploadFile )
7684 {
7785 selectUploadFileRadioButton ();
7886 setFormElement (Locator .name ("__primaryFile__" ), uploadFile );
87+ return this ;
7988 }
8089
81- private void selectUploadFileRadioButton ()
90+ public AssayImportPage selectUploadFileRadioButton ()
8291 {
8392 elementCache ().uploadFileButton .check ();
93+ return this ;
8494 }
8595
96+ /**
97+ * Retrieves the file name for a field if it has been previously uploaded. In this case the server
98+ * will display a file name with an icon and a "[remove]" link. If a value has not been previously uploaded,
99+ * then this will look for a file input and return the value of that field.
100+ *
101+ * @param fieldName the name of the field for which the value should be retrieved
102+ * @return the value associated with the specified file field, or null if no value is found
103+ */
104+ public @ Nullable String getFileFieldValue (String fieldName )
105+ {
106+ var removeFileLink = Locator .tagWithClass ("div" , "lk-remove-file" )
107+ .withAttribute ("data-fieldname" , fieldName );
108+
109+ if (isElementPresent (removeFileLink ))
110+ {
111+ var text = removeFileLink .findElement (getDriver ()).getText ();
112+ return StringUtils .trimToNull (text .replace ("[remove]" , "" ));
113+ }
114+
115+ var fileInput = Locator .input (fieldName );
116+ if (isElementPresent (fileInput ))
117+ return getFormElement (fileInput );
118+
119+ return null ;
120+ }
86121
87122 /* button actions */
123+ public AssayImportPage clickNext ()
124+ {
125+ doAndWaitForPageToLoad (()-> elementCache ().nextButton .click ());
126+ return new AssayImportPage (getDriver ());
127+ }
128+
88129 public void clickSaveAndFinish ()
89130 {
131+ scrollIntoView (elementCache ().saveAndFinishButton , true );
90132 doAndWaitForPageToLoad (()-> elementCache ().saveAndFinishButton .click ());
91133 }
92134
@@ -115,16 +157,17 @@ protected Elements newElementCache()
115157 public class Elements extends LabKeyPage .ElementCache
116158 {
117159 final RadioButton pasteTSVButton = new RadioButton (
118- new LazyWebElement (Locator .radioButtonById ("textAreaDataProvider" ), this ));
160+ new LazyWebElement <> (Locator .radioButtonById ("textAreaDataProvider" ), this ));
119161 final RadioButton uploadFileButton = new RadioButton (
120- new LazyWebElement (Locator .radioButtonById ("FileUpload " ), this ));
162+ new LazyWebElement <> (Locator .radioButtonById ("Fileupload " ), this ));
121163 final Input inputRunDataField = new Input (
122- new LazyWebElement ( Locator . xpath ( ".//textarea[@id='TextAreaDataCollector.textArea']" ) , this ),
164+ new LazyWebElement <>( AssayConstants . TEXT_AREA_DATA_COLLECTOR_LOCATOR , this ),
123165 getDriver ());
124166
125- final WebElement saveAndFinishButton = new LazyWebElement (Locator .lkButton ("Save and Finish" ), this );
126- final WebElement saveAndImportAnotherButton = new LazyWebElement (Locator .lkButton ("Save and Import Another Run" ), this );
127- final WebElement resetDefaultValuesButton = new LazyWebElement (Locator .lkButton ("Reset Default Values" ), this );
128- final WebElement cancelButton = new LazyWebElement (Locator .lkButton ("Cancel" ), this );
167+ final WebElement nextButton = new LazyWebElement <>(Locator .lkButton ("Next" ), this );
168+ final WebElement saveAndFinishButton = new LazyWebElement <>(Locator .lkButton ("Save and Finish" ), this );
169+ final WebElement saveAndImportAnotherButton = new LazyWebElement <>(Locator .lkButton ("Save and Import Another Run" ), this );
170+ final WebElement resetDefaultValuesButton = new LazyWebElement <>(Locator .lkButton ("Reset Default Values" ), this );
171+ final WebElement cancelButton = new LazyWebElement <>(Locator .lkButton ("Cancel" ), this );
129172 }
130173}
0 commit comments