This is a multi part series of videos and tutorials. Most of these sessions are recorded during the live class…
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
package TakeScreenshotReusable; import java.io.File; import java.io.IOException; import org.apache.commons.io.FileUtils; import org.openqa.selenium.OutputType; import org.openqa.selenium.TakesScreenshot; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; /** * * @author Sarang Holey * * 9:15:22 pm */ public class ScreenshotReusable { static WebDriver driver; public static void main(String[] args) { // Setting up browser properties System.setProperty("webdriver.chrome.driver", "chromedriver.exe"); // creating object of ChromeDriver with the reference of WebDriver interface driver = new ChromeDriver(); // passing the required url driver.get("https://www.google.co.in"); // calling the re-usable function for taking screenshot of current page on browser takeScreenshot("google"); } //Reusbale function for capturing screenshot with unique filename /** * * @param fileName */ public static void takeScreenshot(String fileName) { // capturing screenshot as output type file from getScreenshotAs method by up casting the WebDriver reference to TakeScreenshot Interface File file = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); try { // Coping screenshot file into Screenshots folder with Filename from argument along with current time appended to file name FileUtils.copyFile(file, new File("../TakeScreenshot/src/test/resources/Screenshots/"+fileName+""+System.currentTimeMillis()+".png")); } catch (IOException e) { // catching the exception while file handling e.printStackTrace(); } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
import java.util.List; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.testng.annotations.Test; public class BootStrapDropDown_Reusable { @Test public void BootStrapDropDown_Reusables() { //Creating reference variable of Webdriver WebDriver driver; // Setting up the properties for Chrome Driver System.setProperty("webdriver.chrome.driver", "C:\\Vision\\chromedriver.exe"); // Inserting Chromedriver to Webdriver refernece object driver = new ChromeDriver(); // Maximizing the browser window driver.manage().window().maximize(); // Passing the URL driver.get("https://www.jquery-az.com/boots/demo.php?ex=63.0_2"); // Providing wait to load all the elements on page driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); // Clicking on Bootstrap Dropdown driver.findElement(By.xpath("//button[contains(@class,'multiselect')]")).click(); // Get the all WebElements inside the dropdown in List List<WebElement> dropdown_list = driver.findElements(By.xpath("//ul[contains(@class,'multiselect-container dropdown-menu')]//li//a//label")); // Printing the amount of WebElements inside the list System.out.println("The Options in the Dropdown are: " + dropdown_list.size()); // Condition to get the WebElement for list and Click over "Angular" option for(int i=0; i<dropdown_list.size(); i++) { // Printing All the options from the dropdown System.out.println(dropdown_list.get(i).getText()); // Checking the condition whether option in text "Angular" is comming if(dropdown_list.get(i).getText().contains("Angular")) { // Clicking if text "Angular" is there dropdown_list.get(i).click(); // Breaking the condition if the condition get satisfied break; } } } } |
Handling of Frame and Frame-Set Selenium Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
WebDriver driver = new ChromeDriver(); driver.get("file:///C:/Automation/FrameProblem/FrameProblem.html"); driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); //Switching to 2nd Parent Frame driver.switchTo().frame(1); //Switching to frame inside frameset driver.switchTo().frame(0); //or //WebElement o_frameset = driver.findElement(By.tagName("frameset")); //WebElement o_frameset_frame = o_frameset.findElement(By.tagName("frame")); //driver.switchTo().frame(o_frameset_frame); WebElement obj = driver.findElement(By.tagName("input")); obj.sendKeys("Akash"); |
HTML which Above Code Handles:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
<!DOCTYPE html> <html> <body> <h1>The Cascaded Frames Problem</h1> <div> <iframe src="./Frame1.html"> <!DOCTYPE html> <html> <body> <h3>Frame 1</h3> </body> </html> </iframe> <iframe src="./Frame2.html"> <!DOCTYPE html> <html> <frameset cols="25%,50%,25%"> <frame src ="./frame3.html"> <html> <body> <input type="text"></input> </body> </html> </frame> </frameset> </html> </iframe> </div> </body> </html> |
Program: Simple JUnit test using @Test annotation. JUnit is a simple framework to write repeatable tests. It is an…
What is Eclipse? In the context of computing, Eclipse is an integrated development environment (IDE) for developing applications using the…