From a49d209c29caba71f67483c9d74182b88479cebb Mon Sep 17 00:00:00 2001 From: jwzimmer Date: Wed, 14 Sep 2016 15:28:45 -0400 Subject: [PATCH 01/11] folder and file for the initial automated test, checking the navbar create link URL is correct --- test/integration/check_navbar_links.js | 38 ++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 test/integration/check_navbar_links.js diff --git a/test/integration/check_navbar_links.js b/test/integration/check_navbar_links.js new file mode 100644 index 000000000..8683e4c80 --- /dev/null +++ b/test/integration/check_navbar_links.js @@ -0,0 +1,38 @@ +/* + * 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'), + seleniumWebdriver = require('selenium-webdriver'); + +//how to generalize for other browsers... how will this work in saucelabs? Do I need to iterate through the drivers for each browser here? +//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') + +/* + * Remove later after resolving these questions + */ +//find the navbar +//var navbarElement = driver.findElement(seleniumWebdriver.By.id("navigation")) +//var createLinkSignedOut = navbarElement.findElement(seleniumWebdriver.By.xpath('//li[@class="link create"]/a')) <-- this doesn't work to force findElement to look in the scope of navbarElement + +//find the create link within the navbar +//the create link depends on whether the user is signed in or not (tips window opens) + +//this xpath is fragile, can i look up by successive attributes instead? +tap.test('checkCreateLinkWhenSignedOut', function (t) { + var createLinkSignedOut = driver.findElement(seleniumWebdriver.By.xpath('//div[@id="navigation"]/div[@class="inner"]/ul/li[@class="link create"]/a')); + createLinkSignedOut.getAttribute("href").then(function(href){ + t.equal('https://scratch.ly/projects/editor/?tip_bar=home', href); + t.end(); + }); +}); + + +// close the instance of the browser +driver.quit(); + From 052819f8c549718c802bc46cca616e6e8a9baa0c Mon Sep 17 00:00:00 2001 From: jwzimmer Date: Wed, 14 Sep 2016 15:33:45 -0400 Subject: [PATCH 02/11] Clarified inline comments --- test/integration/check_navbar_links.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/integration/check_navbar_links.js b/test/integration/check_navbar_links.js index 8683e4c80..ae0b3e591 100644 --- a/test/integration/check_navbar_links.js +++ b/test/integration/check_navbar_links.js @@ -7,6 +7,9 @@ var tap=require('tap'), seleniumWebdriver = require('selenium-webdriver'); +/* + * Remove question comments after resolving them + */ //how to generalize for other browsers... how will this work in saucelabs? Do I need to iterate through the drivers for each browser here? //chrome driver var driver = new seleniumWebdriver.Builder().withCapabilities(seleniumWebdriver.Capabilities.chrome()).build(); @@ -14,7 +17,7 @@ var driver = new seleniumWebdriver.Builder().withCapabilities(seleniumWebdriver. driver.get('https://scratch.ly') /* - * Remove later after resolving these questions + * Remove question comments after resolving them */ //find the navbar //var navbarElement = driver.findElement(seleniumWebdriver.By.id("navigation")) @@ -23,6 +26,9 @@ 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) +/* + * Remove question comments after resolving them + */ //this xpath is fragile, can i look up by successive attributes instead? tap.test('checkCreateLinkWhenSignedOut', function (t) { var createLinkSignedOut = driver.findElement(seleniumWebdriver.By.xpath('//div[@id="navigation"]/div[@class="inner"]/ul/li[@class="link create"]/a')); From 3855926a1553abbe732cb165531b74df88c365bb Mon Sep 17 00:00:00 2001 From: jwzimmer Date: Thu, 15 Sep 2016 10:36:47 -0400 Subject: [PATCH 03/11] Tried to fix the errors for travis check, but wasn't sure how to handle some of them --- test/integration/check_navbar_links.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/test/integration/check_navbar_links.js b/test/integration/check_navbar_links.js index ae0b3e591..7fa81de80 100644 --- a/test/integration/check_navbar_links.js +++ b/test/integration/check_navbar_links.js @@ -4,24 +4,26 @@ * Test cases: https://github.com/LLK/scratch-www/wiki/Most-Important-Workflows#Create_should_take_you_to_the_editor */ -var tap=require('tap'), +var tap=require('tap'), seleniumWebdriver = require('selenium-webdriver'); /* * Remove question comments after resolving them */ -//how to generalize for other browsers... how will this work in saucelabs? Do I need to iterate through the drivers for each browser here? +//how to generalize for other browsers... how will this work in saucelabs? Do I need to iterate +//through the drivers for each browser here? //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') +driver.get('https://scratch.ly'); /* * Remove question comments after resolving them */ //find the navbar //var navbarElement = driver.findElement(seleniumWebdriver.By.id("navigation")) -//var createLinkSignedOut = navbarElement.findElement(seleniumWebdriver.By.xpath('//li[@class="link create"]/a')) <-- this doesn't work to force findElement to look in the scope of navbarElement +//var createLinkSignedOut = navbarElement.findElement(seleniumWebdriver.By.xpath('//li[@class="link create"]/a')) +//^^this doesn't work to force findElement to look in the scope of navbarElement //find the create link within the navbar //the create link depends on whether the user is signed in or not (tips window opens) @@ -31,11 +33,11 @@ driver.get('https://scratch.ly') */ //this xpath is fragile, can i look up by successive attributes instead? tap.test('checkCreateLinkWhenSignedOut', function (t) { - var createLinkSignedOut = driver.findElement(seleniumWebdriver.By.xpath('//div[@id="navigation"]/div[@class="inner"]/ul/li[@class="link create"]/a')); - createLinkSignedOut.getAttribute("href").then(function(href){ - t.equal('https://scratch.ly/projects/editor/?tip_bar=home', href); - t.end(); - }); + var createLinkSignedOut = driver.findElement(seleniumWebdriver.By.xpath('//div[@id="navigation"]/div[@class="inner"]/ul/li[@class="link create"]/a')); + createLinkSignedOut.getAttribute('href').then( function (href) { + t.equal('https://scratch.ly/projects/editor/?tip_bar=home', href); + t.end(); + }); }); From e21a2eadb176d6e9fb85dfd5a5e9888d46e0a3ca Mon Sep 17 00:00:00 2001 From: jwzimmer Date: Thu, 15 Sep 2016 11:40:46 -0400 Subject: [PATCH 04/11] Added selenium to devDependencies using npm install --save-dev --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 6951df6b2..cb66b745c 100644 --- a/package.json +++ b/package.json @@ -82,6 +82,7 @@ "sass-lint": "1.5.1", "sass-loader": "2.0.1", "scratchr2_translations": "git://github.com/LLK/scratchr2_translations.git#master", + "selenium-webdriver": "^2.44.0", "slick-carousel": "1.5.8", "source-map-support": "0.3.2", "style-loader": "0.12.3", From eb788acac04c91a9e498c60dce442408697fcfe9 Mon Sep 17 00:00:00 2001 From: jwzimmer Date: Thu, 15 Sep 2016 13:22:53 -0400 Subject: [PATCH 05/11] require statements on separate lines and travis check failires --- test/integration/check_navbar_links.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/test/integration/check_navbar_links.js b/test/integration/check_navbar_links.js index 7fa81de80..facbeb0d0 100644 --- a/test/integration/check_navbar_links.js +++ b/test/integration/check_navbar_links.js @@ -4,13 +4,13 @@ * Test cases: https://github.com/LLK/scratch-www/wiki/Most-Important-Workflows#Create_should_take_you_to_the_editor */ -var tap=require('tap'), - seleniumWebdriver = require('selenium-webdriver'); +var tap=require('tap'); +var seleniumWebdriver = require('selenium-webdriver'); /* * Remove question comments after resolving them */ -//how to generalize for other browsers... how will this work in saucelabs? Do I need to iterate +//how to generalize for other browsers... how will this work in saucelabs? Do I need to iterate //through the drivers for each browser here? //chrome driver var driver = new seleniumWebdriver.Builder().withCapabilities(seleniumWebdriver.Capabilities.chrome()).build(); @@ -33,7 +33,8 @@ driver.get('https://scratch.ly'); */ //this xpath is fragile, can i look up by successive attributes instead? tap.test('checkCreateLinkWhenSignedOut', function (t) { - var createLinkSignedOut = driver.findElement(seleniumWebdriver.By.xpath('//div[@id="navigation"]/div[@class="inner"]/ul/li[@class="link create"]/a')); + var xPathLink = '//div[@id="navigation"]/div[@class="inner"]/ul/li[@class="link create"]/a'; + var createLinkSignedOut = driver.findElement(seleniumWebdriver.By.xpath(xPathLink)); createLinkSignedOut.getAttribute('href').then( function (href) { t.equal('https://scratch.ly/projects/editor/?tip_bar=home', href); t.end(); From eaaa2faf2a82d32f357c4fd1052e478f961f67ad Mon Sep 17 00:00:00 2001 From: jwzimmer Date: Thu, 15 Sep 2016 13:28:17 -0400 Subject: [PATCH 06/11] replaced tab with 4 spaces --- test/integration/check_navbar_links.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/check_navbar_links.js b/test/integration/check_navbar_links.js index facbeb0d0..eb338c55e 100644 --- a/test/integration/check_navbar_links.js +++ b/test/integration/check_navbar_links.js @@ -33,7 +33,7 @@ driver.get('https://scratch.ly'); */ //this xpath is fragile, can i look up by successive attributes instead? tap.test('checkCreateLinkWhenSignedOut', function (t) { - var xPathLink = '//div[@id="navigation"]/div[@class="inner"]/ul/li[@class="link create"]/a'; + var xPathLink = '//div[@id="navigation"]/div[@class="inner"]/ul/li[@class="link create"]/a'; var createLinkSignedOut = driver.findElement(seleniumWebdriver.By.xpath(xPathLink)); createLinkSignedOut.getAttribute('href').then( function (href) { t.equal('https://scratch.ly/projects/editor/?tip_bar=home', href); From 579ec728183d3bb6cb3689a3f50ae30ce8c477a9 Mon Sep 17 00:00:00 2001 From: jwzimmer Date: Thu, 15 Sep 2016 14:10:47 -0400 Subject: [PATCH 07/11] removed ^ prefix from selenium dev dependency --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index cb66b745c..077e598f0 100644 --- a/package.json +++ b/package.json @@ -82,7 +82,7 @@ "sass-lint": "1.5.1", "sass-loader": "2.0.1", "scratchr2_translations": "git://github.com/LLK/scratchr2_translations.git#master", - "selenium-webdriver": "^2.44.0", + "selenium-webdriver": "2.44.0", "slick-carousel": "1.5.8", "source-map-support": "0.3.2", "style-loader": "0.12.3", From 57ab628337a87983d12680c23c3a7f751a6b771b Mon Sep 17 00:00:00 2001 From: jwzimmer Date: Mon, 19 Sep 2016 13:02:16 -0400 Subject: [PATCH 08/11] check only the href, not the URL. i'm not sure this is a good way to do this. may be too convoluted. --- test/integration/check_navbar_links.js | 44 ++++++++++++++------------ 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/test/integration/check_navbar_links.js b/test/integration/check_navbar_links.js index eb338c55e..23a341d64 100644 --- a/test/integration/check_navbar_links.js +++ b/test/integration/check_navbar_links.js @@ -7,36 +7,40 @@ var tap=require('tap'); var seleniumWebdriver = require('selenium-webdriver'); -/* - * Remove question comments after resolving them - */ -//how to generalize for other browsers... how will this work in saucelabs? Do I need to iterate -//through the drivers for each browser here? //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'); -/* - * Remove question comments after resolving them - */ -//find the navbar -//var navbarElement = driver.findElement(seleniumWebdriver.By.id("navigation")) -//var createLinkSignedOut = navbarElement.findElement(seleniumWebdriver.By.xpath('//li[@class="link create"]/a')) -//^^this doesn't work to force findElement to look in the scope of navbarElement +//return only the part of the URL that is in the href in the page's html, +//and the index that the href was found at +function getHrefFromUrl(url, expectedHref) { + var hrefOnly = ""; + var hrefIndex = url.lastIndexOf(expectedHref); + if (hrefIndex != -1) { + var hrefOnly = url.substr(hrefIndex); + }; + return {hrefIndex: hrefIndex, + hrefOnly: hrefOnly}; +}; //find the create link within the navbar //the create link depends on whether the user is signed in or not (tips window opens) - -/* - * Remove question comments after resolving them - */ -//this xpath is fragile, can i look up by successive attributes instead? tap.test('checkCreateLinkWhenSignedOut', function (t) { - var xPathLink = '//div[@id="navigation"]/div[@class="inner"]/ul/li[@class="link create"]/a'; + var xPathLink = '//li[contains(@class, "link") and contains(@class, "create")]/a'; var createLinkSignedOut = driver.findElement(seleniumWebdriver.By.xpath(xPathLink)); - createLinkSignedOut.getAttribute('href').then( function (href) { - t.equal('https://scratch.ly/projects/editor/?tip_bar=home', href); + createLinkSignedOut.getAttribute('href').then( function (url) { + //expected value of the href + var expectedHref = '/projects/editor/?tip_bar=home'; + var hrefInfo = getHrefFromUrl(url, expectedHref); + var hrefIndex = hrefInfo.hrefIndex; + var hrefOnly = hrefInfo.hrefOnly; + //the create href should match `/projects/editor/?tip_bar=home` + t.equal(expectedHref, hrefOnly); + //the create href should be at the end of the URL + var urlLength = url.length; + var urlLengthFromHrefInfo = hrefOnly.length + hrefIndex; + t.equal(urlLengthFromHrefInfo, urlLength) t.end(); }); }); From 867c95b382442a8c995f0e53de6bbe107cb227f3 Mon Sep 17 00:00:00 2001 From: jwzimmer Date: Mon, 19 Sep 2016 13:11:24 -0400 Subject: [PATCH 09/11] travis checks --- test/integration/check_navbar_links.js | 28 +++++++++++++------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/test/integration/check_navbar_links.js b/test/integration/check_navbar_links.js index 23a341d64..c490cdd16 100644 --- a/test/integration/check_navbar_links.js +++ b/test/integration/check_navbar_links.js @@ -14,15 +14,15 @@ driver.get('https://scratch.ly'); //return only the part of the URL that is in the href in the page's html, //and the index that the href was found at -function getHrefFromUrl(url, expectedHref) { - var hrefOnly = ""; - var hrefIndex = url.lastIndexOf(expectedHref); - if (hrefIndex != -1) { - var hrefOnly = url.substr(hrefIndex); - }; +function getHrefFromUrl (url, expectedHref) { + var hrefOnly = ''; + var hrefIndex = url.lastIndexOf(expectedHref); + if (hrefIndex != -1) { + hrefOnly = url.substr(hrefIndex); + } return {hrefIndex: hrefIndex, hrefOnly: hrefOnly}; -}; +} //find the create link within the navbar //the create link depends on whether the user is signed in or not (tips window opens) @@ -30,17 +30,17 @@ 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'; - var hrefInfo = getHrefFromUrl(url, expectedHref); - var hrefIndex = hrefInfo.hrefIndex; - var hrefOnly = hrefInfo.hrefOnly; - //the create href should match `/projects/editor/?tip_bar=home` + //expected value of the href + var expectedHref = '/projects/editor/?tip_bar=home'; + var hrefInfo = getHrefFromUrl(url, expectedHref); + var hrefIndex = hrefInfo.hrefIndex; + var hrefOnly = hrefInfo.hrefOnly; + //the create href should match `/projects/editor/?tip_bar=home` t.equal(expectedHref, hrefOnly); //the create href should be at the end of the URL var urlLength = url.length; var urlLengthFromHrefInfo = hrefOnly.length + hrefIndex; - t.equal(urlLengthFromHrefInfo, urlLength) + t.equal(urlLengthFromHrefInfo, urlLength); t.end(); }); }); From e06cf2b134e8632b7658da1bedda1b08ad89d267 Mon Sep 17 00:00:00 2001 From: jwzimmer Date: Wed, 21 Sep 2016 10:41:24 -0400 Subject: [PATCH 10/11] simplify checking that the href is at the end of the url with ray's suggestion --- test/integration/check_navbar_links.js | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/test/integration/check_navbar_links.js b/test/integration/check_navbar_links.js index c490cdd16..aeaf4ab69 100644 --- a/test/integration/check_navbar_links.js +++ b/test/integration/check_navbar_links.js @@ -12,18 +12,6 @@ var driver = new seleniumWebdriver.Builder().withCapabilities(seleniumWebdriver. //open scratch.ly in a new instance of the browser driver.get('https://scratch.ly'); -//return only the part of the URL that is in the href in the page's html, -//and the index that the href was found at -function getHrefFromUrl (url, expectedHref) { - var hrefOnly = ''; - var hrefIndex = url.lastIndexOf(expectedHref); - if (hrefIndex != -1) { - hrefOnly = url.substr(hrefIndex); - } - return {hrefIndex: hrefIndex, - hrefOnly: hrefOnly}; -} - //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) { @@ -32,15 +20,10 @@ tap.test('checkCreateLinkWhenSignedOut', function (t) { createLinkSignedOut.getAttribute('href').then( function (url) { //expected value of the href var expectedHref = '/projects/editor/?tip_bar=home'; - var hrefInfo = getHrefFromUrl(url, expectedHref); - var hrefIndex = hrefInfo.hrefIndex; - var hrefOnly = hrefInfo.hrefOnly; //the create href should match `/projects/editor/?tip_bar=home` - t.equal(expectedHref, hrefOnly); //the create href should be at the end of the URL - var urlLength = url.length; - var urlLengthFromHrefInfo = hrefOnly.length + hrefIndex; - t.equal(urlLengthFromHrefInfo, urlLength); + t.equal(url.substr(-expectedHref.length), expectedHref); + console.log(url.substr(-expectedHref.length)); t.end(); }); }); From 7b59953d84f10614d753c0b3c51690af8973adf2 Mon Sep 17 00:00:00 2001 From: jwzimmer Date: Wed, 21 Sep 2016 10:45:55 -0400 Subject: [PATCH 11/11] removed console log statement accidentally left from testing --- test/integration/check_navbar_links.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/integration/check_navbar_links.js b/test/integration/check_navbar_links.js index aeaf4ab69..0fb236c53 100644 --- a/test/integration/check_navbar_links.js +++ b/test/integration/check_navbar_links.js @@ -23,7 +23,6 @@ tap.test('checkCreateLinkWhenSignedOut', function (t) { //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); - console.log(url.substr(-expectedHref.length)); t.end(); }); });