Fix Gh-1385 - Issue/smoke test signing in (#1411)

* add tests for signing in and my stuff

* flesh out tests, reorganize a bit

* add more tests

* tests for my stuff & signing in

* fix some of the errors causing build to fail

* pass in credentials from commandline rather than uncommitted file

* switch root back to staging

* address pr review comments, rename username & password vars

* update testing readme
This commit is contained in:
jwzimmer 2017-07-19 12:58:50 -04:00 committed by GitHub
parent 06acfbb61c
commit b289c42120
3 changed files with 184 additions and 0 deletions

View file

@ -15,5 +15,12 @@
* To run a single file from the command-line: `$ node_modules/.bin/tap ./test/integration/smoke-testing/filename.js --timeout=3600`
* The timeout var is for the length of the entire tap test-suite; if you are getting a timeout error, you may need to adjust this value (some of the Selenium tests take a while to run)
### Configuration
| Variable | Default | Description |
| --------------------- | --------------------- | --------------------------------------------------------- |
| `SMOKE_USERNAME` | `None` | Username for Scratch user you're signing in with to test |
| `SMOKE_PASSWORD` | `None` | Password for Scratch user you're signing in with to test |
## Using sauce
* We're still working on setting this up; more info coming shortly

View file

@ -0,0 +1,126 @@
/*
* Tests signing in & My Stuff according to smoke-tests at:
*
* https://github.com/LLK/scratchr2/wiki/Smoke-Testing-Test-Cases
*
*/
var username = process.env.SMOKE_USERNAME;
var password = process.env.SMOKE_PASSWORD;
var tap = require('tap');
const test = tap.test;
const webdriver = require('selenium-webdriver');
const By = webdriver.By;
const until = webdriver.until;
const driver = new webdriver.Builder()
.forBrowser('chrome')
.build();
const findByXpath = (xpath) => {
return driver.wait(until.elementLocated(By.xpath(xpath), 5 * 1000));
};
const clickXpath = (xpath) => {
return findByXpath(xpath).then(el => el.click());
};
const clickText = (text) => {
return clickXpath(`//*[contains(text(), '${text}')]`);
};
const clickButton = (text) => {
return clickXpath(`//button[contains(text(), '${text}')]`);
};
var rootUrl = process.env.ROOT_URL || 'https://scratch.ly';
var url = rootUrl + '/users/anyuser';
tap.plan(5);
tap.tearDown(function () {
driver.quit();
});
tap.beforeEach(function () {
return driver.get(url);
});
test('Sign in to Scratch using scratchr2 navbar', t => {
clickText('Sign in')
.then(() => findByXpath('//input[@id="login_dropdown_username"]'))
.then((element) => element.sendKeys(username))
.then(() => findByXpath('//input[@name="password"]'))
.then((element) => element.sendKeys(password))
.then(() => clickButton('Sign in'))
.then(() => findByXpath('//li[contains(@class, "logged-in-user")'
+ 'and contains(@class, "dropdown")]/span'))
.then((element) => element.getText('span'))
.then((text) => t.match(text.toLowerCase(), username.substring(0,10).toLowerCase(),
'first part of username should be displayed in navbar'))
.then(() => t.end());
});
test('Sign in to Scratch & verify My Stuff structure (tabs, title)', t => {
clickXpath('//a[@class="mystuff-icon"]')
.then(() => findByXpath('//div[@class="box-head"]/h2'))
.then((element) => element.getText('h2'))
.then((text) => t.equal('My Stuff', text, 'title should be My Stuff'))
.then(() => findByXpath('//li[@data-tab="projects"]/a'))
.then((element) => element.getText('a'))
.then((text) => t.match(text, 'All Projects', 'All Projects tab should be present'))
.then(() => findByXpath('//li[@data-tab="shared"]/a'))
.then((element) => element.getText('a'))
.then((text) => t.match(text, 'Shared Projects', 'Shared Projects tab should be present'))
.then(() => findByXpath('//li[@data-tab="unshared"]/a'))
.then((element) => element.getText('a'))
.then((text) => t.match(text, 'Unshared Projects', 'Unshared Projects tab should be present'))
.then(() => findByXpath('//li[@data-tab="galleries"]/a'))
.then((element) => element.getText('a'))
.then((text) => t.match(text, 'My Studios', 'My Studios tab should be present'))
.then(() => findByXpath('//li[@data-tab="trash"]/a'))
.then((element) => element.getText('a'))
.then((text) => t.match(text, 'Trash', 'Trash tab should be present'))
.then(() => t.end());
});
test('clicking See Inside should take you to the editor', t => {
clickXpath('//a[@class="mystuff-icon"]')
.then(() => findByXpath('//a[@data-control="edit"]'))
.then((element) => element.getText('span'))
.then((text) => t.equal(text, 'See inside', 'there should be a "See inside" button'))
.then(() => clickXpath('//a[@data-control="edit"]'))
.then(() => driver.getCurrentUrl())
.then( function (url) {
var expectedUrl = '/#editor';
t.equal(url.substr(-expectedUrl.length), expectedUrl, 'after clicking, the URL should end in #editor');
})
.then(() => t.end());
});
test('clicking a project title should take you to the project page', t => {
clickXpath('//a[@class="mystuff-icon"]')
.then(() => clickXpath('//a[@data-control="edit"]'))
.then(() => driver.getCurrentUrl())
.then( function (url) {
var expectedUrlRegExp = new RegExp('/projects/.*[0-9].*/?');
t.match(url, expectedUrlRegExp, 'after clicking, the URL should end in projects/PROJECT_ID/');
})
.then(() => t.end());
});
test('Add To button should bring up a list of studios', t => {
clickXpath('//a[@class="mystuff-icon"]')
.then(() => findByXpath('//div[@data-control="add-to"]'))
.then((element) => element.getText('span'))
.then((text) => t.equal(text, 'Add to', 'there should be an "Add to" button'))
.then(() => clickXpath('//div[@data-control="add-to"]'))
.then(() => findByXpath('//div[@class="dropdown-menu"]/ul/li'))
.then((element) => element.getText('span'))
.then( function (text) {
var expectedRegExp = new RegExp('.+');
t.match(text, expectedRegExp, 'the dropdown menu should have at least 1 text item in it');
})
.then(() => t.end());
});

View file

@ -0,0 +1,51 @@
var username = process.env.SMOKE_USERNAME;
var password = process.env.SMOKE_PASSWORD;
var tap = require('tap');
const test = tap.test;
const webdriver = require('selenium-webdriver');
const By = webdriver.By;
const until = webdriver.until;
const driver = new webdriver.Builder()
.forBrowser('chrome')
.build();
const findByXpath = (xpath) => {
return driver.wait(until.elementLocated(By.xpath(xpath), 5 * 1000));
};
const clickXpath = (xpath) => {
return findByXpath(xpath).then(el => el.click());
};
const clickText = (text) => {
return clickXpath(`//*[contains(text(), '${text}')]`);
};
var rootUrl = process.env.ROOT_URL || 'https://scratch.ly';
tap.plan(1);
tap.tearDown(function () {
driver.quit();
});
tap.beforeEach(function () {
return driver.get(rootUrl);
});
test('Sign in to Scratch using scratch-www navbar', t => {
clickText('Sign in')
.then(() => findByXpath('//input[@id="frc-username-1088"]'))
.then((element) => element.sendKeys(username))
.then(() => findByXpath('//input[@id="frc-password-1088"]'))
.then((element) => element.sendKeys(password))
.then(() => clickXpath('//button[contains(@class, "button") and '
+ 'contains(@class, "submit-button") and contains(@class, "white")]'))
.then(() => findByXpath('//span[@class="profile-name"]'))
.then((element) => element.getText())
.then((text) => t.match(text.toLowerCase(), username.substring(0,10).toLowerCase(),
'first part of username should be displayed in navbar'))
.then(() => t.end());
});