From 39c96a5142d73d6160b2f6bff4bbf668a670d7e7 Mon Sep 17 00:00:00 2001
From: Varac <varac@varac.net>
Date: Tue, 30 Apr 2019 15:54:02 +0200
Subject: [PATCH] Add nextcloud behave test

---
 test/behave/README.md                  |  2 ++
 test/behave/features/environment.py    | 10 ++++++++++
 test/behave/features/nextcloud.feature | 15 +++++++++++++++
 test/behave/features/steps/login.py    | 13 ++++++++++---
 test/ci-bootstrap.py                   | 10 ++++++++++
 5 files changed, 47 insertions(+), 3 deletions(-)
 create mode 100644 test/behave/features/nextcloud.feature

diff --git a/test/behave/README.md b/test/behave/README.md
index c7e083c0c..b43f0fe22 100644
--- a/test/behave/README.md
+++ b/test/behave/README.md
@@ -5,3 +5,5 @@
       apk --no-cache add git
       git clone https://code.greenhost.net/openappstack/bootstrap.git
       cd bootstrap/test/behave
+      behave -D nextcloud.url=https://files.ci-20410.ci.openappstack.net \
+       -D nextcloud.admin.password=…
diff --git a/test/behave/features/environment.py b/test/behave/features/environment.py
index eb9cac121..bc3dae74c 100644
--- a/test/behave/features/environment.py
+++ b/test/behave/features/environment.py
@@ -22,6 +22,16 @@ def save_screenshot(context, step):
 def before_all(context):
     """Run at the very beginning."""
     userdata = context.config.userdata
+    context.nextcloud = {}
+    context.nextcloud['url'] = userdata.get('nextcloud.url')
+    context.nextcloud['username'] = \
+        userdata.get('nextcloud.username', 'admin')
+    context.nextcloud['password'] = \
+        userdata.get('nextcloud.password')
+
+    assert context.nextcloud['url'], 'Nextcloud url variable missing in userdata!'
+    assert context.nextcloud['username'], 'Nextcloud username variable missing in userdata!'
+    assert context.nextcloud['password'], 'Nextcloud password variable missing in userdata!'
 
     headless = userdata.get('headless', 'False')
 
diff --git a/test/behave/features/nextcloud.feature b/test/behave/features/nextcloud.feature
new file mode 100644
index 000000000..f010b4b82
--- /dev/null
+++ b/test/behave/features/nextcloud.feature
@@ -0,0 +1,15 @@
+Feature: Test nextcloud admin login
+  As an OAS admin
+  I want to be able to login to nextcloud as the user admin
+
+Scenario: Open nextcloud
+  When I open the nextcloud URL
+  Then I wait on element "input#user" for 25000ms to be visible
+  And  I expect that element "input#user" is visible
+
+Scenario: Login to nextcloud
+  Given the element "input#user" is visible
+  When I enter the "nextcloud" "username" in the inputfield "input#user"
+  When I enter the "nextcloud" "password" in the inputfield "input#password"
+  And I click on the button "input#submit"
+  Then I expect that the title is "Files - Nextcloud"
diff --git a/test/behave/features/steps/login.py b/test/behave/features/steps/login.py
index 4eec789c8..77ce58c6b 100644
--- a/test/behave/features/steps/login.py
+++ b/test/behave/features/steps/login.py
@@ -3,13 +3,20 @@
 from behave import given, when
 from behave_webdriver.steps import *
 
+@when(u'I open the nextcloud URL')
+@given(u'I open the nextcloud URL')
+def step_impl(context):
+    """Login to nextcloud."""
+    context.behave_driver.get(context.nextcloud['url'])
 
-@when(u'I enter the "{section}" "{user}" "{cred_type}" in the inputfield "{element}"')
-def step_impl(context, section, user, cred_type, element):
+
+@when(u'I enter the "{section}" "{cred_type}" in the inputfield "{element}"')
+def step_impl(context, section, cred_type, element):
     """Enter username/password into login inputfields."""
     elem = context.behave_driver.get_element(element)
     elem.clear()
 
     context_section = getattr(context, section)
-    value = context_section[user][cred_type]
+    print(context_section)
+    value = context_section[cred_type]
     elem.send_keys(value)
diff --git a/test/ci-bootstrap.py b/test/ci-bootstrap.py
index 0133bafc0..ed8a881bf 100755
--- a/test/ci-bootstrap.py
+++ b/test/ci-bootstrap.py
@@ -268,9 +268,19 @@ def write_behave_config(settings=None):
     if settings is None:
         with open(SETTINGS_FILE) as stream:
             settings = yaml.safe_load(stream)
+
+    with open('./secrets/nextcloud_admin_password', 'r') as stream:
+        nextcloud_admin_password = yaml.safe_load(stream)
+
     behave_config = configparser.ConfigParser()
     behave_config['behave'] = {'stop': True}
     behave_config['behave.userdata'] = {}
+    behave_config['behave.userdata']['nextcloud.url'] = \
+        'https://files.{}'.format(settings['domain'])
+    behave_config['behave.userdata']['nextcloud.username'] = 'admin'
+    behave_config['behave.userdata']['nextcloud.password'] = \
+        nextcloud_admin_password
+
     with open('./behave/behave.ini', 'w') as configfile:
         behave_config.write(configfile)
 
-- 
GitLab