From 14959b25f556ad1f73ba755fd34b390b62acffe9 Mon Sep 17 00:00:00 2001
From: anttil <anttil>
Date: Wed, 26 Sep 2012 08:42:52 +0000
Subject: [PATCH] SWE-2 / SP-263: Configuring of columns of sample browser if a
 needed column is not visible

SVN: 26814
---
 .../uitest/page/tab/SampleBrowser.java        | 16 ++++-
 .../openbis/uitest/suite/SeleniumTest.java    |  6 ++
 .../cisd/openbis/uitest/suite/SprintTest.java |  2 +-
 .../openbis/uitest/widget/PagingToolBar.java  |  9 +++
 .../openbis/uitest/widget/SettingsDialog.java | 62 +++++++++++++++++++
 5 files changed, 93 insertions(+), 2 deletions(-)
 create mode 100644 ui-test/source/java/ch/systemsx/cisd/openbis/uitest/widget/SettingsDialog.java

diff --git a/ui-test/source/java/ch/systemsx/cisd/openbis/uitest/page/tab/SampleBrowser.java b/ui-test/source/java/ch/systemsx/cisd/openbis/uitest/page/tab/SampleBrowser.java
index 5cdf7c5c991..6fa74e81adb 100644
--- a/ui-test/source/java/ch/systemsx/cisd/openbis/uitest/page/tab/SampleBrowser.java
+++ b/ui-test/source/java/ch/systemsx/cisd/openbis/uitest/page/tab/SampleBrowser.java
@@ -27,6 +27,7 @@ import ch.systemsx.cisd.openbis.uitest.widget.DropDown;
 import ch.systemsx.cisd.openbis.uitest.widget.FilterToolBar;
 import ch.systemsx.cisd.openbis.uitest.widget.Grid;
 import ch.systemsx.cisd.openbis.uitest.widget.PagingToolBar;
+import ch.systemsx.cisd.openbis.uitest.widget.SettingsDialog;
 
 public class SampleBrowser implements Browser<Sample>
 {
@@ -50,6 +51,10 @@ public class SampleBrowser implements Browser<Sample>
     @Locate("openbis_sample-browser_main-grid-filter-toolbar")
     private FilterToolBar filters;
 
+    @Lazy
+    @Locate("entity-browser-grid-SAMPLE-(all)")
+    private SettingsDialog settings;
+
     public void addSample()
     {
         addSample.click();
@@ -79,7 +84,16 @@ public class SampleBrowser implements Browser<Sample>
     @Override
     public BrowserCell cell(Sample sample, String column)
     {
-        return select(sample).get(column);
+        BrowserCell c = select(sample).get(column);
+        if (c == null)
+        {
+            paging.settings();
+            settings.showColumns("Code", column);
+            return select(sample).get(column);
+        } else
+        {
+            return c;
+        }
     }
 
     @Override
diff --git a/ui-test/source/java/ch/systemsx/cisd/openbis/uitest/suite/SeleniumTest.java b/ui-test/source/java/ch/systemsx/cisd/openbis/uitest/suite/SeleniumTest.java
index 0f9b5c89c31..9624208e2d1 100644
--- a/ui-test/source/java/ch/systemsx/cisd/openbis/uitest/suite/SeleniumTest.java
+++ b/ui-test/source/java/ch/systemsx/cisd/openbis/uitest/suite/SeleniumTest.java
@@ -130,6 +130,12 @@ public abstract class SeleniumTest
             dssUrl = "http://localhost:8889";
         }
 
+        /*
+        asUrl = "https://sprint-openbis.ethz.ch/openbis";
+        dssUrl = "https://sprint-openbis.ethz.ch";
+        startPage = asUrl;
+        */
+    
         System.out.println("asUrl: " + asUrl);
         System.out.println("dssUrl: " + dssUrl);
         System.out.println("startPage: " + startPage);
diff --git a/ui-test/source/java/ch/systemsx/cisd/openbis/uitest/suite/SprintTest.java b/ui-test/source/java/ch/systemsx/cisd/openbis/uitest/suite/SprintTest.java
index 2b989e517d2..137d896da57 100644
--- a/ui-test/source/java/ch/systemsx/cisd/openbis/uitest/suite/SprintTest.java
+++ b/ui-test/source/java/ch/systemsx/cisd/openbis/uitest/suite/SprintTest.java
@@ -39,7 +39,7 @@ import ch.systemsx.cisd.openbis.uitest.type.Vocabulary;
 public class SprintTest extends SeleniumTest
 {
 
-    @Test(enabled = false)
+    @Test
     public void basic()
     {
         // 0) Cleanup
diff --git a/ui-test/source/java/ch/systemsx/cisd/openbis/uitest/widget/PagingToolBar.java b/ui-test/source/java/ch/systemsx/cisd/openbis/uitest/widget/PagingToolBar.java
index b7534c8e051..79fb53bf9a0 100644
--- a/ui-test/source/java/ch/systemsx/cisd/openbis/uitest/widget/PagingToolBar.java
+++ b/ui-test/source/java/ch/systemsx/cisd/openbis/uitest/widget/PagingToolBar.java
@@ -35,6 +35,15 @@ public class PagingToolBar implements Widget, Refreshable
         }
     }
 
+    public void settings()
+    {
+        Button b = context.find(".//button[text()='Settings']", Button.class);
+        if (!b.isPressed())
+        {
+            b.click();
+        }
+    }
+
     @Override
     public void setContext(WidgetContext context)
     {
diff --git a/ui-test/source/java/ch/systemsx/cisd/openbis/uitest/widget/SettingsDialog.java b/ui-test/source/java/ch/systemsx/cisd/openbis/uitest/widget/SettingsDialog.java
new file mode 100644
index 00000000000..04a794fa8e0
--- /dev/null
+++ b/ui-test/source/java/ch/systemsx/cisd/openbis/uitest/widget/SettingsDialog.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2012 ETH Zuerich, CISD
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package ch.systemsx.cisd.openbis.uitest.widget;
+
+import java.util.List;
+
+import org.openqa.selenium.WebElement;
+
+import ch.systemsx.cisd.openbis.uitest.infra.webdriver.WidgetContext;
+
+/**
+ * @author anttil
+ */
+public class SettingsDialog implements Widget
+{
+
+    private WidgetContext context;
+
+    public void showColumns(String... columns)
+    {
+
+        context.find(".//*[text()='No Columns']").click();
+
+        for (String name : columns)
+        {
+            List<WebElement> l =
+                    context.findAll(".//div[text()='"
+                            + name
+                            + "']/../..//div[contains(@class, 'IS_VISIBLE') and not(*)]");
+
+            System.out.println("SEarching for " + name);
+
+            if (l.size() > 0)
+            {
+                System.out.println("Actually clicking " + name);
+                l.get(0).click();
+            }
+        }
+
+        context.find("//*[@class='x-window-bl']//button[text()='OK']").click();
+    }
+
+    @Override
+    public void setContext(WidgetContext context)
+    {
+        this.context = context;
+    }
+}
-- 
GitLab