First commit, so it's not stuck on my laptop · angular/protractor@0595652 (original) (raw)

``

1

`+

var webdriver = require('/Users/ralphj/selenium/selenium-read-only/build/javascript/node/webdriver');

`

``

2

`+

var assert = require('assert');

`

``

3

`+

var util = require('util')

`

``

4

+

``

5

`+

var waitForAngular = function() {

`

``

6

`+

util.puts('Starting waitForAngular');

`

``

7

`+

driver.executeAsyncScript(function() {

`

``

8

`+

var callback = arguments[arguments.length - 1];

`

``

9

`+

angular.element(document.body).injector().get('$browser').notifyWhenNoOutstandingRequests(callback);

`

``

10

`+

});

`

``

11

`+

util.puts('Ending waitForAngular');

`

``

12

`+

};

`

``

13

+

``

14

+

``

15

`+

var driver = new webdriver.Builder().

`

``

16

`+

usingServer('http://localhost:4444/wd/hub').

`

``

17

`+

withCapabilities({

`

``

18

`+

'browserName': 'chrome',

`

``

19

`+

'version': '',

`

``

20

`+

'platform': 'ANY',

`

``

21

`+

'javascriptEnabled': true

`

``

22

`+

}).

`

``

23

`+

build();

`

``

24

+

``

25

`+

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

`

``

26

+

``

27

`+

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

`

``

28

+

``

29

`+

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

`

``

30

`+

driver.sleep(2);

`

``

31

+

``

32

`+

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

`

``

33

`+

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

`

``

34

`+

sample1Button.click();

`

``

35

+

``

36

`+

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

`

``

37

`+

fetchButton.click();

`

``

38

+

``

39

`+

// The quick RPC works fine.

`

``

40

`+

driver.findElement(webdriver.By.id('statuscode')).getText().then(function(text) {

`

``

41

`+

assert.equal('200', text);

`

``

42

`+

});

`

``

43

`+

driver.findElement(webdriver.By.id('data')).getText().then(function(text) {

`

``

44

`+

assert.equal('diablo', text);

`

``

45

`+

});

`

``

46

+

``

47

`+

// The slow one fails:

`

``

48

`+

sample2Button.click();

`

``

49

`+

fetchButton.click();

`

``

50

`+

// Would normally need driver.sleep(2) or something.

`

``

51

`+

waitForAngular();

`

``

52

`+

driver.findElement(webdriver.By.id('statuscode')).getText().then(function(text) {

`

``

53

`+

assert.equal('200', text);

`

``

54

`+

});

`

``

55

`+

waitForAngular();

`

``

56

`+

driver.findElement(webdriver.By.id('data')).getText().then(function(text) {

`

``

57

`+

assert.equal('hello now', text);

`

``

58

`+

});

`

``

59

+

``

60

+

``

61

`+

driver.quit();

`

``

62

+

``

63

`+

// Original Angular scenario runner code

`

``

64

`+

/*

`

``

65

`+

describe("api/ng.$http", function() {

`

``

66

`+

beforeEach(function() {

`

``

67

`+

browser().navigateTo("index-nocache.html#!/api/ng.$http");

`

``

68

`+

});

`

``

69

+

``

70

`+

it('should make an xhr GET request', function() {

`

``

71

`+

element(':button:contains("Sample GET")').click();

`

``

72

`+

element(':button:contains("fetch")').click();

`

``

73

`+

expect(binding('status')).toBe('200');

`

``

74

`+

expect(binding('data')).toMatch(/Hello, $http!/);

`

``

75

`+

});

`

``

76

+

``

77

`+

it('should make a JSONP request to angularjs.org', function() {

`

``

78

`+

element(':button:contains("Sample JSONP")').click();

`

``

79

`+

element(':button:contains("fetch")').click();

`

``

80

`+

expect(binding('status')).toBe('200');

`

``

81

`+

expect(binding('data')).toMatch(/Super Hero!/);

`

``

82

`+

});

`

``

83

+

``

84

`+

it('should make JSONP request to invalid URL and invoke the error handler',

`

``

85

`+

function() {

`

``

86

`+

element(':button:contains("Invalid JSONP")').click();

`

``

87

`+

element(':button:contains("fetch")').click();

`

``

88

`+

expect(binding('status')).toBe('0');

`

``

89

`+

expect(binding('data')).toBe('Request failed');

`

``

90

`+

});

`

``

91

+

``

92

`+

});

`

``

93

`+

*/

`