Pmiazga has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/392026 )

Change subject: Rewrite MobileFronted Ruby tests to NodeJS
......................................................................

Rewrite MobileFronted Ruby tests to NodeJS

Changes:
 - added basic scaffolding
 - rewritten features/special_historyu
 - rewritten features/contributions
 - rewritten features/switch_view
 - removed rewrriten ruby tests

Bug: T177260
Change-Id: I9fc76ea0366fb44fbc593a16a5774a8a3d643a63
---
D tests/browser/features/special_history.feature
D tests/browser/features/step_definitions/common_article_steps.rb
D tests/browser/features/step_definitions/switch_views.rb
D tests/browser/features/step_definitions/switch_views_bug_t129600.rb
D tests/browser/features/switch_views.feature
A tests/selenium/.eslintrc.json
A tests/selenium/LocalSettings.php
A tests/selenium/README.md
A tests/selenium/helpers/mobile.mode.js
A tests/selenium/pageobjects/article.page.js
A tests/selenium/pageobjects/special/common/history.page.js
A tests/selenium/pageobjects/special/contributions.page.js
A tests/selenium/pageobjects/special/history.page.js
A tests/selenium/pageobjects/special/user.page.js
A tests/selenium/specs/contributions.js
A tests/selenium/specs/history.js
A tests/selenium/specs/switch_views.js
17 files changed, 322 insertions(+), 75 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend 
refs/changes/26/392026/1

