Skip to content
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
Closed

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

Hardcode37 opened this issue Aug 22, 2013 · 16 comments

Comments

@Hardcode37
Copy link

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
Copy link

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

@juliemr
Copy link
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 as completed Aug 22, 2013
@tfnico
Copy link

tfnico commented Jan 17, 2014

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

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

@wayneseymour
Copy link

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

@tfnico
Copy link

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
Copy link

@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
Copy link

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
Copy link

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

@ranadheerrannu
Copy link

@tfnico. Thank u very much. it worked

@dgmchennai
Copy link

ghyjfj

@didando8a
Copy link

Great solution!!

Thanks

@ProtHelp
Copy link

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
Copy link
Contributor

@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
Copy link

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
Copy link

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests