Friday, February 22, 2019

log4j in maven testng

1. Add dependency in the pom.xml

2. Create log4j.proprties in the resource folder under/test folder

3. Copy paste the below code in the log4j.proparties file:
------------------start------------------------

#Set level log4j.rootCategory=debug, console, file # Appender which writes to console log4j.appender.console=org.apache.log4j.ConsoleAppender log4j.appender.console.layout=org.apache.log4j.PatternLayout log4j.appender.console.layout.ConversionPattern=%d{MM-dd-yyyy HH:mm:ss} %F %-5p [%t] %c{2} %L - %m%n # Appender which writes to a file log4j.appender.file=org.apache.log4j.RollingFileAppender log4j.appender.file.File=application.log # Defining maximum size of a log file log4j.appender.file.MaxFileSize=10mb log4j.appender.file.MaxBackupIndex=10 log4j.appender.file.layout=org.apache.log4j.PatternLayout log4j.appender.file.layout.ConversionPattern=%d{ISO8601} %5p [%t] %c{1}:%L - %m%n log4j.appender.file.Append=false

 ---------------end-----------------------

4. run the test

5. Refresh the project folder
application log folder is created > open that file to see logs

Thursday, February 21, 2019

Penaism by Dana Pena


Though time don’t last. Though people do.

Don’t waste time on things you can’t change.

When you deal with the opinionated or egoistical, always give credit where it isn’t due.

Business deals start and end with people- the interaction of flesh and blood, bone and sinew, heart and mind, emotion and soul.

Dream big. Think big. Be big.

Dream big. and dare to fail!

The more you investigate, the less you have to invest.
Never, ever second guess yourself.

Cash only prolongs death; it doesn’t void it.

I’ve never seen a “part-time” super successful, high performance person.

A deal has to sound good before it is good.

During Quantum growth, any problem you solve will be replaced immediately by a larger, more complicated problem.

Every party to every negotiation has comfort zone. The effective negotiator is the one who can define the boundaries of the other party’s comfort zone, then place the deal inside the boundary of the zone nearest his own interests.

Sick to your knitting. To maximize the return on invested capital, deploy your assets, resource and capabilities in those areas wherein lie your expertise and experience.

Man plans; god laughs.

You won’t always have all the answers. Only take seriously the advice of the others whom you greatly respect.

The consequences of a misguided decision are significant in the cosmos of eternity.

Always shoot for the moon. Even if you don’t hit the bulls-eye, you’ll at least get 80%.

Always, always, always pay yourself – and your employees – first! Through all economic cycles.

Plan for success. With no back-up plans, no ripcords, no fail-safes or you will fail.

Management performance sins will always be forgiven during periods of rapidly increasing revenues.

Learn to play bad golf well.

Become more disciplined. The pain of discipline hurts less than the pain of regret.

Hunger makes beast of men, and demons of beasts.

Everybody else is worried about life after death. My concern is about life before death.

The business world is divided into people with great ideas, and people who take action on those ideas.

If you want to things to change, first you have to change.
A man who dwells on his past, robs the future.

There’s a big difference between playing to win and paying not to lose.

The difference between a failure and a high performance person uses his fear to galvanize his actions.

Ignorance is a steep hill with jagged rocks at the bottom.

The only difference between a champ and a chump is “U”.

To succeed in the business, you must do more than take a step in the right direction. You have to take a Quantum Leap

A good plan executed today is better than a great plan executed next week.

In order to really succeed in business, you must have outside advisors. These must be trusted advisors, professionals at your accounting and lw firms with whom you have a very special relationship. These advisors become your moles within their own organization, more loyal to you than their employer. motivated, aggressive, ambitious and bright enough – but not as bright as he or she thinks.

You can’t win at poker or business with scared money. It gives off stench that is repugnant to the other side. If you’re going to play, leave your money at home play with OPM –Other People’s Money.

The fulfillment of your dream is directly proportional to your desire to succeed and how much you’re willing to sacrifice. If you are not prepared to die, then you are not prepared to live.

When you get rid of someone, never give them a “hook” with which to get back in. Always make a clean, definable and irrevocable break.

Quantum Leap success means fishing with nets, not just with lines.

To achieve “Hyper-growth”, avert avoidable mistakes, and let your successes run their course. Do more of what you’re doing right- and less of what you’re doing wrong.

You always need a reason to overlook the obvious.

Never underestimate how wrong you can be. Even the most careful planning can be overtaken by external events and circumstances.

Always maintain your personal relationships on the same plan upon which they were formed. True friends will rejoice in your professional successes. Allow them to enjoy them with you. Never reassess their personal and professional lives in terms of your own.

Your most valuable natural asset is your own guts instinct. Don’t be afraid of it. Your instinct has more power than all of the conventional wisdom in the world.

Business opportunities abound-  but formidable barriers exist. And the biggest barrier is psychological. It is you.

Your greatest idea, born out of revolutionary thinking and passion, will die of indifference, apathy and the cancel of low expectations.

Conventional wisdom is almost always wrong.

Absence of evidence is not evidence of absent. Just because something has never been done doesn’t mean it can’t be done. The fact you have never seen or heard something is not proof that is doesn’t exist.

Every worthy dream has a “pay=price-to-action”. That means you have to give up something to get something. You can’t have it all.

The old Kenny Rogers son, “The Gambler” has a message for CEOs. “You have got to know when to hold them, and know when to fold them.” As a CEO you’ll get more advice from your staff than you know what to do with. But it’s up to you to know when to hold them and when to fold them. Listen your staff. Listen to your gut. Make your decision and move on.

I never met a super successful, high performance person who wasn’t enthusiastic.

The best way to predict the future is to create it yourself.

A deal is either hot –or it’s not.

You don’t have to know how you’re going to get there. But you do need to know where you want to go.

If you have no destination, wherever you end up will be acceptable.

Its cost nothing to aim high – but if you aim at nothing, you’ll hit anything.

FEAR IS False Expectations Appearing Real.

“Thinking it over” is for people who can’t take actions.

Quantum Growth eliminates clear sailing. So you’d better learn to navigate troubled waters.

From chaos comes order. In chaos is opportunity- Chaordic!

Whoever said money can’t buy you happiness doesn’t know where to shop.

Insanity is doing the same thing over and over and expecting different results.
More of the same usually just gives you more of the same.

Doesn’t matter what morons say.

Give potential associates and partners the “Doofus Test”. Place them under stress to see how they react to pressure as a high performance person.

You are paid in life not for what you know, but what you can do.  Or get others to do.

Ideas are a dime a dozen. The person who puts them into action is priceless.

You’ve known all along its though to be successful. But you’d rather hear the fairy tales.

Half-truth and misinformation sell easier – and return harder.

Excuses are the crutches of the untalented and unambitious.

Everyone know how to manage success, but no one ever asks, “How do we manage failure?”

Regret for the past is a waste of the spirit – and makes no money!

Minutia never makes money. It only makes manure.

Super successful people are macro managers who know that less control mean more control.

Always respect the individual on the other side of the deal. He is not as stupid as you may think. And you’re not as smart as you think.

Logic can be a logical process which leads to a wrong conclusion.

It isn’t a case of taking a big chance. It’s a matter of giving yourself a big chance.

The more self-esteem you give others, the more you have. And the more you have, the easier it is to give away.

Most successful people do it poorly until they do it well. Just keep blundering along. You can’t wait until its exactly right. The product of quest for perfection is paralysis.

High performance people get paid for performing their hobbies.

I may be wrong- but I’m never in doubt!

Don’t hire credentials. Hire attitude.

Surprise your associates – and your enemies.
Structure follows strategy. If you base your strategy on your existing structure, you limit your potential to what you’ve already done.

Watch your peaks and troughts. As long as your lows are higher than before, your Quantum Leap Action War Plan is working.

A guarantor is fool with a pen.

No matter how tempting, never accept short-term solutions to long-term problems.

Too many companies try to patch when they should amputate. ‘Let’s reorganize and save this mess’ is a clarion call to disaster. Cut your losses, kick the cuttings out of your way, and move on.

If you want to travel above and beyond the herd, don’t try to be better. Try to be different. Or better yet, be first.

Your doubts are not the product of accurate thinking, but habitual thinking.

Find you passion and wrap your carrier around it.

Live your life on purpose!

You’ll be motivated by inspiration or desperation. It’s your choice.

People with low self-esteem protect themselves by not taking risks. High self-esteem gives you the power of confidence to take chances.

Give yourself permission to make mistakes. It’s called learning.

The only things in this life that you’ll really regret are the risks- and adventures- you didn’t take.

“Hell” can be the video of your life if only you had taken the actions to become super successful.

Nothing you’ll ever be in business is a matter of life or death. In the cosmos of time, any decision you make is a fart in the mind.

You cannot make a Quantum Leap if you don’t share the wealth with your Dream Team and employees –be it cash, equity, options or warrants that are tangible rewards for performance and loyalty.

Never, ever share your doubt with anyone but your mentor.

Being all you can be is possible for anyone, but…

…. super success is not for everyone. Period.

Fear of failure is caused by lack of self-esteem and confidence. Dealing with fear is the key to super success.

Don’t take high performance advice from your peers, family or friends unless they are high performance people themselves.

You cannot grow exponentially by yourself. You need to support of others.

Don’t set time for achieving goals. They should transcend time.

Set goals you cannot achieve in your lifetime.

Business should not run smoothly while you’re making your Quantum Leap. Chaos is normal. The nosiness on quite waters is still in the harbor.

Life is what happens while you’re making other plans.

The road to success is always under construction.

Get ruthless about trying something different.

Motivation is your “fire in the belly”. But unless its fueled it goes out.

I have no more mountains left to climb – but myself!

Don’t focus on mistakes; focus on the positive say “next time”!

Progress often masquerades as trouble.

We must all remember life doesn’t have to be fair for us to succeed, if we take change and become masters and creators of own destiny!

The older you get, the less you are surprised.

Important topics to lean in Selenium

  • Selenium Webdriver 3.x
  • Java Concepts in details
  • TestNG Framework
  • Advanced Reporting
  • Logging infrastructure with Log4j
  • Page Object Model
  • Page Factory Framework
  • Data Driven Framework
  • Executing tests on a remote machine using Selenium Grid 2.0
  • Build Management with Maven
  • Continuous Integration with Jenkins
  • Database Testing
  • Performance Testing
  • Behavior Driven Testing Using Cucumber and Gherkin language

Important topics to lean in java for Selenuim

OOPS Concept

Basic concept of Oops like
Class
Object
Inheritance
Polymorphism
Abstraction

List of keywords, Interface in Java.

Handle data types and usage of same.

Strings class

Control statements.

Looping statements.

String class, Wrapper classes, Array (2 D arrays)

Exception handling.

Collection framework (List, Set)

File handling.

Packages and Eclipse usages.



Tuesday, February 19, 2019

FormulaEvaluator in Apache POI

 import java.io.File;  
 import java.io.FileInputStream;  
 import java.io.IOException;  
 import org.apache.poi.ss.usermodel.Cell;  
 import org.apache.poi.ss.usermodel.FormulaEvaluator;  
 import org.apache.poi.ss.usermodel.Row;  
 import org.apache.poi.ss.usermodel.Sheet;  
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;  
 public class Excel2 {  
      static Object[][] nana = null;  
      public static void read() throws IOException, IOException {  
           String filepath = "C:\\Users\\Mutturaj\\Desktop\\muttu.xlsx";  
           XSSFWorkbook workbook = new XSSFWorkbook(new FileInputStream(new File(filepath)));  
           Sheet sheet = workbook.getSheetAt(0);  
           FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator();  
           for (Row row : sheet) {  
                for (Cell cell : row) {  
                     switch (evaluator.evaluateInCell(cell).getCellType()) {  
                     case Cell.CELL_TYPE_STRING:  
                          System.out.print(cell.getStringCellValue() + "\t\t");  
                          break;  
                     case Cell.CELL_TYPE_NUMERIC:  
                          System.out.print(cell.getNumericCellValue() + "\t\t");  
                     }  
                }  
                System.out.println();  
           }  
      }  
      public static void main(String[] args) throws IOException {  
           Excel2.read();  
      }  
 }  

Monday, February 18, 2019