diff --git a/tests/browser/features/special_history.feature 
b/tests/browser/features/special_history.feature
deleted file mode 100644
index b74451f..0000000
--- a/tests/browser/features/special_history.feature
+++ /dev/null
@@ -1,20 +0,0 @@
-@chrome @en.m.wikipedia.beta.wmflabs.org @firefox @test2.m.wikipedia.org 
@vagrant
-Feature: Special:History (Note test may take a long time to run on first run)
-
-  Background:
-    Given I am using the mobile site
-      And the page "Selenium diff test" exists and has at least "51" edits
-      And I am on the "Selenium diff test" page
-    When I click on the history link in the last modified bar
-
-  Scenario: Check components in diff summary
-    When I click the link in the header bar
-    Then the text of the first heading should be "Selenium diff test"
-
-  Scenario: Check components in diff summary
-    Then I should see a list of page contributions
-      And I should see a summary of the last contribution
-      And the last contribution summary should not show the title of the page 
edited
-      And the last contribution summary should show the edit summary
-      And the last contribution summary should show the time of the last edit
-      And the last contribution summary should show the username who made the 
last edit
diff --git a/tests/browser/features/step_definitions/common_article_steps.rb 
b/tests/browser/features/step_definitions/common_article_steps.rb
deleted file mode 100644
index 88bed7e..0000000
--- a/tests/browser/features/step_definitions/common_article_steps.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-When(/^I click on the history link in the last modified bar$/) do
-  on(ArticlePage).last_modified_bar_history_link_element.when_present.click
-  expect(on(SpecialHistoryPage).side_list_element.when_present(10)).to 
be_visible
-end
-
-Then(/^the text of the first heading should be "(.*)"$/) do |title|
-  on(ArticlePage) do |page|
-    page.wait_until do
-      page.first_heading_element.when_present.text.include? title
-    end
-    expect(page.first_heading_element.when_present.text).to match title
-  end
-end
diff --git a/tests/browser/features/step_definitions/switch_views.rb 
b/tests/browser/features/step_definitions/switch_views.rb
deleted file mode 100644
index 5f289dc..0000000
--- a/tests/browser/features/step_definitions/switch_views.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-Given(/^I toggle the mobile view$/) do
-  on(Page).toggle_mobile_view
-end
-
-Then(/^I should see the mobile view$/) do
-  expect(on(Page).toggle_view_desktop_element).to be_visible
-end
-
-Given(/^I toggle the desktop view$/) do
-  on(Page).toggle_desktop_view
-end
-
-Then(/^I should see the desktop view$/) do
-  expect(on(Page).toggle_view_mobile_element).to be_visible
-end
diff --git 
a/tests/browser/features/step_definitions/switch_views_bug_t129600.rb 
b/tests/browser/features/step_definitions/switch_views_bug_t129600.rb
deleted file mode 100644
index 9fb87a6..0000000
--- a/tests/browser/features/step_definitions/switch_views_bug_t129600.rb
+++ /dev/null
@@ -1,5 +0,0 @@
-Given(/^I am on a page that transcludes content from a special page$/) do
-  api.create_page 'T129600', '{{Special:PrefixIndex/User:Admin/}}'
-
-  step 'I am on the "T129600" page'
-end
diff --git a/tests/browser/features/switch_views.feature 
b/tests/browser/features/switch_views.feature
deleted file mode 100644
index 0803014..0000000
--- a/tests/browser/features/switch_views.feature
+++ /dev/null
@@ -1,22 +0,0 @@
-@chrome @firefox @vagrant
-Feature: Switch between mobile and desktop views
-
-  @integration
-  Scenario: Switching from desktop view to mobile view
-    Given I am on the "Main Page" page
-    And I toggle the mobile view
-    Then I should see the mobile view
-
-  @integration
-  Scenario: Switching from mobile view to desktop view
-    Given I am using the mobile site
-    And I am on the "Main Page" page
-    And I toggle the desktop view
-    Then I should see the desktop view
-
-  @integration
-  Scenario: Bug: T129600
-    Given I am on the desktop site
-    And I am on a page that transcludes content from a special page
-    And I toggle the mobile view
-    Then I should see the mobile view
diff --git a/tests/selenium/.eslintrc.json b/tests/selenium/.eslintrc.json
new file mode 100644
index 0000000..d64ada9
--- /dev/null
+++ b/tests/selenium/.eslintrc.json
@@ -0,0 +1,14 @@
+{
+       "extends": "../../.eslintrc.json",
+       "env": {
+               "es6": true,
+               "mocha": true,
+               "node": true
+       },
+       "parserOptions": {
+               "ecmaVersion": 6
+       },
+       "globals": {
+               "browser": false
+       }
+}
diff --git a/tests/selenium/LocalSettings.php b/tests/selenium/LocalSettings.php
new file mode 100644
index 0000000..a4abe2d
--- /dev/null
+++ b/tests/selenium/LocalSettings.php
@@ -0,0 +1,2 @@
+<?php
+
diff --git a/tests/selenium/README.md b/tests/selenium/README.md
new file mode 100644
index 0000000..32c5202
--- /dev/null
+++ b/tests/selenium/README.md
@@ -0,0 +1,32 @@
+# Selenium tests
+
+Please see tests/selenium/README.md file in mediawiki/core repository.
+
+## Usage
+
+Set up MediaWiki-Vagrant:
+
+    cd mediawiki/vagrant
+    vagrant up
+    vagrant roles enable mobilefrontend
+    vagrant provision
+
+From mediawiki/core folder:
+
+    echo 'include_once 
"$IP/extensions/MobileFrontend/tests/browser/LocalSettings.php";' >> 
LocalSettings.php
+
+Run both mediawiki/core and MobileFrontend tests from mediawiki/core folder:
+
+    npm run selenium
+
+To run only MobileFrontend tests in one terminal window or tab start 
Chromedriver:
+
+    chromedriver --url-base=/wd/hub --port=4444
+
+In another terminal tab or window go to mediawiki/core folder:
+
+    ./node_modules/.bin/wdio tests/selenium/wdio.conf.js --spec 
extensions/MobileFrontend/tests/selenium/specs/*.js
+
+Run only one MobileFrontend test file from mediawiki/core:
+
+    ./node_modules/.bin/wdio tests/selenium/wdio.conf.js --spec 
extensions/MobileFrontend/tests/selenium/specs/contributions.js
diff --git a/tests/selenium/helpers/mobile.mode.js 
b/tests/selenium/helpers/mobile.mode.js
new file mode 100644
index 0000000..d2c5783
--- /dev/null
+++ b/tests/selenium/helpers/mobile.mode.js
@@ -0,0 +1,20 @@
+'use strict';
+
+const Page = require( '../../../../../tests/selenium/pageobjects/page' );
+
+class MobileMode {
+
+    useMobileSite() {
+        // we need to open page, otherwise set cookie fails
+        let page = new Page();
+        page.open( 'Main_Page' );
+        browser.cookie('post', {
+            'name': 'mf_useformat',
+            'value': 'true'
+        });
+        page.open( 'Main_Page' );
+    }
+
+}
+
+module.exports = new MobileMode();
diff --git a/tests/selenium/pageobjects/article.page.js 
b/tests/selenium/pageobjects/article.page.js
new file mode 100644
index 0000000..ba040f4
--- /dev/null
+++ b/tests/selenium/pageobjects/article.page.js
@@ -0,0 +1,46 @@
+'use strict';
+
+const Page = require( '../../../../../tests/selenium/pageobjects/page' );
+
+class ArticlePage extends Page {
+
+    // UI Elements
+    get mainMenuButton() { return browser.element( '#mw-mf-main-menu-button'); 
}
+    get isAuthenticated() { return browser.element( 'body.is-authenticated'); }
+
+    get switchToMobileViewElement() { return browser.element( 
'a.stopMobileRedirectToggle' ); }
+    get switchToDesktopViewElement() { return browser.element( 
'a#mw-mf-display-toggle' ); }
+
+    // pre-content
+    get getFirstHeading() { return browser.element( 'h1#section_0' ); }
+    // standalone history link
+    get standaloneEditHistoryLink() { return browser.element( 
'.last-modified-bar a' ); }
+    // beta mode indicator
+    get betaModeIndicator() { return browser.element( 'a.branding-box sup' ); }
+
+    // left nav
+    get navigation() { return browser.element( 'nav'); }
+    get aboutLink() { return this.navigation.element( 'a'); } //text matches 
/^About/
+    get disclaimerLink() { return this.navigation.element( 'a'); } // text 
matches 'Disclaimers'
+
+    // last modified bar
+    get lastModifiedBarHistoryLink() {
+        // wait element.waitForVisible() sometimes didn't work, no idea why
+        browser.waitForText("*=Last edited");
+        return browser.element('.last-modified-bar 
a[href^="/wiki/Special:History"]');
+    }
+    get lastModifiedBarHistoryUserPageLink() {
+        let link = browser.element('.last-modified-bar 
a[href^="/wiki/User:"]');
+        link.waitForVisible();
+        return link;
+    }
+
+    switchToMobileView() {
+        this.switchToMobileViewElement.click();
+    }
+    switchToDesktopView() {
+        this.switchToDesktopViewElement.click();
+    }
+}
+
+module.exports = ArticlePage;
diff --git a/tests/selenium/pageobjects/special/common/history.page.js 
b/tests/selenium/pageobjects/special/common/history.page.js
new file mode 100644
index 0000000..8d24fee
--- /dev/null
+++ b/tests/selenium/pageobjects/special/common/history.page.js
@@ -0,0 +1,24 @@
+'use strict';
+const ArticlePage = require( '../../article.page' );
+const HISTORY_LIST_SELECTOR = '.diff-summary-list';
+
+class HistoryCommonsPage extends ArticlePage {
+
+    get contentHeaderBarLink() { return browser.element('.content-header a'); }
+    get historyList() { return browser.element( HISTORY_LIST_SELECTOR); }
+    get lastContribution() { return this.historyList.element( 'li' ); }
+    get lastContributionTitle() { return this.lastContribution.element('h3'); }
+    get lastContributionTimetstamp() { return 
this.lastContribution.element('p.timestamp'); }
+    get lastContributionEditSummary() { return 
this.lastContribution.element('p.edit-summary'); }
+    get lastContributionUsername() { return 
this.lastContribution.element('p.mw-mf-user'); }
+    get moreLink() { return browser.element('.more'); }
+
+    contributionsListIsVisible() {
+        const list = browser.element( HISTORY_LIST_SELECTOR );
+        list.waitForVisible();
+        return list;
+    }
+
+}
+
+module.exports = HistoryCommonsPage;
diff --git a/tests/selenium/pageobjects/special/contributions.page.js 
b/tests/selenium/pageobjects/special/contributions.page.js
new file mode 100644
index 0000000..7b334c9
--- /dev/null
+++ b/tests/selenium/pageobjects/special/contributions.page.js
@@ -0,0 +1,13 @@
+'use strict';
+const CommonsHistoryPage = require( './common/history.page' );
+
+
+class ContributionsSpecialPage extends CommonsHistoryPage {
+
+    open( user ) {
+        super.open( 'Special:Contributions/' + user );
+    }
+
+}
+
+module.exports = ContributionsSpecialPage;
\ No newline at end of file
diff --git a/tests/selenium/pageobjects/special/history.page.js 
b/tests/selenium/pageobjects/special/history.page.js
new file mode 100644
index 0000000..58b709b
--- /dev/null
+++ b/tests/selenium/pageobjects/special/history.page.js
@@ -0,0 +1,13 @@
+'use strict';
+const CommonsHistoryPage = require( './common/history.page' );
+
+
+class HistorySpecialPage extends CommonsHistoryPage {
+
+    open( title ) {
+        super.open( 'Special:History/' + title );
+    }
+
+}
+
+module.exports = HistorySpecialPage;
\ No newline at end of file
diff --git a/tests/selenium/pageobjects/special/user.page.js 
b/tests/selenium/pageobjects/special/user.page.js
new file mode 100644
index 0000000..2a2adea
--- /dev/null
+++ b/tests/selenium/pageobjects/special/user.page.js
@@ -0,0 +1,20 @@
+'use strict';
+const HistoryCommonsPage = require( '../article.page' );
+
+
+class UserPage extends HistoryCommonsPage {
+
+    get userContributionsLink() {
+        return browser.element( '.user-links 
a[href^="/wiki/Special:Contributions/"]' );
+    }
+
+    open( username ) {
+        super.open( 'User:' + username );
+    }
+
+    isUserPageOpen( username ) {
+        return browser.getUrl().search('User:' + username) !== -1;
+    }
+}
+
+module.exports = new UserPage();
\ No newline at end of file
diff --git a/tests/selenium/specs/contributions.js 
b/tests/selenium/specs/contributions.js
new file mode 100644
index 0000000..33b1ec4
--- /dev/null
+++ b/tests/selenium/specs/contributions.js
@@ -0,0 +1,48 @@
+'use strict';
+
+const assert = require( 'assert' ),
+      MobileMode = require( '../helpers/mobile.mode' ),
+      ContributionsPage = require( '../pageobjects/special/contributions.page' 
),
+      UserPage = require( '../pageobjects/special/user.page' ),
+      UserLogin = require( 
'../../../../../tests/selenium/pageobjects/userlogin.page' ),
+      EditPage = require( 
'../../../../../tests/selenium/pageobjects/edit.page' );
+
+describe( 'Contribution page', function () {
+    const username = browser.options.username,
+          password = browser.options.password,
+          title = 'Contributions Page test',
+          content = `Testing wiki page content ${Math.random().toString()}`;
+    let contributionsPage;
+
+    before( function() {
+        UserLogin.login( username, password );
+        browser.call( function () {
+            // lets be sure that user has at least one contribution
+            return EditPage.edit(title, content );
+        } );
+        MobileMode.useMobileSite();
+    } );
+
+    it( 'User page has correct contributions link', function() {
+        UserPage.open( username );
+        UserPage.userContributionsLink.click();
+    });
+
+    it( 'Contributions page title redirects to my user page', function() {
+        contributionsPage = new ContributionsPage();
+        contributionsPage.open( username );
+        contributionsPage.contentHeaderBarLink.click();
+        assert( UserPage.isUserPageOpen( username ) );
+    });
+
+    it( 'Contributions page has all necessary elements', function() {
+        contributionsPage = new ContributionsPage();
+        contributionsPage.open( username );
+        assert( contributionsPage.contributionsListIsVisible() );
+        assert( contributionsPage.lastContribution.isVisible() );
+        assert( contributionsPage.lastContributionEditSummary.isVisible() );
+        assert( contributionsPage.lastContributionTimetstamp.isVisible()  );
+        assert( contributionsPage.lastContributionTitle.isVisible() );
+        assert( !contributionsPage.lastContributionUsername.isVisible() );
+    });
+} );
diff --git a/tests/selenium/specs/history.js b/tests/selenium/specs/history.js
new file mode 100644
index 0000000..1d1fc7a
--- /dev/null
+++ b/tests/selenium/specs/history.js
@@ -0,0 +1,48 @@
+'use strict';
+
+const assert = require( 'assert' );
+const HistoryPage = require( '../pageobjects/special/history.page' );
+const ArticlePage = require( '../pageobjects/article.page' );
+const MobileMode = require( '../helpers/mobile.mode' );
+
+describe( 'History pages', function () {
+    const title = 'Selenium diff test';
+
+    before( function() {
+        MobileMode.useMobileSite();
+    } );
+
+    it( 'Article has a correct link to history', function () {
+        //This test sometimes fail, with `selector needs to be typeof 
`string`` no idea why
+        //the last modified bar is injected via JS, instead of 
waitForVisible() now I use waitForText()
+        const articlePage = new ArticlePage();
+        articlePage.open(title);
+        articlePage.lastModifiedBarHistoryLink.click();
+    });
+
+    it( 'Clicking article title in header redirects to the article page', 
function () {
+        const historyPage = new HistoryPage();
+        historyPage.open( title );
+        historyPage.contentHeaderBarLink.click();
+        assert( historyPage.getFirstHeading.getText() === title );
+    } );
+
+    it( 'History should contain all required elements', function() {
+        const historyPage = new HistoryPage();
+        historyPage.open( title );
+        assert( historyPage.contributionsListIsVisible() );
+        assert( historyPage.lastContribution.isVisible() );
+        assert( historyPage.lastContributionEditSummary.isVisible() );
+        assert( historyPage.lastContributionTimetstamp.isVisible()  );
+        assert( historyPage.lastContributionUsername.isVisible() );
+        assert( !historyPage.lastContributionTitle.isVisible() );
+    });
+
+} );
+/**
+ Background:
+ [X] Given I am using the mobile site
+ [!] And the page "Selenium diff test" exists and has at least "51" edits 
--TODO
+ [X] And I am on the "Selenium diff test" page
+ [X] When I click on the history link in the last modified bar
+ */
\ No newline at end of file
diff --git a/tests/selenium/specs/switch_views.js 
b/tests/selenium/specs/switch_views.js
new file mode 100644
index 0000000..4855cc7
--- /dev/null
+++ b/tests/selenium/specs/switch_views.js
@@ -0,0 +1,42 @@
+'use strict';
+
+const assert = require( 'assert' ),
+      MobileMode = require( '../helpers/mobile.mode' ),
+      ArticlePage = require( '../pageobjects/article.page' ),
+      EditPage = require( 
'../../../../../tests/selenium/pageobjects/edit.page' );
+
+describe( 'Switching views works properly', function () {
+    beforeEach(function() {
+        // mobile mode is stored in cookie, dop all cookies so we always start 
from scratch
+        browser.deleteCookie();
+    } );
+
+    it('Switching from desktop view to mobile view', function() {
+        const page = new ArticlePage();
+        page.open( 'Main_Page' );
+        page.switchToMobileView();
+        assert( !page.switchToMobileViewElement.isVisible() );
+        assert( page.switchToDesktopViewElement.isVisible() );
+    });
+
+    it('Switching from mobile view to desktop view', function () {
+        const page = new ArticlePage();
+        MobileMode.useMobileSite();
+        page.switchToDesktopView();
+        assert( page.switchToMobileViewElement.isVisible() );
+        assert( !page.switchToDesktopViewElement.isVisible() );
+    } );
+
+    it( 'Switching mode on page that transcludes content from a special page', 
function() {
+        const page = new ArticlePage();
+        // create problematic article
+        browser.call( function () {
+            return EditPage.apiEdit('T129600', 
'{{Special:PrefixIndex/User:Admin/}}' );
+        } );
+
+        page.open( 'T129600' );
+        page.switchToMobileView();
+        assert( !page.switchToMobileViewElement.isVisible() );
+        assert( page.switchToDesktopViewElement.isVisible() );
+    });
+} );
\ No newline at end of file

-- 
To view, visit https://gerrit.wikimedia.org/r/392026
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9fc76ea0366fb44fbc593a16a5774a8a3d643a63
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Pmiazga <pmia...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to