Sunday, 4 June 2017

POM Framework



Pom

Page Object Model, is selenium framework where we can create object of each page and call in test methods.

Same time in test case method we only call method from page.

Below is project for POM




In test package you need to use below code
As classname “Google”

package test;


import java.util.concurrent.TimeUnit;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

import pages.GoogleFun;
import pages.Guru99HomePage;
import pages.Guru99Login;

public class Google {

         
          GoogleFun objGoogle;//page obejct
         
         
         


          @Test
          public void test_Home_Page_Appear_Correct(){
                   System.setProperty("webdriver.chrome.driver", "D://Ylo//chromedriver.exe");
                   WebDriver driver = new ChromeDriver();
          //      driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
                   driver.get("https://www.webpagetest.org/");
                   System.out.println("test1");
                   System.out.println("test2");
                   //Create Login Page object
          objGoogle = new GoogleFun(driver);// calling page method
         
          objGoogle.searchButtonExist();
         
         
          }
         
}


In package “pages” you have to use “GoogleFun” as class

package test;


import java.util.concurrent.TimeUnit;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

import pages.GoogleFun;
import pages.Guru99HomePage;
import pages.Guru99Login;

public class Google {

         
          GoogleFun objGoogle;//page obejct
         
         
         


          @Test
          public void test_Home_Page_Appear_Correct(){
                   System.setProperty("webdriver.chrome.driver", "D://Ylo//chromedriver.exe");
                   WebDriver driver = new ChromeDriver();
          //      driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
                   driver.get("https://www.webpagetest.org/");
                   System.out.println("test1");
                   System.out.println("test2");
                   //Create Login Page object
          objGoogle = new GoogleFun(driver);// calling page method
         
          objGoogle.searchButtonExist();
         
         
          }
         
}

Remember you need to handle object well in POM and in test file you have to call only page methods.

For object we can create Objet Repo or we can even call it from page, example mentioned in page class

Saturday, 27 May 2017

Test cases

1. Manual Test Cases for Email: https://lnkd.in/fjyuupH
2. Manual Test Cases for Calculator: https://lnkd.in/fHBQ92M
3. Manual Test Cases for ATM Machine: https://lnkd.in/faXE8Ds
4. Manual Test Cases for Date Field: https://lnkd.in/fW7VsHb
5. Manual Test Cases for Triangle: https://lnkd.in/fanTSth
6. Manual Test Cases for LoginPage: https://lnkd.in/f9A_H6K
7. Manual Test Cases for Flight Reservation System: https://lnkd.in/fxVx3KV
8. Manual Test Cases for Google Search: https://lnkd.in/fqTpszb
9. Manual Test Cases for Coffee Machine: https://lnkd.in/f7ij4BC
10. Manual Test Cases for ATM Machine: https://lnkd.in/fn9RmMT
11. Manual Test Cases for Database Testing: https://lnkd.in/eRNNf-G
12. Manual Test Cases for Image Upload Functionality: https://lnkd.in/fJgwK79
13. Manual Test Cases for Sending Email: https://lnkd.in/f3vyKeW
14. Manual Test Cases for Security Testing: https://lnkd.in/ejE9q_z

Thursday, 9 March 2017

Extent Report for selenium

Extent report gives you online HTML Report with screenshot.

You need to have Extent report jar with you ,It also need freemarker jar, below is Jar URL,
https://jar-download.com/?detail_search=g%3A%22com.relevantcodes%22+AND+a%3A%22extentreports%22&search_type=av&a=extentreports
Below is code for extent report,


public class HomeVerification extends BaseClass {

//extent report initializatiion
       ExtentReports report;
       ExtentTest test;
      
       @Before
       public void setBrowser() {
             
              //u need to write broser launch selenium code
      
              startBrowser("chrome");
                System.out.println("browser launchead");
       }

       @Test
       public void login() throws InterruptedException, IOException {
             
             
              //report path
              report = new ExtentReports("C:\\Users\\ylondhe\\reports\\automationreport.html"true);
              //report = new ExtentReports("D:\\automationreport.html", true);
                           test = report.startTest("Verify application Home screen");
             
              driver.get("TestingURL");
              test.log(LogStatus.INFO"URL Launched started");
              String actualTitle = driver.getTitle();
              test.log(LogStatus.INFO"page title is " + actualTitle );
             
              //Thread.sleep(30000);
              (new WebDriverWait(driver, 30))
                              .until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id='headertext']")));
              List<WebElement> list = driver.findElements(By.xpath("//*[@id='navitemlist']/li[1]/a/span1"));
       //     Assert.assertTrue("Text not found!", list.size() > 0);
              System.out.println(list.size());
             
       if(list.size()>0){
          test.log(LogStatus.PASS"Element is Present");
          System.out.println("element present");
          
       }
       else{
      
       //fail scenario, capture image code
          
          File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
                     FileUtils.copyFile(scrFile,
                                  new File("D:\\img.jpg"));
                     String image = test
                                  .addScreenCapture("D:\\img.jpg");
                     test.log(LogStatus.FAIL"verify logo of the application"image);
       }
              Thread.sleep(5000);

       }

       @After
       public void closeDriver() {
              driver.close();
              report.endTest(test);
              report.flush();
       }
}

Monday, 24 October 2016

java code for repeating character

In this core java programming tutorial we will write a program to Find first non repeated character in string in java.



Write a program to find out first non-repeating character in string in java.
Example in java>
Given string =this is it
first non-repeating character in string= h

Must read: Reverse words in sentence in java.

Full Program/SourceCode/ Example to Find first non repeated character in string in java>
import java.util.LinkedHashMap;
import java.util.Map;
/** Copyright (c), AnkitMittal www.JavaMadeSoEasy.com */
public class FirstNonRepeatedCharacterInStringExample {
  
   public static void main(String[] args){
      
      String inputString="this is it";
       System.out.println("The first non repeated character in inputString("+inputString+") is :  " + firstNonRepeatedCharacter(inputString));
   }
  
   /**
    * Method returns first non-repeating character in inputString.
    * Returns null if there is no non-repeating character in inputString
    */
   public static Character firstNonRepeatedCharacter(String inputString){
       Map<Character,Integer>  map= new LinkedHashMap<Character ,Integer>(); //LinkedHashMap used so that we could maintain insertion order.
       char ar[]=inputString.toCharArray();
       char ch ;
      
       for (int i=0; i<ar.length; i++){
        ch=ar[i];
       
        if(map.containsKey(ch))   //if map already contains this character as key, get value corresponding to key and increment it.
            map.put(ch, map.get(ch)+1 );
        else        //put character in map with value as 1 (showing first occurrence of key in string)
            map.put(ch, 1) ;
       
       }   
       /*
     * Till this point of program, we have stored all unique characters in map as key & corresponding value representing count of character.
     */  
      
       for (int i=0; i<ar.length; i++ ){
        ch= ar[i];
        if( map.get(ch)  == 1 )   //we have found our first non-repeating character in string.
         return ch;
       }
       return null ;
   }
}
/*OUTPUT
The first non repeated character in inputString(this is it) is :  h
*/