New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can protractor test a login that is not angular based #51

Closed
Hardcode37 opened this Issue Aug 22, 2013 · 16 comments

Comments

Projects
None yet
@Hardcode37

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()

@stickel

This comment has been minimized.

Show comment
Hide comment
@stickel

stickel Aug 22, 2013

Contributor

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');
        });
});
Contributor

stickel commented Aug 22, 2013

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');
        });
});
@andresdominguez

This comment has been minimized.

Show comment
Hide comment
@andresdominguez

andresdominguez Aug 22, 2013

Contributor

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();
  });
});
Contributor

andresdominguez commented Aug 22, 2013

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();
  });
});
@juliemr

This comment has been minimized.

Show comment
Hide comment
@juliemr

juliemr Aug 22, 2013

Member

Yup, the correct way to do this is to use the webdriver directly. It can be grabbed from a protractor instance as ptor.driver.

Member

juliemr commented Aug 22, 2013

Yup, the correct way to do this is to use the webdriver directly. It can be grabbed from a protractor instance as ptor.driver.

@juliemr juliemr closed this Aug 22, 2013

@tfnico

This comment has been minimized.

Show comment
Hide comment
@tfnico

tfnico Jan 17, 2014

More recently, it's available as browser.driver, I believe:

browser.driver.findElement(by.id('username')).sendKeys('tfnico');

tfnico commented Jan 17, 2014

More recently, it's available as browser.driver, I believe:

browser.driver.findElement(by.id('username')).sendKeys('tfnico');
@wayneseymour

This comment has been minimized.

Show comment
Hide comment
@wayneseymour

wayneseymour Jan 23, 2014

So, do you all see many users of protractor not using Angular?

So, do you all see many users of protractor not using Angular?

@tfnico

This comment has been minimized.

Show comment
Hide comment
@tfnico

tfnico Jan 23, 2014

@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 commented Jan 23, 2014

@wayneseymour In our case, we have a non-Angular login page we need to get through before we can start testing the Angular parts.

@wayneseymour

This comment has been minimized.

Show comment
Hide comment
@wayneseymour

wayneseymour Jan 23, 2014

@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?

@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?

@tfnico

This comment has been minimized.

Show comment
Hide comment
@tfnico

tfnico Jan 23, 2014

@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 commented Jan 23, 2014

@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‎

@wayneseymour

This comment has been minimized.

Show comment
Hide comment
@wayneseymour

wayneseymour Jan 23, 2014

@tfnico My apologies, you are right...and thanks. :)

@tfnico My apologies, you are right...and thanks. :)

@ranadheerrannu

This comment has been minimized.

Show comment
Hide comment
@ranadheerrannu

ranadheerrannu May 30, 2014

@tfnico. Thank u very much. it worked

@tfnico. Thank u very much. it worked

@dgmchennai

This comment has been minimized.

Show comment
Hide comment

ghyjfj

@didando8a

This comment has been minimized.

Show comment
Hide comment
@didando8a

didando8a Jun 8, 2015

Great solution!!

Thanks

Great solution!!

Thanks

@ProtHelp

This comment has been minimized.

Show comment
Hide comment
@ProtHelp

ProtHelp Nov 6, 2015

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 commented Nov 6, 2015

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 ?

@NickTomlin

This comment has been minimized.

Show comment
Hide comment
@NickTomlin

NickTomlin Nov 6, 2015

Member

@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.)

Member

NickTomlin commented Nov 6, 2015

@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.)

@philipb4u

This comment has been minimized.

Show comment
Hide comment
@philipb4u

philipb4u Oct 19, 2016

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 trying to use browser.driver and it throws the exception saying driver is not defined. Can someone suggest how to debug further

@VinishaDsouza

This comment has been minimized.

Show comment
Hide comment
@VinishaDsouza

VinishaDsouza Dec 2, 2016

I am having the same error too, i cant find browser.driver :(

I am having the same error too, i cant find browser.driver :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment