Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have SPA application on on stack ASP MVC + AngularJS and i'd like to test UI. For a now i'm trying for Selenium with PhantomJS and WebKit drivers.

Testing page - view with single element - the list of <li> which loads dynamically from server and bind by Angular.

<div id="items">
    <li>text</li>
    <li>text2</li>
</div>

I'm trying to pass test

_driver.FindElements(By.TagName('li'))

The problem is that at this moment there is no elements loaded, and _driver.PageSource doesn't contain elements too.

How can i wait for items loaded? Please do not suggest Thread.Sleep()

share|improve this question

2 Answers 2

If you're using AngularJS then using Protractor is a good idea.

If you use protractor you can use it's waitForAngular() method which will wait for http requests to complete. It's still good practise to wait for elements to be displayed before acting on them, depending on your language and implementation it might look this in a synchronous language

WebDriverWait wait = new WebDriverWait(webDriver, timeoutInSeconds);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id<locator>));

Or in JS you can use wait method which executes a function until it returns true

browser.wait(function () {
    return browser.driver.isElementPresent(elementToFind);
});
share|improve this answer

Beside eddiec's suggest. If you test an AngularJS app, I strongly suggest you to think about protractor

Protractor will help you solve the waiting matter (sync, async). However, there are some notes

1 - You need to develop your test in javascript

2 - There are some different mechanism in handling flow

share|improve this answer
    
and what about E2E testing? i'd like to get "happy path". For unit tests i'm using Jasmine. Is it possible to test UI with Jasmine? –  deeptowncitizen Aug 1 at 8:36
    
protractor is used for e2e. You can use it with Jasmine, Cucumber and Mocha test framework. However, Mocha has limited beta support. You will need to include your own assertion framework if working with mocha. –  Nguyen Vu Hoang Aug 1 at 9:00
    
I'm using ASP MVC, AngularJS, Jasmine. Can i use 'protractor' without Node.JS? –  deeptowncitizen Aug 1 at 10:05
    
I'm afraid nope. –  Nguyen Vu Hoang Aug 1 at 10:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.