Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Commit

Permalink
First commit, so it's not stuck on my laptop
Browse files Browse the repository at this point in the history
  • Loading branch information
juliemr committed Jan 16, 2013
0 parents commit 0595652
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
angular-seed/
Empty file added LICENSE
Empty file.
Empty file added README.md
Empty file.
93 changes: 93 additions & 0 deletions httpspec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
var webdriver = require('/Users/ralphj/selenium/selenium-read-only/build/javascript/node/webdriver');
var assert = require('assert');
var util = require('util')

var waitForAngular = function() {
util.puts('Starting waitForAngular');
driver.executeAsyncScript(function() {
var callback = arguments[arguments.length - 1];
angular.element(document.body).injector().get('$browser').notifyWhenNoOutstandingRequests(callback);
});
util.puts('Ending waitForAngular');
};


var driver = new webdriver.Builder().
usingServer('http://localhost:4444/wd/hub').
withCapabilities({
'browserName': 'chrome',
'version': '',
'platform': 'ANY',
'javascriptEnabled': true
}).
build();

driver.manage().timeouts().setScriptTimeout(10000);

// driver.get('http://docs.angularjs.org/api/ng.$http');

driver.get('http://localhost:8000/app/index.html');
driver.sleep(2);

var sample1Button = driver.findElement(webdriver.By.id('sample1'));
var sample2Button = driver.findElement(webdriver.By.id('sample2'));
sample1Button.click();

var fetchButton = driver.findElement(webdriver.By.id('fetch'));
fetchButton.click();

// The quick RPC works fine.
driver.findElement(webdriver.By.id('statuscode')).getText().then(function(text) {
assert.equal('200', text);
});
driver.findElement(webdriver.By.id('data')).getText().then(function(text) {
assert.equal('diablo', text);
});

// The slow one fails:
sample2Button.click();
fetchButton.click();
// Would normally need driver.sleep(2) or something.
waitForAngular();
driver.findElement(webdriver.By.id('statuscode')).getText().then(function(text) {
assert.equal('200', text);
});
waitForAngular();
driver.findElement(webdriver.By.id('data')).getText().then(function(text) {
assert.equal('hello now', text);
});


driver.quit();

// Original Angular scenario runner code
/*
describe("api/ng.$http", function() {
beforeEach(function() {
browser().navigateTo("index-nocache.html#!/api/ng.$http");
});
it('should make an xhr GET request', function() {
element(':button:contains("Sample GET")').click();
element(':button:contains("fetch")').click();
expect(binding('status')).toBe('200');
expect(binding('data')).toMatch(/Hello, \$http!/);
});
it('should make a JSONP request to angularjs.org', function() {
element(':button:contains("Sample JSONP")').click();
element(':button:contains("fetch")').click();
expect(binding('status')).toBe('200');
expect(binding('data')).toMatch(/Super Hero!/);
});
it('should make JSONP request to invalid URL and invoke the error handler',
function() {
element(':button:contains("Invalid JSONP")').click();
element(':button:contains("fetch")').click();
expect(binding('status')).toBe('0');
expect(binding('data')).toBe('Request failed');
});
});
*/

0 comments on commit 0595652

Please sign in to comment.