Retrieve data from excel , data provider and TestNG

 import java.io.File;  
 import java.io.FileInputStream;  
 import java.io.IOException;  
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;  
 import org.apache.poi.ss.usermodel.Row;  
 import org.apache.poi.ss.usermodel.Sheet;  
 import org.apache.poi.ss.usermodel.Workbook;  
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;  
 import org.testng.annotations.DataProvider;  
 public class PoiEx {  
      static Object[][] names = null;  
      static String filePath = "C:\\Users\\Mutturaj\\Desktop";  
      public static Object[][] readExcel(String filePath, String filename, String sheetName) throws IOException {  
           File file = new File(filePath + "\\" + filename);  
           FileInputStream fileInputStream = new FileInputStream(file);  
           Workbook workbook = null;  
           String fileextensionname = filename.substring(filename.indexOf("."));  
           if (fileextensionname.equals(".xlsx")) {  
                workbook = new XSSFWorkbook(fileInputStream);  
           } else if (fileextensionname.equals(".xls")) {  
                workbook = new HSSFWorkbook(fileInputStream);  
           }  
           // Get sheet by name  
           Sheet sheet = workbook.getSheet(sheetName);  
           // Count rows in the sheet  
           int rowCount = sheet.getLastRowNum();  
           int colCount = 2;  
           names = new Object[rowCount + 1][colCount];  
           for (int i = 0; i < rowCount + 1; i++) {  
                Row row = sheet.getRow(i);  
                int lastCellNumber = row.getLastCellNum();  
                for (int j = 0; j < lastCellNumber; j++) {  
                     names[i][j] = (row.getCell(j).getStringCellValue());  
                }  
           }  
           return names;  
      }  
      @DataProvider(name = "array")  
      public Object[][] nana() throws IOException {  
           Object[][] array = PoiEx.readExcel(filePath, "muttu.xlsx", "muttu");  
           return array;  
      }  
      
 }  



 import org.testng.annotations.AfterMethod;  
 import org.testng.annotations.AfterTest;  
 import org.testng.annotations.BeforeMethod;  
 import org.testng.annotations.BeforeTest;  
 import org.testng.annotations.Test;  
 public class NGTest1 {  
      @BeforeTest()  
      public void loadFile() {  
           System.out.println("File open....");  
      }  
      @BeforeMethod  
      public void openBrowser() {  
           System.out.println("Browser opened************");  
      }  
      @AfterMethod  
      public void closeBrowser() {  
           System.out.println("**************Close browser");  
      }  
      @Test(priority = 1, dataProvider = "array", dataProviderClass = PoiEx.class)  
      public void add(String first, String second) {  
           System.out.println(first);  
           System.out.println(second);  
      }  
      @Test(priority = 2)  
      public void substract() {  
           System.out.println("Substraction");  
      }  
      @Test(priority = 3)  
      public void Multiply() {  
           System.out.println("Multiply");  
      }  
      @Test(priority = 4)  
      public void Divide() {  
           System.out.println("Divide");  
      }  
      @AfterTest  
      public void closeFile() {  
           System.out.println("File closed.....");  
      }  
 }  

Sunday, February 17, 2019

@Data Provider and other Annotations of TestNG

 import org.testng.annotations.AfterMethod;  
 import org.testng.annotations.AfterTest;  
 import org.testng.annotations.BeforeMethod;  
 import org.testng.annotations.BeforeTest;  
 import org.testng.annotations.DataProvider;  
 import org.testng.annotations.Test;  
 public class NGTest1 {  
      @BeforeTest()  
      public void loadFile() {  
           System.out.println("File open....");  
      }  
      @BeforeMethod  
      public void openBrowser() {  
           System.out.println("Browser opened************");  
      }  
      @AfterMethod  
      public void closeBrowser() {  
           System.out.println("**************Close browser");  
      }  
      @DataProvider(name = "Numbers")  
      public static Object[][] getMumbers() {  
           return new Object[][] { { 1, 2,3}, { 4, 5,6 } };  
      }  
      @Test(priority = 1, dataProvider = "Numbers")  
      public void add(int number1, int number2,int number3) {  
           System.out.println(number1);  
           System.out.println(number2);  
           System.out.println(number3);  
           System.out.println("Total "+ number1+number2+number3);  
      }  
      @Test(priority = 2)  
      public void substract() {  
           System.out.println("Substraction");  
      }  
      @Test(priority = 3)  
      public void Multiply() {  
           System.out.println("Multiply");  
      }  
      @Test(priority = 4)  
      public void Divide() {  
           System.out.println("Divide");  
      }  
      @AfterTest  
      public void closeFile() {  
           System.out.println("File closed.....");  
      }  
 }  

Thursday, February 14, 2019

Retrieve data from xls/xlsx file by Apache POI

 import java.io.File;  
 import java.io.FileInputStream;  
 import java.io.IOException;  
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;  
 import org.apache.poi.ss.usermodel.Row;  
 import org.apache.poi.ss.usermodel.Sheet;  
 import org.apache.poi.ss.usermodel.Workbook;  
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;  
 public class PoiEx {  
      public void readExcel(String filePath, String filename,String sheetName) throws IOException{  
           File file=new File(filePath+"\\"+filename);  
           FileInputStream fileInputStream=new FileInputStream(file);  
           Workbook workbook=null;  
           String fileextensionname=filename.substring(filename.indexOf("."));  
           if(fileextensionname.equals(".xlsx")){  
                workbook=new XSSFWorkbook(fileInputStream);  
           }else if(fileextensionname.equals(".xls")){  
                workbook=new HSSFWorkbook(fileInputStream);  
           }  
           //Get sheet by name  
           Sheet sheet=workbook.getSheet(sheetName);  
           //Count rows in the sheet  
           int rowCount=sheet.getLastRowNum()-sheet.getFirstRowNum();  
           for(int i=0;i<rowCount+1;i++){  
                Row row=sheet.getRow(i);  
                int lastCellNumber=row.getLastCellNum();  
                for(int j=0;j<lastCellNumber;j++){  
                     System.out.print(row.getCell(j).getStringCellValue()+" ");  
                }  
                System.out.println();  
           }  
      }  
      public static void main(String[] args) throws IOException {  
           // TODO Auto-generated method stub  
                PoiEx ex=new PoiEx();  
                String filePath="C:\\Users\\Mutturaj\\Desktop";  
                ex.readExcel(filePath, "muttu.xlsx", "muttu");  
      }  
 }  

