-
Notifications
You must be signed in to change notification settings - Fork 2.3k
getCurrentUrl() should wait for Angular before executing #92
Comments
@juliemr I tried the temporary fix its timing out. |
same here |
I used the ptor.sleep(5000); to let the page load before it trys and get the current url. It works for me now. |
@Douwe92 I tried your suggestion... Didnt work for me |
Can you show your code? @rj051286 |
@Douwe92
}); |
@rj051286 What is it timing out on? One thing I noticed is there's no expectation on the first test. Try combining the two var util = require('util');
describe('Login', function() {
var ptor;
beforeEach(function() {
ptor = protractor.getInstance();
ptor.get('#/login');
},30000);
it('allows user to log in', function() {
var expectedUrl = ptor.baseUrl + '/#/missioncontrol';
ptor.findElement(protractor.By.input('login')).sendKeys('username');
ptor.findElement(protractor.By.input('password')).sendKeys('password');
ptor.findElement(protractor.By.css('input.login-form-container-button')).click();
ptor.sleep(10000);
expect(ptor.getCurrentUrl()).toBe(expectedUrl);
}, 30000);
}); |
@apankov1 Glad it helped! Hopefully it works for the issue @rj051286 is having. |
@stickel Got this error now ScriptTimeoutError: Timed out waiting for async script result after 1ms |
@stickel one more question if I may. I moved Sign In part to beforeEach part and it is failing again. I don't think it's a good idea to put all checks under one Now my code looks like this:
And it is failing. If I move code back to What do you think will be the best way to do it? I want to structure my code so that Iog in in beforeEach and then write different test. Thanks |
@apankov1 How is it failing? What's the error? One thing to try (I haven't tested this) would be putting Why do you want to log in before each test? After the first login the app will remember the state it was in after each test. For example, if you first test the log in form (and it's successful), the next test will happen on the logged in state ( |
@stickel I'm getting:
I probably misunderstanding use of Thank you. |
@stickel I am able to login. It works fine without any timeout. The code i am using to make a click on the link is below:
}); The error i am getting is: ScriptTimeoutError: Timed out waiting for async script result after 1ms Can you help me understand why this might be occurring? |
@apankov1 It sounds like you have it right. In my app I have logging in as one |
@rj051286 You're trying to end a test after clicking a logout button; there's no expectation. I'd suggest moving |
@stickel So i will have to move the login credentials in the beforeEach correct? this is what i have now, Still timing out var util = require('util');
}); |
@rj051286 You don't have to move the login credentials into the var util = require('util');
describe('Login', function() {
var ptor;
beforeEach(function() {
ptor = protractor.getInstance();
});
it('allows user to log in', function() {
var expectedUrl = ptor.baseUrl + '#/missioncontrol';
// We're going to log into the app
ptor.get('#/login');
ptor.findElement(protractor.By.input('login')).sendKeys('ranjan');
ptor.findElement(protractor.By.input('password')).sendKeys('Password1');
ptor.findElement(protractor.By.css('input.login-form-container-button')).click();
ptor.sleep(10000);
// Successful login means we should be on the 'missioncontrol' page
expect(ptor.getCurrentUrl()).toBe(expectedUrl);
}, 30000);
it('allows user to logout', function() {
var expectedUrl = ptor.baseUrl + '#/login';
// Because we logged in successfully in the last test
// the Logout button should be on the page, let's click it
ptor.findElement(protractor.By.linkText('Logout')).click();
ptor.sleep(10000);
// we logged out and should be on the login page again
expect(ptor.getCurrentUrl()).toBe(expectedUrl);
}, 30000);
}); |
@stickel I got this error Login Failures:
Finished in 47.721 seconds Shutting down selenium standalone server /Users/ranjanbhambroo/Documents/protractor_voloforce_tests/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:1542 |
@stickel i have another question/issue, which is most likely has nothing to do with bug but I don't want to create a separate topic because it looks very similar. I'm getting timeout issue when I'm trying to get text and check if it's correct. here is my code:
I'm getting:
User's name is shown in the menu. I'm assuming that in case if selector was wrong it would show error:
Please let me know if I should open a separate ticket with this question (just don't want to pollute issue tracker). Thank you for you help and responses. |
@rj051286 I'm not sure why the test is timing out now. It could be a slow server response. If you increase the timeout does it still fail the same way? @juliemr might have better insight into this specific issue. @apankov1 Try removing
|
@stickel thanks a lot for your help. I've changed my code as you suggested but I still get timeout. I'm trying to debug my code with this ugly stuff:
When I do this I get following Thanks |
@apankov1 In my tests I usually keep the
|
@stickel, i've changed my code to match yours
but I still get an error:
So weird. |
@apankov1 Small thing, you've got |
@stickel I'm trying both |
Re: timeouts
|
Hey @juliemr, we do have $timeout call on our page. Does that mean that we won't be able to use protractor for our project? It's pretty sad. We some core functionality relaying on it. Is there any workaround for it? I also did what you suggested in and got following error:
|
@juliemr, I went through opened discussions and found that this issues is being discussed here #49. I will keep an eye on this ticket. I have a question thought about at what point |
For what it's worth, I'm using AngJS + RequireJS and the following E2E worked for me via a Grunt task. Couple of things to note:
describe("AppScenario basic startup tests", function()
{
// NOTE: this must be done first
var ptor = protractor.getInstance();
//-----------------------------------------------------------------------
// Setup/Teardown Methods
//-----------------------------------------------------------------------
/**
* Setup the base url.
*/
beforeEach(function()
{
ptor.driver.get(ptor.baseUrl);
});
//-----------------------------------------------------------------------
// Tests Suite
//-----------------------------------------------------------------------
/**
* Ensure that the application defaults to the login view when no other url hash is provided
*/
it("should automatically redirect to /login when location hash/fragment is empty", function()
{
// we make protractor sleep for 5 seconds since we need to wait for the app to bootstrap manually
// this is not ideal, but will suffice for now
// consider using ptor.waitForAngular();
ptor.sleep(5000);
// ptor.waitForAngular(); // this throws: UnknownError: javascript error: Cannot call method 'get' of undefined
ptor.getCurrentUrl().
then(function(url) {
expect(url).toEqual(ptor.baseUrl+"#/login");
});
});
}); |
@stickel I have tried increasing the time out but i am still getting the timeout errors... |
Is this done for the dev in the framework behind the scenes or is there something the dev needs to add to the test manually to enforce this? |
Hi, I think this issue has turned into a couple different issues. Log-in issues may have been addressed here: https://github.com/angular/protractor/blob/master/docs/faq.md If there are lingering other problems, please open a new issue with a descriptive subject for them! |
Hello, Concerning the getCurrentUrl(), I'm on 0.10 and I still I have an inconsistent behaviour when I'm doing: ptor.getCurrentUrl() is either malformed, or the previous url I was on, or right. Is this fix for you or should I reopen that bug? |
reopen, please! |
@eduardomartines if you are having an issue, please include exactly what is failing and open a new bug. This issue is too out of date to be reopened. |
The expectation should be that the page settles down before
getCurrentUrl()
executes.Temporary fix - instead of doing
ptor.getCurrentUrl().then...
doThe text was updated successfully, but these errors were encountered: