Javascript protractor commands. issue



  1. Protractor is a Node.js program,To run, you will need to have Node.js installed. You will download Protractor package using npm, which comes with Node.js.
  2. By default, Protractor uses the Jasmine test framework for its testing interface.

Setup

Use npm to install Protractor globally with:

npm install -g protractor

This will install two command line tools, protractor and webdriver-manager. Try running protractor --version to make sure it's working.

The webdriver-manager is a helper tool to easily get an instance of a Selenium Server running. Use it to download the necessary binaries with:

webdriver-manager update

Now start up a server with:

webdriver-manager start

This will start up a Selenium Server and will output a bunch of info logs. Your Protractor test will send requests to this server to control a local browser. Leave this server running throughout the tutorial. You can see information about the status of the server at http://localhost:4444/wd/hub.



// spec.js
describe('Protractor Demo App', function() {
  it('should have a title', function() {
    browser.get('http://juliemr.github.io/protractor-demo/');

    expect(browser.getTitle()).toEqual('Super Calculator');
  });
});

The describe and it syntax is from the Jasmine framework. browser is a global created by Protractor, which is used for browser-level commands such as navigation with browser.get.

Now create the configuration file. Copy the following into conf.js:

// conf.js
exports.config = {
  framework: 'jasmine',
  seleniumAddress: 'http://localhost:4444/wd/hub',
  specs: ['spec.js']
}

This configuration tells Protractor where your test files (specs) are, and where to talk to your Selenium Server (seleniumAddress). It specifies that we will be using Jasmine for the test framework. It will use the defaults for all other configuration. Chrome is the default browser.

Now run the test with

protractor conf.js

You should see a Chrome browser window open up and navigate to the Calculator, then close itself (this should be very fast!). The test output should be 1 tests, 1 assertion, 0 failures. Congratulations, you've run your first Protractor test!



npm install -g protractor

npm install node

webdriver-manager start - selenium server start 

webdriver-manager update  - selenium server update

execute js file -

node filename.js

exec proc file

protractor configuration.js 





issue :

npm install permission denied (macOS)


solution

  1. To check the location of the package:

    npm config get prefix

  2. Then run this :

    sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}




Commands:

describe('',function(){
it('',function(){
browser.get('http://juliemr.github.io/protractor-demo/');
element(by.model("first")).sendKeys("3").then(function(){
browser. sleep(5000);
console.log("Entering 3 into text box");
})
element(by.model('second')).sendKeys("4").then(function(){
browser. sleep(5000);
console.log("entering into second");
})
element(by.id('gobutton')).click().then(function(){
console.log("clicking on the button GO");
})
//ASSERTIONS:
//compare the expected and the actual
expect(element(by.css("h2[class='ng-binding']")).getText()).toBe('7');
//compare the expected and is not equal the actual
expect(element(by.css("h2[class='ng-binding']")).getText()).not.toBe('17');

//get the text from the webpage
element(by.css("h2[class='ng-binding']")).getText().then(function(text){
console.log(text);
console.log('getting the text after additions')
})

});
});

//CSS : tagname[attribute= 'value']];


describe('',function(){
it('',function(){

browser.get("http://juliemr.github.io/protractor-demo/");

element(by.model("first")).sendKeys("3").then(function(){
browser.sleep(5000);
})
element(by.model("second")).sendKeys("5").then(function(){
browser.sleep(5000);
})
element(by.id('gobutton')).click().then(function(){
browser.sleep(5000);
})
element(by.repeater("result in memory")).element(by.css("td:nth-child(3)")).getText().
then(function(text){
console.log(text);
})
element(by.repeater("result in memory")).element(by.css("td:nth-child(1)")).getText().then(function(text){
console.log(text);
})



});
});

Comments

Popular posts from this blog

Implicit and Explicit Waits,FluentWait,PageLoadTimeOut

A Interview Questions- selenium