After trying multiple examples with slight variations in the code, I am still unable to get it to work as expected. The code below consists of commented sections that claim to work but do not in my case.
The tools I am using include:
- selenium-webdriver
- jasmine-node-reporter-fix
(to resolve jasmine-node
errors)
This involves a simple asynchronous test where Google is opened and searched, followed by retrieving the page title.
Issue; The page title returned is from the Google homepage rather than the search results page, even though the browser ends up on the search results page.
Code
var webdriver = require('selenium-webdriver');
var driver = new webdriver.Builder().
withCapabilities(webdriver.Capabilities.firefox()).
build();
jasmine.DEFAULT_TIMEOUT_INTERVAL = 9999999;
describe('basic test', function () {
it('should be on correct page', function (done) {
//driver.get('http://www.wingify.com');
//driver.getTitle().then(function (title) {
// expect(title).toBe('Wingify');
// // Jasmine waits for the done callback to be called before proceeding to next specification.
// done();
//});
driver.get("http://www.google.com");
driver.findElement(webdriver.By.name("q")).sendKeys("webdriver");
driver.findElement(webdriver.By.name("btnG")).click();
//driver.getTitle().then(function (title) {
// console.log(title);
// console.log(expect);
// expect(title).toBe('webdriver - Google Search');
// done();
//});
driver.wait(function () {
driver.getTitle().then(function (title) {
expect(title).toBe('webdriver - Google Search');
done();
});
}, 5000);
});
});
Result
Failures:
1) basic test should be on correct page
Message:
Expected 'Google' to be 'webdriver - Google Search'.
Stacktrace:
Error: Expected 'Google' to be 'webdriver - Google Search'.
at C:\Stash\Will-Hancock\grunt-jasmine\spec\test-spec.js:31:19
at C:\Stash\Will-Hancock\grunt-jasmine\node_modules\selenium-webdriver\lib\goog\base.js:1243:15
at webdriver.promise.ControlFlow.runInNewFrame_ (C:\Stash\Will-Hancock\grunt-jasmine\node_modules\selenium-webdriver\lib\webdriver\promise.js:1539
:20)
at notify (C:\Stash\Will-Hancock\grunt-jasmine\node_modules\selenium-webdriver\lib\webdriver\promise.js:362:12)
at notifyAll (C:\Stash\Will-Hancock\grunt-jasmine\node_modules\selenium-webdriver\lib\webdriver\promise.js:331:7)
at resolve (C:\Stash\Will-Hancock\grunt-jasmine\node_modules\selenium-webdriver\lib\webdriver\promise.js:309:7)
at fulfill (C:\Stash\Will-Hancock\grunt-jasmine\node_modules\selenium-webdriver\lib\webdriver\promise.js:429:5)
at Object.webdriver.promise.asap (C:\Stash\Will-Hancock\grunt-jasmine\node_modules\selenium-webdriver\lib\webdriver\promise.js:671:5)
Finished in 4.281 seconds
1 test, 1 assertion, 1 failure, 0 skipped
Despite suggestions to extend the jasmine timeout or utilize the Jasmine done() method, the issue persists.
I am puzzled about why the wait function does not delay as expected. Results are generated instantly regardless of the provided timeout value.