2017-04-19 17:14:02 -04:00
|
|
|
/*
|
|
|
|
* 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
|
2018-01-30 11:53:12 -05:00
|
|
|
seleniumWebdriver.SELENIUM_PROMISE_MANAGER = 0;
|
2017-04-19 17:14:02 -04:00
|
|
|
|
2018-01-30 11:53:12 -05:00
|
|
|
// chrome driver
|
|
|
|
var driver = new seleniumWebdriver.Builder().withCapabilities(seleniumWebdriver.Capabilities.chrome())
|
|
|
|
.build();
|
2017-04-19 17:14:02 -04:00
|
|
|
|
|
|
|
var rootUrl = process.env.ROOT_URL || 'https://scratch.ly';
|
|
|
|
|
2018-01-30 11:53:12 -05:00
|
|
|
// number of tests in the plan
|
2017-04-19 17:14:02 -04:00
|
|
|
tap.plan(4);
|
|
|
|
|
|
|
|
tap.tearDown(function () {
|
2018-01-30 11:53:12 -05:00
|
|
|
// quit the instance of the browser
|
2017-04-19 17:14:02 -04:00
|
|
|
driver.quit();
|
|
|
|
});
|
|
|
|
|
|
|
|
tap.beforeEach(function () {
|
2018-01-30 11:53:12 -05:00
|
|
|
// load the page with the driver
|
2017-04-19 17:14:02 -04:00
|
|
|
return driver.get(rootUrl);
|
|
|
|
});
|
|
|
|
|
2018-01-30 11:53:12 -05:00
|
|
|
// checks that the title of the first row is Featured Projects
|
2017-04-19 17:14:02 -04:00
|
|
|
tap.test('checkFeaturedProjectsRowTitleWhenSignedOut', function (t) {
|
|
|
|
var xPathLink = '//div[@class="box"]/div[@class="box-header"]/h4';
|
|
|
|
driver.findElement(seleniumWebdriver.By.xpath(xPathLink))
|
2018-01-30 11:53:12 -05:00
|
|
|
.then(function (element) {
|
2017-04-19 17:14:02 -04:00
|
|
|
element.getText('h4')
|
2018-01-30 11:53:12 -05:00
|
|
|
.then(function (text) {
|
|
|
|
// expected value of the title text
|
|
|
|
var expectedText = 'Featured Projects';
|
|
|
|
t.equal(text, expectedText);
|
|
|
|
t.end();
|
|
|
|
});
|
2017-04-19 17:14:02 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-01-30 11:53:12 -05:00
|
|
|
// checks that the link for a project makes sense
|
2017-04-19 17:14:02 -04:00
|
|
|
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)))
|
2018-01-30 11:53:12 -05:00
|
|
|
.then(function (element) {
|
2017-04-19 17:14:02 -04:00
|
|
|
element.getAttribute('href')
|
2018-01-30 11:53:12 -05:00
|
|
|
.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();
|
|
|
|
});
|
2017-04-19 17:14:02 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-01-30 11:53:12 -05:00
|
|
|
// checks that the title of the 2nd row is Featured Studios
|
2017-04-19 17:14:02 -04:00
|
|
|
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')
|
2018-01-30 11:53:12 -05:00
|
|
|
.then(function (text) {
|
|
|
|
var expectedText = 'Featured Studios';
|
|
|
|
t.equal(text, expectedText);
|
|
|
|
t.end();
|
|
|
|
});
|
2017-04-19 17:14:02 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-01-30 11:53:12 -05:00
|
|
|
// checks that the link for a studio makes sense
|
2017-04-19 17:14:02 -04:00
|
|
|
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')
|
2018-01-30 11:53:12 -05:00
|
|
|
.then(function (url) {
|
|
|
|
var expectedUrlRegExp = new RegExp('/studios/.*[0-9].*/?');
|
|
|
|
t.match(url, expectedUrlRegExp);
|
|
|
|
t.end();
|
|
|
|
});
|
2017-04-19 17:14:02 -04:00
|
|
|
});
|
|
|
|
});
|