Browser test: fix log in Selenium tests
authorŽeljko Filipin <zeljko.filipin@gmail.com>
Tue, 16 Feb 2016 11:53:06 +0000 (12:53 +0100)
committerHashar <hashar@free.fr>
Wed, 17 Feb 2016 13:09:34 +0000 (13:09 +0000)
LoginPage is removed from mediawiki_selenium Ruby gem. This repository
is the only repository that needs it, so the file is copied here.

Also, user used to be logged in via the API, not really testing if log
in via the web site works. It is fixed now.

Bug: T127042
Change-Id: Iff85d66a9a6d3343c212fe648c589539e889a313

tests/browser/features/login.feature
tests/browser/features/step_definitions/login_steps.rb
tests/browser/features/support/pages/login_page.rb [new file with mode: 0644]

index 2cb6356..7ed66a0 100644 (file)
@@ -27,5 +27,5 @@ Feature: Log in
 
   @login
   Scenario: Log in with valid credentials
-    When I am logged in
+    When I log in
     Then error box should not be visible
index bff5bdd..788bfc4 100644 (file)
@@ -13,6 +13,10 @@ Given(/^I am at Log in page$/) do
   visit LoginPage
 end
 
+When(/^I log in$/) do
+  on(LoginPage).login_with(user, password, false)
+end
+
 When(/^I log in with incorrect password$/) do
   on(LoginPage).login_with(user, 'incorrect password', false)
 end
diff --git a/tests/browser/features/support/pages/login_page.rb b/tests/browser/features/support/pages/login_page.rb
new file mode 100644 (file)
index 0000000..8ef1e44
--- /dev/null
@@ -0,0 +1,27 @@
+require 'page-object'
+
+class LoginPage
+  include PageObject
+
+  page_url 'Special:UserLogin'
+
+  div(:feedback, class: 'errorbox')
+  button(:login, id: 'wpLoginAttempt')
+  li(:logout, id: 'pt-logout')
+  text_field(:password, id: 'wpPassword1')
+  a(:password_strength, text: 'password strength')
+  a(:phishing, text: 'phishing')
+  text_field(:username, id: 'wpName1')
+  a(:username_displayed, title: /Your user page/)
+
+  def logged_in_as_element
+    @browser.div(id: 'mw-content-text').p.b
+  end
+
+  def login_with(username, password, wait_for_logout_element = true)
+    username_element.when_present.send_keys(username)
+    password_element.when_present.send_keys(password)
+    login_element.when_present.click
+    logout_element.when_present(10) if wait_for_logout_element
+  end
+end