Issue/gh 1167 test splash page (#1185)

* automated tests for footer links

* renamed navbar test file and removed footer links to separate file

* run with make smoke

* added tests for join scratch and sign in in navbar

* fix linter errors & update www links

* addressed some of ray's comments

* fix failing test - projects row link

* maybe fix error?

* continue switching to click, convert so it runs with disabled selenium promise manager, and refactor to be less location dependent

* finish switching off of implicit reliance on selenium promise manager
This commit is contained in:
jwzimmer 2017-04-19 17:14:02 -04:00 committed by GitHub
parent 76c46be17b
commit de78abbea2
6 changed files with 530 additions and 33 deletions

View file

@ -67,6 +67,9 @@ functional:
integration:
$(TAP) ./test/integration/*.js
smoke:
$(TAP) ./test/integration/smoke-testing/*.js --timeout=3600
localization:
$(TAP) ./test/localization/*.js

View file

@ -6,6 +6,7 @@
"start": "make start",
"stop": "make stop",
"test": "make test",
"smoke": "make smoke",
"watch": "make watch",
"build": "make build",
"dev": "make watch && make start &"

View file

@ -1,33 +0,0 @@
/*
* Checks that the links in the navbar on the homepage have the right URLs to redirect to
*
* Test cases: https://github.com/LLK/scratch-www/wiki/Most-Important-Workflows#Create_should_take_you_to_the_editor
*/
var tap=require('tap');
var seleniumWebdriver = require('selenium-webdriver');
//chrome driver
var driver = new seleniumWebdriver.Builder().withCapabilities(seleniumWebdriver.Capabilities.chrome()).build();
//open scratch.ly in a new instance of the browser
driver.get('https://scratch.ly');
//find the create link within the navbar
//the create link depends on whether the user is signed in or not (tips window opens)
tap.test('checkCreateLinkWhenSignedOut', function (t) {
var xPathLink = '//li[contains(@class, "link") and contains(@class, "create")]/a';
var createLinkSignedOut = driver.findElement(seleniumWebdriver.By.xpath(xPathLink));
createLinkSignedOut.getAttribute('href').then( function (url) {
//expected value of the href
var expectedHref = '/projects/editor/?tip_bar=home';
//the create href should match `/projects/editor/?tip_bar=home`
//the create href should be at the end of the URL
t.equal(url.substr(-expectedHref.length), expectedHref);
t.end();
});
});
// close the instance of the browser
driver.quit();

View file

@ -0,0 +1,301 @@
/*
* Checks that the links in the footer on the homepage have the right URLs to redirect to
*
* Test cases: https://github.com/LLK/scratch-www/wiki/Most-Important-Workflows
*/
require('chromedriver');
var tap = require('tap');
var seleniumWebdriver = require('selenium-webdriver');
// Selenium's promise driver will be deprecated, so we should not rely on it
seleniumWebdriver.SELENIUM_PROMISE_MANAGER=0;
//chrome driver
var driver = new seleniumWebdriver.Builder().withCapabilities(seleniumWebdriver.Capabilities.chrome()).build();
var rootUrl = process.env.ROOT_URL || 'https://scratch.ly';
//timeout for each test; timeout for suite set at command line level
var options = { timeout: 20000 };
//number of tests in the plan
tap.plan(24);
tap.tearDown(function () {
//quit the instance of the browser
driver.quit();
});
tap.beforeEach(function () {
//load the page with the driver
return driver.get(rootUrl);
});
// Function clicks the link and returns the url of the resulting page
function clickFooterLinks ( linkText ) {
// Not sure if I need this first wait - maybe it solved intermittent initial failure problem?
return driver.wait(seleniumWebdriver.until.elementLocated(seleniumWebdriver.By.id('view')))
.then( function () {
return driver.wait(seleniumWebdriver.until.elementLocated(seleniumWebdriver.By
.id('footer')))
.then( function () {
return driver.findElement(seleniumWebdriver.By.linkText(linkText)); })
.then( function (element) {
return element.click(); })
.then(function () {
return driver.getCurrentUrl();
});
});
}
// ==== ABOUT SCRATCH column ====
// ABOUT SCRATCH
tap.test('clickAboutScratchLink', options, function (t) {
var linkText = 'About Scratch';
var expectedHref = '/about';
clickFooterLinks(linkText).then( function (url) {
//the href should be at the end of the URL
t.equal(url.substr(-expectedHref.length), expectedHref);
t.end();
});
});
// FOR PARENTS
tap.test('clickForParentsLink', options, function (t) {
var linkText = 'For Parents';
var expectedHref = '/parents/';
clickFooterLinks(linkText).then( function (url) {
t.equal(url.substr(-expectedHref.length), expectedHref);
t.end();
});
});
// FOR EDUCATORS
tap.test('clickForEducatorsLink', options, function (t) {
var linkText = 'For Educators';
var expectedHref = '/educators';
clickFooterLinks(linkText).then( function (url) {
t.equal(url.substr(-expectedHref.length), expectedHref);
t.end();
});
});
// FOR DEVELOPERS
tap.test('clickForDevelopersScratchLink', options, function (t) {
var linkText = 'For Developers';
var expectedHref = '/developers';
clickFooterLinks(linkText).then( function (url) {
t.equal(url.substr(-expectedHref.length), expectedHref);
t.end();
});
});
// CREDITS
tap.test('clickCreditsLink', options, function (t) {
var linkText = 'Credits';
var expectedHref = '/info/credits';
clickFooterLinks(linkText).then( function (url) {
t.equal(url.substr(-expectedHref.length), expectedHref);
t.end();
});
});
// JOBS
tap.test('clickJobsLink', options, function (t) {
var linkText = 'Jobs';
var expectedHref = '/jobs';
clickFooterLinks(linkText).then( function (url) {
t.equal(url.substr(-expectedHref.length), expectedHref);
t.end();
});
});
// PRESS
tap.test('clickPressLink', options, function (t) {
var linkText = 'Press';
var expectedHref = 'https://wiki.scratch.mit.edu/wiki/Scratch_Press';
clickFooterLinks(linkText).then( function (url) {
t.equal(url, expectedHref);
t.end();
});
});
// ==== COMMUNITY column ====
// COMMUNITY GUIDELINES
tap.test('clickCommunityGuidelinesLink', options, function (t) {
var linkText = 'Community Guidelines';
var expectedHref = '/community_guidelines';
clickFooterLinks(linkText).then( function (url) {
t.equal(url.substr(-expectedHref.length), expectedHref);
t.end();
});
});
// DISCUSSION FORUMS
tap.test('clickDiscussionForumsLink', options, function (t) {
var linkText = 'Discussion Forums';
var expectedHref = '/discuss/';
clickFooterLinks(linkText).then( function (url) {
t.equal(url.substr(-expectedHref.length), expectedHref);
t.end();
});
});
// SCRATCH WIKI
tap.test('clickScratchWikiLink', options, function (t) {
var linkText = 'Scratch Wiki';
var expectedHref = 'https://wiki.scratch.mit.edu/wiki/Scratch_Wiki_Home';
clickFooterLinks(linkText).then( function (url) {
t.equal(url, expectedHref);
t.end();
});
});
// STATISTICS
tap.test('clickStatisticsLink', options, function (t) {
var linkText = 'Statistics';
var expectedHref = '/statistics/';
clickFooterLinks(linkText).then( function (url) {
t.equal(url.substr(-expectedHref.length), expectedHref);
t.end();
});
});
// ==== SUPPORT column ====
// HELP PAGE
tap.test('clickHelpPageLink', options, function (t) {
var linkText = 'Help Page';
var expectedHref = '/help/';
clickFooterLinks(linkText).then( function (url) {
t.equal(url.substr(-expectedHref.length), expectedHref);
t.end();
});
});
// FAQ
tap.test('clickFAQLink', options, function (t) {
var linkText = 'FAQ';
var expectedHref = '/info/faq';
clickFooterLinks(linkText).then( function (url) {
t.equal(url.substr(-expectedHref.length), expectedHref);
t.end();
});
});
// OFFLINE EDITOR
tap.test('clickOfflineEditorLink', options, function (t) {
var linkText = 'Offline Editor';
var expectedHref = '/scratch2download/';
clickFooterLinks(linkText).then( function (url) {
t.equal(url.substr(-expectedHref.length), expectedHref);
t.end();
});
});
// CONTACT US
tap.test('clickContactUsLink', options, function (t) {
var linkText = 'Contact Us';
var expectedHref = '/contact-us/';
clickFooterLinks(linkText).then( function (url) {
t.equal(url.substr(-expectedHref.length), expectedHref);
t.end();
});
});
// DONATE
tap.test('clickDonateLink', options, function (t) {
var linkText = 'Donate';
var expectedHref = 'https://secure.donationpay.org/scratchfoundation/';
clickFooterLinks(linkText).then( function (url) {
t.equal(url.substr(-expectedHref.length), expectedHref);
t.end();
});
});
// ==== LEGAL column ====
// TERMS OF USE
tap.test('clickTermsOfUseLink', options, function (t) {
var linkText = 'Terms of Use';
var expectedHref = '/terms_of_use';
clickFooterLinks(linkText).then( function (url) {
t.equal(url.substr(-expectedHref.length), expectedHref);
t.end();
});
});
// PRIVACY POLICY
tap.test('clickPrivacyPolicyLink', options, function (t) {
var linkText = 'Privacy Policy';
var expectedHref = '/privacy_policy';
clickFooterLinks(linkText).then( function (url) {
t.equal(url.substr(-expectedHref.length), expectedHref);
t.end();
});
});
// DMCA
tap.test('clickDMCALink', options, function (t) {
var linkText = 'DMCA';
var expectedHref = '/DMCA';
clickFooterLinks(linkText).then( function (url) {
t.equal(url.substr(-expectedHref.length), expectedHref);
t.end();
});
});
// ==== SCRATCH FAMILY column ====
// SCRATCH ED (SCRATCHED)
tap.test('clickScratchEdLink', options, function (t) {
var linkText = 'ScratchEd';
var expectedHref = 'http://scratched.gse.harvard.edu/';
clickFooterLinks(linkText).then( function (url) {
t.equal(url, expectedHref);
t.end();
});
});
// SCRATCH JR (SCRATCHJR)
tap.test('clickScratchJrLink', options, function (t) {
var linkText = 'ScratchJr';
var expectedHref = 'http://www.scratchjr.org/';
clickFooterLinks(linkText).then( function (url) {
t.equal(url, expectedHref);
t.end();
});
});
// SCRATCH DAY
tap.test('clickScratchDayLink', options, function (t) {
var linkText = 'Scratch Day';
var expectedHref = 'https://day.scratch.mit.edu/';
clickFooterLinks(linkText).then( function (url) {
t.equal(url, expectedHref);
t.end();
});
});
// SCRATCH CONFERENCE
tap.test('clickScratchConferenceLink', options, function (t) {
var linkText = 'Scratch Conference';
var expectedHref = '/conference';
clickFooterLinks(linkText).then( function (url) {
t.equal(url.substr(-expectedHref.length), expectedHref);
t.end();
});
});
// SCRATCH FOUNDATION
tap.test('clickScratchFoundationLink', options, function (t) {
var linkText = 'Scratch Foundation';
var expectedHref = 'https://www.scratchfoundation.org/';
clickFooterLinks(linkText).then( function (url) {
t.equal(url, expectedHref);
t.end();
});
});

View file

@ -0,0 +1,131 @@
/*
* Checks that the links in the navbar on the homepage have the right URLs to redirect to
*
* Test cases: https://github.com/LLK/scratch-www/wiki/Most-Important-Workflows
*/
require('chromedriver');
var seleniumWebdriver = require('selenium-webdriver');
var tap = require('tap');
// Selenium's promise driver will be deprecated, so we should not rely on it
seleniumWebdriver.SELENIUM_PROMISE_MANAGER=0;
//Set test url through environment variable
var rootUrl = process.env.ROOT_URL || 'https://scratch.ly';
//chrome driver
var driver = new seleniumWebdriver.Builder().withCapabilities(seleniumWebdriver.Capabilities.chrome()).build();
//number of tests in the plan
tap.plan(8);
tap.tearDown(function () {
//quit the instance of the browser
driver.quit();
});
tap.beforeEach(function () {
//load the page with the driver
return driver.get(rootUrl);
});
// ==== Links in navbar ====
//the create link changes depending on whether the user is signed in or not (tips window opens)
tap.test('checkCreateLinkWhenSignedOut', function (t) {
var xPathLink = '//li[contains(@class, "link") and contains(@class, "create")]/a';
var expectedHref = '/projects/editor/?tip_bar=home';
driver.findElement(seleniumWebdriver.By.xpath(xPathLink))
.then( function (element) {
return element.getAttribute('href');})
.then( function (url) {
t.equal(url.substr(-expectedHref.length), expectedHref);
t.end();
});
});
tap.test('checkExploreLinkWhenSignedOut', function (t) {
var xPathLink = '//li[contains(@class, "link") and contains(@class, "explore")]/a';
var expectedHref = '/explore/projects/all';
driver.findElement(seleniumWebdriver.By.xpath(xPathLink))
.then( function (element) {
return element.getAttribute('href');})
.then( function (url) {
t.equal(url.substr(-expectedHref.length), expectedHref);
t.end();
});
});
tap.test('checkDiscussLinkWhenSignedOut', function (t) {
var xPathLink = '//li[contains(@class, "link") and contains(@class, "discuss")]/a';
var expectedHref = '/discuss';
driver.findElement(seleniumWebdriver.By.xpath(xPathLink))
.then( function (element) {
return element.getAttribute('href');})
.then( function (url) {
t.equal(url.substr(-expectedHref.length), expectedHref);
t.end();
});
});
tap.test('checkAboutLinkWhenSignedOut', function (t) {
var xPathLink = '//li[contains(@class, "link") and contains(@class, "about")]/a';
var expectedHref = '/about';
driver.findElement(seleniumWebdriver.By.xpath(xPathLink))
.then( function (element) {
return element.getAttribute('href');})
.then( function (url) {
t.equal(url.substr(-expectedHref.length), expectedHref);
t.end();
});
});
tap.test('checkHelpLinkWhenSignedOut', function (t) {
var xPathLink = '//li[contains(@class, "link") and contains(@class, "help")]/a';
var expectedHref = '/help';
driver.findElement(seleniumWebdriver.By.xpath(xPathLink))
.then( function (element) {
return element.getAttribute('href');})
.then( function (url) {
t.equal(url.substr(-expectedHref.length), expectedHref);
t.end();
});
});
// ==== Search bar ====
tap.test('checkSearchBar', function (t) {
var xPathLink = '//input[@id="frc-q-1088"]';
// search bar should exist
driver.findElement(seleniumWebdriver.By.xpath(xPathLink)).then( function (element) {
t.ok(element);
t.end();
});
});
// ==== Join Scratch & Sign In ====
tap.test('checkJoinScratchLinkWhenSignedOut', function (t) {
var xPathLink = '//li[contains(@class, "link") and contains(@class, "right") and contains(@class, "join")]/a';
var expectedText = 'Join Scratch';
driver.findElement(seleniumWebdriver.By.xpath(xPathLink))
.then( function (element) {
return element.getText('a');})
.then( function (text) {
t.equal(text, expectedText);
t.end();
});
});
tap.test('checkSignInLinkWhenSignedOut', function (t) {
var xPathLink = '//li[contains(@class, "link") and contains(@class, "right") and contains(@class, "login-item")]/a';
var expectedText = 'Sign in';
driver.findElement(seleniumWebdriver.By.xpath(xPathLink))
.then( function (element) {
return element.getText('a');})
.then( function (text) {
t.equal(text, expectedText);
t.end();
});
});

View file

@ -0,0 +1,94 @@
/*
* Checks that the some of the homepage rows on the homepage are displayed and
* contents have the right URLs to redirect to
*
* Test cases: https://github.com/LLK/scratch-www/wiki/Most-Important-Workflows
*/
require('chromedriver');
var tap = require('tap');
var seleniumWebdriver = require('selenium-webdriver');
// Selenium's promise driver will be deprecated, so we should not rely on it
seleniumWebdriver.SELENIUM_PROMISE_MANAGER=0;
//chrome driver
var driver = new seleniumWebdriver.Builder().withCapabilities(seleniumWebdriver.Capabilities.chrome()).build();
var rootUrl = process.env.ROOT_URL || 'https://scratch.ly';
//number of tests in the plan
tap.plan(4);
tap.tearDown(function () {
//quit the instance of the browser
driver.quit();
});
tap.beforeEach(function () {
//load the page with the driver
return driver.get(rootUrl);
});
//checks that the title of the first row is Featured Projects
tap.test('checkFeaturedProjectsRowTitleWhenSignedOut', function (t) {
var xPathLink = '//div[@class="box"]/div[@class="box-header"]/h4';
driver.findElement(seleniumWebdriver.By.xpath(xPathLink))
.then( function (element) {
element.getText('h4')
.then( function (text) {
//expected value of the title text
var expectedText = 'Featured Projects';
t.equal(text, expectedText);
t.end();
});
});
});
//checks that the link for a project makes sense
tap.test('checkFeaturedProjectsRowLinkWhenSignedOut', function (t) {
var xPathLink = '//div[contains(@class, "thumbnail") ' +
'and contains(@class, "project") and contains(@class, "slick-slide") ' +
'and contains(@class, "slick-active")]/a[@class="thumbnail-image"]';
driver.wait(seleniumWebdriver.until
.elementLocated(seleniumWebdriver.By.xpath(xPathLink)))
.then( function (element) {
element.getAttribute('href')
.then( function (url) {
//expected pattern for the project URL
//since I don't know the length of the project ID number
var expectedUrlRegExp = new RegExp('/projects/.*[0-9].*/?');
t.match(url, expectedUrlRegExp);
t.end();
});
});
});
//checks that the title of the 2nd row is Featured Studios
tap.test('checkFeaturedStudiosRowWhenSignedOut', function (t) {
var xPathLink = '//div[@class="box"][2]/div[@class="box-header"]/h4';
driver.findElement(seleniumWebdriver.By.xpath(xPathLink))
.then(function (element) {
element.getText('h4')
.then( function (text) {
var expectedText = 'Featured Studios';
t.equal(text, expectedText);
t.end();
});
});
});
//checks that the link for a studio makes sense
tap.test('checkFeaturedStudiosRowLinkWhenSignedOut', function (t) {
var xPathLink = '//div[contains(@class, "thumbnail") and contains(@class, "gallery") ' +
'and contains(@class, "slick-slide") and contains(@class, "slick-active")]/a[@class="thumbnail-image"]';
driver.findElement(seleniumWebdriver.By.xpath(xPathLink))
.then(function (element) {
element.getAttribute('href')
.then( function (url) {
var expectedUrlRegExp = new RegExp('/studios/.*[0-9].*/?');
t.match(url, expectedUrlRegExp);
t.end();
});
});
});