protractor icon indicating copy to clipboard operation
protractor copied to clipboard

Can protractor test a login that is not angular based

Open Hardcode37 opened this issue 13 years ago • 16 comments

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

Hardcode37 avatar Aug 22 '13 15:08 Hardcode37

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

stickel avatar Aug 22 '13 19:08 stickel

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

andresdominguez avatar Aug 22 '13 21:08 andresdominguez

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 avatar Aug 22 '13 22:08 juliemr

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

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

tfnico avatar Jan 17 '14 09:01 tfnico

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

wayneseymour avatar Jan 23 '14 09:01 wayneseymour

@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 avatar Jan 23 '14 10:01 tfnico

@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 avatar Jan 23 '14 10:01 wayneseymour

@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 avatar Jan 23 '14 10:01 tfnico

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

wayneseymour avatar Jan 23 '14 15:01 wayneseymour

@tfnico. Thank u very much. it worked

ranadheerrannu avatar May 30 '14 05:05 ranadheerrannu

ghyjfj

dgmchennai avatar Aug 14 '14 10:08 dgmchennai

Great solution!!

Thanks

didando8a avatar Jun 08 '15 14:06 didando8a

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 avatar Nov 06 '15 12:11 ProtHelp

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

NickTomlin avatar Nov 06 '15 17:11 NickTomlin

I am trying to use browser.driver and it throws the exception saying driver is not defined. Can someone suggest how to debug further

philipb4u avatar Oct 19 '16 07:10 philipb4u

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

VinishaDsouza avatar Dec 02 '16 16:12 VinishaDsouza