File I/O Java

   
  import java.io.*;   
  public class fileStreamTest {   
   public static void main(String args[]) {   
   try {   
    byte bWrite [] = {11,21,3,40,5};   
    OutputStream os = new FileOutputStream("test.txt");   
    for(int x = 0; x < bWrite.length ; x++) {   
     os.write( bWrite[x] ); // writes the bytes   
    }   
    os.close();   
    InputStream is = new FileInputStream("test.txt");   
    int size = is.available();   
    for(int i = 0; i < size; i++) {   
     System.out.print((int)is.read() + " ");   
    }   
    is.close();   
   } catch (IOException e) {   
    System.out.print("Exception");   
   }      
   }   
  }   
output:

Monday, February 11, 2019

Enumeration, static and initialize block in java


 package Interfaces;  
 enum Color{  
      RED, GREEN, BLUE;  
 }  
 public class Emunz {  
      private static String offday;  
      {  
           System.out.println("*********initializer block********************");  
      }  
      static{  
           System.out.println("****************Static block**************");  
           offday="Sunday";  
           System.out.println(offday);  
      }       
      public Emunz() {  
           System.out.println("Constructor");  
      }  
      public static void main(String[] args) {       
           Emunz emunz=new Emunz();  
           System.out.println(Color.BLUE);  
           System.out.println(Emunz.offday);  
           Emunz emunz1=new Emunz();  
      }  
 }  

Access Levels in Java



Modifier
Class
Package
Subclass
World
public
 Y
Y
Y
Y
protected
Y
Y
Y
N
no modifier
Y
Y
N
N
private
Y
N
N
N
*no modifier is: Package private

Saturday, February 9, 2019

String Manipulations


 public class Str {  
  public static void main(String[] args) {  
  String s = "Mutturaj Hulagabal";  
  System.out.println(s.charAt(4));  
  System.out.println(s.length());  
  String trim = s.trim();  
  System.out.println(trim.length());  
  System.out.println(s.concat("Atharga"));  
  System.out.println(s.contains("Muttu"));  
  System.out.println(s.indexOf("H"));  
  System.out.println(s.compareTo("Naveen Patil"));  
  System.out.println(s.toUpperCase() + " " + s.toLowerCase());  
  System.out.println(s.compareTo("Mutturaj Hulagabal"));  
  System.out.println(s.compareToIgnoreCase("mutturaj hulagabal"));  
  System.out.println(s.isEmpty());  
  // Sub String  
  System.out.println(s.substring(9));  
  System.out.println(s.substring(0, 8));  
  // Object  
  System.out.println(s.equals("Mutturaj Hulagabal"));  
  }  
 }  


Formatter and scanner in Java.Util package


 import java.io.File;  
 import java.io.FileNotFoundException;  
 import java.util.Formatter;  
 import java.util.Scanner;  
 public class CSVFile {  
  Formatter formatter;  
  Scanner scanner;  
  public void createFile() {  
  try {  
   formatter = new Formatter("muttu1.txt");  
  } catch (FileNotFoundException exception) {  
   exception.printStackTrace();  
  }  
  }  
  public void writeFile() {  
  formatter.format("%s,%s,%s", "muttu", "pavu", "navu");  
  }  
  public void closeFile() {  
  formatter.close();  
  }  
  public void readFile() throws FileNotFoundException {  
  scanner = new Scanner(new File("muttu1.csv"));  
  while (scanner.hasNext()) {  
   String x = scanner.next();  
   System.out.println(x);  
  }  
  }  
  public static void main(String[] args) throws FileNotFoundException {  
  CSVFile csvFile = new CSVFile();  
  csvFile.createFile();  
  csvFile.writeFile();  
  csvFile.closeFile();  
  csvFile.readFile();  
  csvFile.closeFile();  
  }  
 }