Can protractor test a login that is not angular based
This question is on stackoverflow.
I am testing an application written predominantly in angularjs however some elements of the application are written in .NET C#, such as the login form.
My question is this.
Can I leverage Protractor and test my application fully with e2e testing.
I have tried using protractor and I am happy with it thus far. However I do not seem to be able to test a page that written in .NET. I am not sure if this is because protractor only tests the elements of an angular application or if it is the way I have written my tests.
I have tried searching for the elements in the page like the example below.
ptor.findElement(protractor.By.xpath('/html/body/div/div[1]/section/input')).sendKeys('xxx');
But this only returns an UnknownError: javascript error: cannot call method 'get' of undefined.
I know that this error means the elements are not visible on the page, however I have placed a timeout in my test shown below to see if this helps. I have also tried sleep(5000) but this doesn't help either.
it('test if div apears', function () { ptor = protractor.getInstance(); ptor.get('/Test/Index'); var text = ptor.findElement(protractor.By.xpath('/html/body/div/div[1]/section/input')).sendKeys('xxx'); expect(text).toEqual('Index'); }, 10000);
all I require is to be able to add text to a dynamically created input box, created by Html.TextBoxFor()
Angular needs to be available on the page in order for Protractor to work. If Angular isn't available on the page you'll need an instance of webdriver (see the Mocha example). Once you have an instance of webdriver you should be able to do this:
// ptor variable is set in the before function
it('test if div appears', function() {
ptor.driver.get('/Test/Index');
ptor.driver.findElement(protractor.By.xpath('/html/body/div/div[1]/section/input')).sendKeys('whatever');
ptor.driver.findElement(protractor.By.xpath('/html/body/div/div[1]/section/input')).getAttribute('value')
.then(function(value) {
expect(value).toEqual('whatever');
});
});
In my project I have a unit test to login into the application. The login page is not an angular app. This is the first test listed in the specs: [] attribute of the config file.
Here is my implementation:
var protractor = require('protractor');
require('../node_modules/protractor/jasminewd');
var config = require('../settings.js').getConfig();
describe('login', function() {
it('should login', function() {
var ptor = protractor.getInstance();
var driver = ptor.driver;
var findByName = function(name) {
return driver.findElement(protractor.By.name(name));
};
driver.get(config.url);
findByName('Email').sendKeys(config.user);
findByName('Passwd').sendKeys(config.password);
findByName('signIn').click();
});
});
Yup, the correct way to do this is to use the webdriver directly. It can be grabbed from a protractor instance as ptor.driver.
More recently, it's available as browser.driver, I believe:
browser.driver.findElement(by.id('username')).sendKeys('tfnico');
So, do you all see many users of protractor not using Angular?
@wayneseymour In our case, we have a non-Angular login page we need to get through before we can start testing the Angular parts.
@tfnico thanks for the response. Well I've been eval-ing a handful of JS libs for e2e testing and Protracotr seems solid, but we are not using angular (yet).
Do you think I should?
@wayneseymour I don't think this discussion belongs in a closed issue. Please ask on the Angular mailing list instead:
https://groups.google.com/d/forum/angular
@tfnico My apologies, you are right...and thanks. :)
@tfnico. Thank u very much. it worked
ghyjfj
Great solution!!
Thanks
Hi , I am new to protractor and i am trying to run few sample tests on non- angular pages, Following is the code i am trying to run on google page:
describe('cct homepage',function(){ it('should open the page with title',function() { browser.manage().timeouts().setScriptTimeout(60000); browser.pause(5000); browser.ignoreSynchronization=true; browser.get("http://google.com",400000); browser.sleep(2000); element(by.id('q')).sendKeys('hi'); });
protractor is unable to locate element. Can you help me with this issue ?
@ProtHelp please ask a question on stackoverflow with the 'protractor' tag or post in the Gitter Channel to get help.
From the the getting help section of the README:
Please ask usage and debugging questions on StackOverflow (use the "protractor" tag) or in the Angular discussion group. (Please do not ask support questions here on Github.)
I am trying to use browser.driver and it throws the exception saying driver is not defined. Can someone suggest how to debug further
I am having the same error too, i cant find browser.driver :(