Here is the issue I have faced. There is the code I’m working on. Code is mostly typical MVC written in Rails with Haml view files.
One part of the app is utilizing AngularJS to do all cool MVC in the browser.
No issue here.
In order to use this part of the application user has to login and here the issue appears:
I have noticed interesting following behavior:
If I instruct my test to go and visit login(or any other) page using chrome
beforeEach(function() {
browser().navigateTo('/help');
});
with the test that follows:
it('should scream for help', function() {
expect(element('#test').text()).toMatch('Help!');
});
and HTML
<div>
<h1>Help</h1>
<p id="test">Help!</p>
</div>
What I get is the frozen browser and rest of the test is not executing. Now, the minute I add angular to the element of the website:
<div ng-app>
<h1>Help</h1>
<p id="test">Help!</p>
</div>
The tests run as expected (both red and green).
The problem this is causing me is that I have little to no idea how to login my user (with something like “before all” block) so that I can happily perform my tests on angular functionality.
For non-javascript things I use RSpec and Capybara where I can conveniently call sign_in user.
Does anybody know how to login user (using non-anguar pages)? Perhaps there is a better way to handle this test? I was thinking about using PhantomJS like you can see in Railscasts episode 391, but I’d like to go using tools recommended by Google. I’m not smart enough to be reinventing the wheel:).
All advice highly appreciated.
Alright here is what I did (if you have better solution I’ll be grateful):
since I had that i could use
input(‘password’).enter(‘PASSWORD GOES HERE’);
Then just clicking on submit, et voilà.
Now, here is what was tricky:
when I wanted to execute all tests that were “meat and potatoes” of my work I got:
I have realized that this is caused by testacular executing remaining instructions before it got response from server that user is logged in.
So I added pause(); (you can add anything you want to make it wait a little if you experience same issue)
GREEN