Reputation: 604
I have defined the use of Jasmine in my conf.js file
exports.config = {
framework: 'jasmine',
// Capabilities to be passed to the webdriver instance.
capabilities: {
'browserName': 'chrome',
},
And I am using the following code to click a button on a page and check for text.
element(by.css('.btn.btn-success.btn-lg')).click();
console.log('Wait 2 seconds');
browser.sleep(2000);
console.log('After wait');
// question 1
var expectedString = "Step 1 of 10";
var actualString = element(by.xpath('/html[1]/body[1]/section[1]/app-root[1]/app-pay-only[1]/div[1]/div[1]/h2[1]')).getText().then(function(actualString) {
return actualString;
});
console.log('here\'s the expect');
expect(actualString).toContain(expectedString);
However, I get a failure saying "expect is not a function" and when I am looking at the test run, I can see that the button isn't being pressed (so the page doesn't navigate.) If I comment out the expect, then the page will navigate as normal. I cannot see any reason why the click event would fail (I have even put in sleeps to see what is going on)
The stacktrace will be below - can anyone see anything to shed some light on this?
Message:
Failed: expect is not a function
Stack:
TypeError: expect is not a function
at UserContext.<anonymous> (C:\Users\Joseph.Adams\Desktop\protractor\LA1-311\end_to_end.js:78:9)
at C:\Users\Joseph.Adams\AppData\Roaming\npm\node_modules\protractor\node_modules\jasminewd2\index.js:112:25
at new ManagedPromise (C:\Users\Joseph.Adams\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:1077:7)
at ControlFlow.promise (C:\Users\Joseph.Adams\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:2505:12)
at schedulerExecute (C:\Users\Joseph.Adams\AppData\Roaming\npm\node_modules\protractor\node_modules\jasminewd2\index.js:95:18)
at TaskQueue.execute_ (C:\Users\Joseph.Adams\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:3084:14)
at TaskQueue.executeNext_ (C:\Users\Joseph.Adams\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:3067:27)
at asyncRun (C:\Users\Joseph.Adams\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:2974:25)
at C:\Users\Joseph.Adams\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:668:7
at <anonymous>
From: Task: Run it("Must allow working end to end") in control flow
at UserContext.<anonymous> (C:\Users\Joseph.Adams\AppData\Roaming\npm\node_modules\protractor\node_modules\jasminewd2\index.js:94:19)
at C:\Users\Joseph.Adams\AppData\Roaming\npm\node_modules\protractor\node_modules\jasminewd2\index.js:64:48
at ControlFlow.emit (C:\Users\Joseph.Adams\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\events.js:62:21)
at ControlFlow.shutdown_ (C:\Users\Joseph.Adams\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:2674:10)
at shutdownTask_.MicroTask (C:\Users\Joseph.Adams\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:2599:53)
From asynchronous test:
Error
at Suite.<anonymous> (C:\Users\Joseph.Adams\Desktop\protractor\LA1-311\end_to_end.js:63:5)
at Object.<anonymous> (C:\Users\Joseph.Adams\Desktop\protractor\LA1-311\end_to_end.js:14:1)
at Module._compile (module.js:635:30)
at Object.Module._extensions..js (module.js:646:10)
at Module.load (module.js:554:32)
at tryModuleLoad (module.js:497:12)
Upvotes: 0
Views: 1344
Reputation: 13712
Firstly, do a quick try as below:
1. comment all lines after console.log('After wait');
2. add a new line expect('Test abc').toContain('abc')
at the end ,
If you still get same error,
check your whole script to find you assign other value to expect
or not.
(like expect=xxx or global.expect=xxxx)
If you not get same error, maybe your protractor version greater than 3.0 (I don't remember the exact version), you have to use jasmine2, jasmine1 is not supported in high protractor.
Easy to verify it by change framework in conf file to jasmine2
exports.config = {
framework: 'jasmine2',
Pleae give your package.json, so that we can know what dependecy you used and their version.
Upvotes: 0
Reputation: 694
The way in which you are getting your variable for the expect is very different. I am not sure if it is the issue, but I have never seen it done that way. Try this:
var expectedString = "Step 1 of 10";
var elem = element(by.xpath('/html[1]/body[1]/section[1]/app-root[1]/app-pay-only[1]/div[1]/div[1]/h2[1]'));
expect(elem.getText()).toContain(expectedString);
Upvotes: 0