Saturday 19 August 2017

Protrator Set up with Eclipse as editor






Installing Protractor

To set up protractor, we need to install below three things  :

1. Node.js

2. Protractor

3. Selenium Webdriver



Step 1:   Node.js  Setup

-  First we have to install NodeJS.   (https://nodejs.org/en/download/)

-  Click on Windows Installer

- Once the download has finished , proceed to installation by click on downloaded exe file .

- Now to see if the installation is done successfully, you can go and check in   variables. The path will be defined automatically.  To open system environment : Click on  Start > select Control Panel >double click System > select the Advanced tab                    Or

You can also check from the command prompt by typing the command 'npm  -version ' and press Enter in command prompt



Step 2:   Protractor Setup

- To install protractor globally we need to use “npm install –g protractor” in cmd

-To check version of protractor we have to use – “protractor--version”





Step 3:   Webdriver Setup

- To install Webdriver , we need to use “npm install -g webdriver-manager” in cmd

- To setting up selenium server , we need to use “webdriver-manager update” in cmd

-Before running any protractor script we need to turn on selenium server with command

“webdriver- manager start”



Use below code as test.spec



describe('angularjs homepage todo list', function() {
  it('should add a todo', function() {
    browser.get('https://angularjs.org');

    element(by.model('todoList.todoText')).sendKeys('write first protractor test');
    element(by.css('[value="add"]')).click();

    var todoList = element.all(by.repeater('todo in todoList.todos'));
    expect(todoList.count()).toEqual(3);
    expect(todoList.get(2).getText()).toEqual('write first protractor test');

    // You wrote your first test, cross it off the list
    todoList.get(2).element(by.css('input')).click();
    var completedAmount = element.all(by.css('.done-true'));
    expect(completedAmount.count()).toEqual(2);
  });
});



and below code as conf.js

exports.config = {
  seleniumAddress: 'http://localhost:4444/wd/hub',
  specs: ['todo-spec.js']
};

Try both code keep in npm folder if network securities are more in your office


run the code using CMD by reaching in folder

"protractor conf.js"



Now with integrated with Eclipse try below steps



Yes, you can use protractor plugin in eclipse.

   1. Go to help-->Marketplace
   2. Search for tern.java
   3. Install Tern Eclipse IDE
   4. and accept the licence.

Now create a project in eclipse

   5. Right click on project-JS project,
   6. Add node_module from c folder to eclipse, add above 2 files in project








Installing Protractor

To set up protractor, we need to install below three things  :

1. Node.js

2. Protractor

3. Selenium Webdriver



Step 1:   Node.js  Setup

-  First we have to install NodeJS.   (https://nodejs.org/en/download/)

-  Click on Windows Installer

- Once the download has finished , proceed to installation by click on downloaded exe file .

- Now to see if the installation is done successfully, you can go and check in   variables. The path will be defined automatically.  To open system environment : Click on  Start > select Control Panel >double click System > select the Advanced tab                    Or

You can also check from the command prompt by typing the command 'npm  -version ' and press Enter in command prompt



Step 2:   Protractor Setup

- To install protractor globally we need to use “npm install –g protractor” in cmd

-To check version of protractor we have to use – “protractor--version”





Step 3:   Webdriver Setup

- To install Webdriver , we need to use “npm install -g webdriver-manager” in cmd

- To setting up selenium server , we need to use “webdriver-manager update” in cmd

-Before running any protractor script we need to turn on selenium server with command

“webdriver- manager start”



Use below code as test.spec



describe('angularjs homepage todo list', function() {
  it('should add a todo', function() {
    browser.get('https://angularjs.org');

    element(by.model('todoList.todoText')).sendKeys('write first protractor test');
    element(by.css('[value="add"]')).click();

    var todoList = element.all(by.repeater('todo in todoList.todos'));
    expect(todoList.count()).toEqual(3);
    expect(todoList.get(2).getText()).toEqual('write first protractor test');

    // You wrote your first test, cross it off the list
    todoList.get(2).element(by.css('input')).click();
    var completedAmount = element.all(by.css('.done-true'));
    expect(completedAmount.count()).toEqual(2);
  });
});



and below code as conf.js

exports.config = {
  seleniumAddress: 'http://localhost:4444/wd/hub',
  specs: ['todo-spec.js']
};

Try both code keep in npm folder if network securities are more in your office


run the code using CMD by reaching in folder

protractor conf.js



Now with integrated with Eclipse try below steps



Yes, you can use protractor plugin in eclipse.

   1. Go to help-->Marketplace
   2. Search for tern.java
   3. Install Tern Eclipse IDE
   4. and accept the licence.

Now create a project in eclipse

   5. Right click on project-JS project,
   6. Add node_module from c folder to eclipse, add above 2 files in project


   7.  Mouse hover to configure and
    Click on convert to tern project
 
 


  8.  Right click and click Run as configure add main tab as conf.js and project name in directory
      and protractor tab as cli.js(go till node module),click on Done, select protractor and save
  9. RUn the script using eclipse
     

  



Sunday 6 August 2017

WebService Automation Using Java



WebService Automation For REST


Webservice automation with java is simple, You have to convert json response in pojo and verify it using java, below are step for 1 of login request for REST
 


1. create Eclipse MVN Prject
2. Add rest assured mvn dependancies (restassured)
3. Add json dependancies in pom
3. Create folder structure like below



4. service package- create service login.java

Copy  below code for loginREquest

public class Service {
      
       /**
        * This API will perform login operation
        * @param loginId
        * @param loginSource
        * @param password
        * @return
        */
       public Response login(String loginId, String loginSource,String password){
              try {
                     LoginPojo loginpojo = new LoginPojo();
                     Login login = new Login();
                     login.setLoginId(loginId);
                     login.setLoginSource(loginSource);
                     login.setPassword(password);
                     loginpojo.setLogin(login);
                     JSONObject jsonObj = new JSONObject(loginpojo);
                     RequestSpecification requestSpecification = RestAssured.given();
                     requestSpecification.headers("content-type","application/json");
                     requestSpecification.body(jsonObj.toString());
                     Response reponse = requestSpecification.post(URLBuilder.loginurl);
                    
                     return reponse;
              } catch (Exception e) {
                     e.printStackTrace();
              }
              return null;
             
       }

5. create(register) user on below URL
6. Add same url in URLBuilder.java
public class URLBuilder {
       public final static  String loginurls = "http://localhost:8080/Retail_App_Rest/retail/admin/login";
      
}

7. Take below code in loginApi.java

public class LoginApiTest {
       Service service;
       Response responseData;
       @Test
       public void loginApiTest(){
               service = new Service();
       responseData= service.login("new user created in step 5", "APP", "step 5 Password");
       System.out.println(responseData.asString());
      
             
       }

8. Run Login API, and take response from console

9. convert json to pojo from below site, use below setting which mentioned in right




10. Add response pojo code in ResponsePojoLogin.java
- You ll get 3 classes, You need to create 3 .java in  same package, only change Example.java as LoginPojoResponse

8. change loginapi.java with below code and verify response

public class LoginApiTest {
       Service service;
       Response responseData;
       @Test
       public void loginApiTest(){
               service = new Service();
       responseData= service.login("new user created in step 5", "APP", "step 5 Password");
       System.out.println(responseData.asString());
       Gson gson = new Gson();
       LoginResponsePojo data = gson.fromJson(responseData.asString(), LoginResponsePojo.class);
      
       CustomerWrapper getCustomerWrapper = data.getCustomerWrapper();
       System.out.println(getCustomerWrapper.getResponseCode());
       Customers getCustomers=getCustomerWrapper.getCustomers();
       System.out.println(getCustomers.getFirstName());
       Assert.assertEquals(getCustomers.getLoginId(),"new user created in step 5");