Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Protractor testing: How to set the value of text elements in a login form?

I am writing tests in Protractor for an Angular app. I want to fill out a login form and submit it.

How can I do this? I have got this far, but I don't know how to set the value of the email and password fields.

describe('The dashboard', function() {   ptor = protractor.getInstance();    beforeEach(function() {     ptor.get('#/dashboard');     var email = ptor.findElement(protractor.By.model('email'));     var password = ptor.findElement(protractor.By.model('password'));     var submit = ptor.findElement(protractor.By.tagName('button'));     // Fill out the form?     submit.click();   });    it('has a heading', function() {     heading = ptor.findElement(protractor.By.tagName('h1'));     expect(heading.getText()).toEqual('My Dashboard');   }); }); 
like image 204
Richard Avatar asked Nov 25 '13 12:11

Richard


People also ask

How to test CSS property of an element in protractor?

We are going to create a basic test program in which we are going to test the CSS property of an element. All the Protractor tests will have a file that will contain the configuration and this will be the initial file that will initiate the test. Now let’s create our HTML file called test.html which will contain the element to be tested.

How do I write a test in protractor?

Write a test. Open a new command line or terminal window and create a clean folder for testing. Protractor needs two files to run, a spec file and a configuration file. Let's start with a simple test that navigates to the todo list example in the AngularJS website...

Is it possible to use gettext () function in protractor?

getText() function won't work like the way it used to be for webdriver, in order to get it work for protractor you will need to wrap it in a function and return the text something like we did for our protractor framework we have kept it in a common function like -.

What is protractor?

Protractor is an end-to-end test framework for Angular and AngularJS applications. Protractor runs tests against your application running in a real browser, interacting with it as a user would. Protractor is built on top of WebDriverJS, which uses native events and browser-specific drivers to interact with your application as a user would.


2 Answers

Just for the benefit of anyone who found this via Google, the answer is:

email.sendKeys('[email protected]'); password.sendKeys('mypassword'); 
like image 122
Richard Avatar answered Oct 11 '22 00:10

Richard


you can use

email.clear().sendKeys('[email protected]'); password.clear().sendKeys('mypassword'); 
like image 33
shruti dalvi Avatar answered Oct 11 '22 00:10

shruti dalvi