Sunday, May 3, 2020

How to Handle Dynamic Frame with Base class

package com.seleniumpractice;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class Base {
public static WebDriver driver;
public static String path="C:\\Users\\admin\\Desktop\\Selenium_software\\chromedriver.exe\\";
public static String url="https://paytm.com/";

   public static void config() {
   System.setProperty("webdriver.chrome.driver",path);
   driver=new ChromeDriver();
   driver.get(url);
   driver.manage().window().maximize();
   driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
   }
 
   public static void closeBrowser() {
   driver.close();
   }
   public static void quitbrowser() {
   driver.quit();
   }
   public static void testcasePased() {
   System.out.println("********** Test case passed ************");
   }
   public static void testFiledPased() {
   System.out.println("********** Test case Filed ************");
   }
   public static void executionSuccessfully() {
   System.out.println("********** Script is executed successfully ************");
   }
 
   public static void switchWindow(String str) {
   driver.switchTo().window(str);
   }
 
   public static void compareText(String actualStr,String expStr) {
   if(actualStr.contentEquals(expStr)) {
   Base.testcasePased();
   }
   else {
   Base.testFiledPased();
   }
   }
 
   public static void sleepWeb(int i) {
   try {
Thread.sleep(i);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
   }
 
   public static void scroolUp() {
   JavascriptExecutor js=(JavascriptExecutor)driver;
   js.executeScript("scroll(0,1000)");
   }
 
   /*
    * This is Method is used to do scrolldown on webpage
    */
   public static void scroolDown() {
   JavascriptExecutor js=(JavascriptExecutor)driver;
   js.executeScript("scroll(0,-1000)");
   }
 
   /*
    * @This Method is used to find no of frame
    */
 
   public static int noOfFrame() {
  int size= driver.findElements(By.tagName("iframe")).size();
  System.out.println("******* No of frame on the webpage **********" +size);
return size;
   }
 
 

}
=======================================================================
package com.seleniumpractice;

import org.openqa.selenium.By;

public class PayTymFrame extends Base{

public static void main(String[] args) {
Base.config();
driver.findElement(By.xpath("//div[contains(text(),'Log In/Sign Up')]")).click();
int size=Base.noOfFrame();
for(int i=0;i<size;i++) {
driver.switchTo().frame(i);
if(driver.findElements(By.xpath("//span[contains(text(),'Open Paytm app and tap on scan icon ')]")).size()!=0) {
String actualText=driver.findElement(By.xpath("//p[contains(text(),'Benefits of Paytm Account')]")).getText();
System.out.println("********** actualText ********" + actualText);
String expText="Benefits of Paytm Account";
System.out.println("********** expText ********" +expText);
Base.compareText(actualText, expText);
}
}
driver.switchTo().defaultContent();
String actualTitle=driver.getTitle();
System.out.println("************ actualTitle ***********" + actualTitle);
String expTitle="Paytm.com – Recharge & Utility Payments, Entertainment, Travel, DTH, Wallet & Payments";
System.out.println("************ expTitle ***********" + expTitle);
Base.compareText(actualTitle, expTitle);
Base.closeBrowser();
Base.quitbrowser();
Base.executionSuccessfully();

}

}

No comments:

Post a Comment

Q) How To Find Duplicate Characters In A String In Java?

Step1:- Creating a HashMap containing char as key and it's occurrences as value. Step2:- Converting given string to char array. Step3:- ...