Day1 Installation
...
Duration
25 hoursCourse Price
$ 399.004.5 (23)
Protractor is an end-to-end test framework for Angular and Angular JS applications. Protractor runs tests against your application running in a real browser, interacting with it as a user would. Protractor is a node.js port of the webdriver.io, which is the JavaScript implementation of Selenium framework.
it is a Node.js program that supports test frameworks like Jasmine, Mocha, and Cucumber.
Protractor is an end-to-end test framework for AngularJS applications. It is a Node.js program that supports the Jasmine and Mocha test frameworks.
Selenium is a browser automation framework. Selenium includes the Selenium Server, the WebDriver APIs, and the WebDriver browser drivers.
So,Protractor works in conjunction with Selenium to provide an automated test infrastructure that can simulate a user’s interaction with an Angular application running in a browser or mobile device.
Mocha is a JavaScript test framework for Node.js programs. It features browser support, asynchronous testing, test coverage reports, and use of any assertion library.
Jasmine is an open source testing framework for JavaScript. It runs on any JavaScript-enabled platform. It doesn’t require a DOM. it has a clean, obvious syntax so that we can easily write tests.
We can verify tooltip text using protractor by fetching the value of ‘title’ attribute.
element(by.id("some")).getAttribute("title").then(function(tooltip){
console.log(tooltip)
}
We can get it by using getAttribute method by passing argument as value. getAttribute() method returns a promise which contains String
Syntax:
element(by.xpath("text box xpath").getAttribute("value")).then(function(textValue){
console.log(textValue)
});
We can set values by using sendKeys() method of Alerts class, we set value to the prompt Alert in Protractor.
browser.switchTo().alert().sendKeys("softwaretestingmaterial")
This can be done using addLocator method. Add a locator to this instance of ProtractorBy. This locator can then be used with element(by.locatorName(args)).
Example:
// Add the custom locator.
by.addLocator('buttonTxt', function(buttonTxt, opt_parent, opt_rootSelector) {
});
Protractor doesn’t come bundled with any reporting tool. So, based on the framework that you’re using, you can use a lot of reporters. For example, you can use Allure with Jasmine 2.0 with Protractor, Mochawesome when using with Mocha and Cucumber specific reporters when working with Cucumber.
To run multiple spec files in Protractor, you need to mention them in the spec flag in an array.
For example, let’s say I have two different spec files test1_spec.js and test2_spec.js, so I can do this
Specs: ['. /test/test1_spec.js','./test/test2_spec.js']
This will make Protractor run these multiple spec files.
Waiting for an alert to appear on a page can be performed using explicit wait in protractor.
Browser. Wait (ExpectedConditions.alertIsPresent (), 30000)
Absolutely Yes. Protractor can be used for testing non Angular JS or non Angular apps both.
It depends on the assertion framework which we are using. In general, most of the e2e
implementation done is based out of the default Jasmine 2.0
, which provides the assertion in this format
expect(something).toEqual(someotherthing)
.
In case you’re using Mocha with a Chai
as the assertion engine, you can use either of the three assertion types provided by Chai
as
expect(something).to.equal(someotherthing)
something.should.equal(someotherthing)
assert.equal(something,someotherthing)
In order to not have to do this, you need to set the directConnect
flag to true
in your conf.js
file.
Waiting for an alert to appear on a page can be performed using explicit wait in Selenium WebDriver.
browser
.wait(ExpectedConditions
.alertIsPresent(), 30000);