I am using protractor along with PhantomJs for e2e testing of my angular app.
Currently I am testing a login form. All the test work fine when I am simply checking
whether the form loaded correctly
username/password fields are empty
errors are displayed when you enter incorrect authentication information.
So far phantomJs and protractor have been quiet cooperative
However the below mentioned test cases simply fails all the time in protractor. I have tried various permutation and combinations but to no avail.
when the user enters correct authentication information in the login form, the angular app will change the route to dashboard section. i.e the url in the browser window would change from
http://localhost:12345/#/signin/
to
http://localhost:12345/#/dashboard
When I run the below give test, I know that the authentication was successful because the server logs display a success response object sent. Upon receiving this response, the angular app should have changed the route to /dashboard. However protractor fails to capture this change in route.
My test looks like below:
describe("SignOn Page - Performing authentication with valid credentials ",function(){
var ptor;
beforeEach(function(){
ptor = protractor.getInstance();
ptor.get('#/signon');
ptor.findElement(protractor.By.id('username')).sendKeys('joe');
ptor.findElement(protractor.By.id('password')).sendKeys('pass');
element(by.partialButtonText('Sign In')).click();
ptor.waitForAngular();
});
it("should re-direct user to dashboard page once the user enters correct authentication information",function(){
ptor = protractor.getInstance();
expect(ptor.getCurrentUrl()).toContain('dashboard');
expect(ptor.getTitle()).toContain('dashboard');
});
});
My question to this forum is, does protractor have issues changing states ? I am using ui.router in my angular application ?
I had the same issue because I was using phantomJS 1.9.x and not the 2.x
So you need to uninstall phantomjs 1.9
npm remove -g phantomjs
and install phantomJS 2.x
npm install -g phantomjs2
Hope it's also solve your issue
Related
While running multiple test suits on CBT via jenkins parallel, Jenkins get slower and page takes more time to load on CBT and hence it shows below error(which is intermittent)
Error: Angular could not be found on the page Https:xxx.xyz.com If this is not an Angular application, you may need to turn off waiting for Angular.
If is not angular application, you need to turn of wait for angular. Usually login pages are not angular:
browser.waitForAngularEnabled(false);
To check if is angular, open dev tools and in console just write "angular", if page is angular will return object, if not will return "Uncaught ReferenceError: angular is not defined".
I am using Ionic and Oauth.io to perform authentication. If I run ionic serve and include the outh.js file in my index everything works good from the browser.
But when I run ionic run ios or install the app in android, I get the following error when I press the auth button (the one that suppose to execute OAuth.popup
I do not know what to do, until now I have checked the following:
In config.xml I have access, allow-intent and allow-navigation full permisive
I have installed and re-installed the plugin ionic plugin add https://github.com/oauth-io/oauth-phonegap.git
I tried to run the native app without the inclusion of the oauth.js file and everything breaks.
Using current versions up to date.
I am new to Ionic, so I don't know how to debug the device-running app or simulator.
Could be similar to this post but not exactly .
Your advices will be appreciated.
I figure it out reading some posts. The OAuth initialization and references should be done after the device is ready, so it is best to put the initialize in this block:
$ionicPlatform.ready(function() {
// ...
if(typeof window.OAuth !== 'undefined'){
$rootScope.OAuth = window.OAuth;
$rootScope.OAuth.initialize('XXX');
}
else{
console.log("plugin not loaded, this is running in a browser");
$.getScript( "lib/oauth.js", function() {
$rootScope.OAuth = OAuth;
$rootScope.OAuth.initialize('XXX');
});
}
});
Now, if the plugin is loaded it initializes the window.OAuth object, else the app is running in browser, so I have to include the oauth.js file. Also I assigned the OAuth to the $rootScope for quick access.
Hope this helps anyone.
I'm writing a suite of Protractor tests from the ground up for a new Angular webapp. My team has asked me to run my tests against their Test server instance. I've got my config file and a basic test spec set up, but as soon as I hit the main page and do a simple expect() statement, I get "Timed out waiting for Protractor to synchronize with the page after 11 seconds."
Here's my test:
describe('the home page', function() {
it('should display the correct user name', function(){
expect(element(by.binding('user.name')).getText()).toContain(browser.params.login.user);
});
});
I cloned the dev team's git repo, set it up on my localhost, changed my baseUrl and ran my Protractor test against it locally. Passed without a hitch.
After some conversation with the dev team, I've determined that it's not a $http or $timeout issue. We use both of those services, but not repeatedly (I don't think they're "polling"). None of them should happen more than once, and all the timeouts are a half-second long.
What else could cause Protractor to time out like that? I wish it failed on my localhost so I could go tweak the code until I find out what's causing the problem, but it doesn't.
I have discovered the solution: check for console errors.
Turns out, one of our $http requests wasn't coming back because my Protractor tests were accessing the page via https, but one of our xhtml endpoints was at a non-secured location. This resulted in a very helpful console error which I had not yet seen, because it only occurred when accessing the site with WebDriver.
The error text: "The page at [url] was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint. This request has been blocked; the content must be served over HTTPS."
I modified my baseUrl to access the site via regular http, and now everything is working fine.
I've got an interesting setup here.
I have an Angular App that loads another Angular App inside an iframe. I'm interested in testing the iframed-in Angular app with Protractor.
Protractor is waiting for the first Angular app to load, but when I switch the iframe with
ptor.switchTo().frame('experience');
I can see that Protractor is not waiting for the iframed Angular app before making assertions. I have tried adding
ptor.waitForAngular();
After switching to the iframe with no luck. Anybody have any ideas what is going on here?
Thanks!
If it helps, I'm running my tests through the Saucelabs ssh tunnel on Chrome. I can tell that the tunneling is working because I see the resources for the iframed app being requested and downloading.
Testing iframes with protractor is a little bit tricky. It took me a while and a lot of patience to sort of understand what was going on. I hope this helps!
Protrator is built upon WebdriverJS, so you can use the whole package to test iframes. When you start testing with protractor, the first thing you do is get an instance of protractor:
var ptor = protractor.getInstance();
But to test what you have inside the iframe you will need ptor.driver instead of ptor!
var driver = ptor.driver;
Then, when you start writing the test, you find the iframe, you switch to it, you test it with 'driver' and you switch back to the initial frame.
ptor.switchTo().frame(driver.findElement(protractor.By.xpath('xpath-to-iframe')));
// Test iframe with driver
driver.findElement(protractor.By.xpath('some-sort-of-input')).sendKeys('username');
driver.findElement(protractor.By.xpath('other-sort-of-input')).sendKeys('password');
driver.findElement(protractor.By.xpath('other-sort-of-button')).click();
// Switch back to Default Content
ptor.switchTo().defaultContent();
// And WAIT for angular!!
ptor.waitForAngular();
The code that follows is a general example of what I mentioned above:
describe('Protractor iframe Test', function(){
var ptor, driver;
beforeEach(function(){
ptor = protractor.getInstance();
driver = ptor.driver;
});
it('should test the iframe', function(){
ptor.switchTo().frame(driver.findElement(protractor.By.xpath('xpath-to-iframe')));
// Test iframe with driver
driver.findElement(protractor.By.xpath('some-sort-of-input')).sendKeys('username');
driver.findElement(protractor.By.xpath('other-sort-of-input')).sendKeys('password');
driver.findElement(protractor.By.xpath('other-sort-of-button')).click();
// At this point, you can expect() things to happen to the iframe app
// Switch back to Default Content
ptor.switchTo().defaultContent();
// And WAIT for angular!!
ptor.waitForAngular();
// Then you can keep testing (or expecting something!)
expect('this answer').toBe('useful');
});
});
With protractor 2.5.1, #lthilon's answer was giving an 'Invalid Locator' error.
The following syntax resolved that though:
var driver = browser.driver;
var loc = by.tagName('iframe');
var el = driver.findElement(loc);
browser.switchTo().frame(el);
driver.findElement(by.tagName('body')).sendKeys('my test string');
browser.switchTo().defaultContent();
browser.waitForAngular();
Switching to an iframe is very simple according to latest protractor API docs 5.4.1:
await browser.switchTo().frame(element(by.xpath('//iframe')).getWebElement());
The context switches to the specified iframe, now every command that you run will be executed on the iframe. Now you can even switch to nested iframes. To switch back to parent iframe:
driver.switchTo().parentFrame();
I've found fantastic unit/e2e test tools karma.
And I wrote simple chrome extension with angular. I want to write automated tests for it, but not only unit tests, end-to-end tests too.
I wrote something like this (will open my angular extension-options page):
it('Go to options page', function() {
browser().navigateTo('chrome-extension://aopgehikihpnclbfeohobanjecpiefho/html/application.html#/options');
});
I removed '--user-data-dir' and '--disable-default-apps' for karma-chrome-launcher, (because I want that my extension stays in chrome during "karma tests")
but I've got next error message "Sandbox Error: Application document not accessible.":
browser navigate to 'chrome-extension://aopgehikihpnclbfeohobanjecpiefho/html/application.html#/options'
http://localhost:9876/base/tests/e2e/scenario.js?1372429335000:9:5:
Sandbox Error: Application document not accessible.
Chrome 27.0 (Windows): Executed 2 of 2 (2 FAILED) (0.254 secs / 0.139 secs)
Chrome option --no-sandbox deprecated long time ago.
I'm sure I'm not wrong, the options page opens ok, but from chrome "omnibox".
chrome-extension://aopgehikihpnclbfeohobanjecpiefho/html/application.html#/options
Sandbox Error means no way for end-to-end tests for google chrome extensions via karma?
Can I set chrome to special "non-secure" mode just for tests?
Thanks,
i don't think karma scenario runner is capable to do that. You can try Protractor, it uses WebDriver and karma scenario runner will be replaced with it.
What if you tried setting a proxy? Like
proxies = {
'/': 'chrome-extension://aopgehikihpnclbfeohobanjecpiefho/'
};
in your karma-e2e.conf.js file and then
browser().navigateTo('/html/application.html#/options');
in the test?