package com.practiceCode;
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.datatransfer.StringSelection;
import java.awt.event.KeyEvent;
import java.io.IOException;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.testng.Assert;
import org.testng.annotations.Test;
/**
* @Blog Name : Selenium Code Example
* @author Deepak Gupta
* @Created Date 29-09-2017
*
*/
public class ImageSaveByRobotClass extends SuperTestNG {
@Test
public void testImageSaveByRobotClass() throws IOException, InterruptedException, AWTException {
System.out.println("========= Starting testImageSaveByRobotClass() ============");
try {
driver.get("http://only-testing-blog.blogspot.in/2014/09/selectable.html");
// Locate Image
WebElement Image = driver.findElement(By.xpath("//img[@border='0']"));
// Rihgt click on Image using contextClick() method.
Actions action = new Actions(driver);
action.contextClick(Image).build().perform();
StringSelection file = new StringSelection("D:\\TestingSaveImage.jpg");
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(file, null);
Robot rb = new Robot();
for (int i = 1; i <= 7; i++) {
// Arrow down
rb.keyPress(KeyEvent.VK_DOWN);
Thread.sleep(100);
}
// To press Enter key.
rb.keyPress(KeyEvent.VK_ENTER);
// Similar to thread.sleep
rb.setAutoDelay(1000);
rb.keyPress(KeyEvent.VK_CONTROL);
rb.keyPress(KeyEvent.VK_V);
rb.keyRelease(KeyEvent.VK_CONTROL);
rb.keyRelease(KeyEvent.VK_V);
rb.setAutoDelay(1000);
// To press Enter key.
rb.keyPress(KeyEvent.VK_ENTER);
rb.keyRelease(KeyEvent.VK_ENTER);
System.out.println("File Save Successfully.");
System.out.println("========= Ending testImageSaveByRobotClass() ============");
} catch (Exception e) {
e.printStackTrace();
Assert.fail();
}
}
}
Friday, 29 September 2017
Code Example - Disable Firefox Console Log
package com.practiceCode;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.Test;
/**
*
* @Blog Name : Selenium Code Example
* @ Disable Firefox Console Log
* @author Deepak Gupta
* @Created Date 29-09-2017
*
*/
public class DisableFirefoxConsoleLog {
WebDriver driver;
@Test
public void testDisableFirefoxConsoleLog() {
try {
System.setProperty("webdriver.gecko.driver", System.getProperty("user.dir") +
"/drivers/geckodriver.exe"); System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE, "/dev/null"); driver = new FirefoxDriver(); driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); driver.manage().window().maximize(); driver.get("https://seleniumcodeexample.blogspot.in/"); String title = driver.getTitle(); System.out.println("Title Name is : " + title); } catch (Exception e) { e.printStackTrace(); Assert.fail(); } } @AfterTest public void tearDown() { driver.quit(); } }
"/drivers/geckodriver.exe"); System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE, "/dev/null"); driver = new FirefoxDriver(); driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); driver.manage().window().maximize(); driver.get("https://seleniumcodeexample.blogspot.in/"); String title = driver.getTitle(); System.out.println("Title Name is : " + title); } catch (Exception e) { e.printStackTrace(); Assert.fail(); } } @AfterTest public void tearDown() { driver.quit(); } }
Code Example - File Download By Robot Class In Firefox Browser
package com.practiceCode;
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
import org.openqa.selenium.By;
import org.testng.Assert;
import org.testng.annotations.Test;
/**
* @Blog Name : Selenium Code Example
* @author Deepak Gupta
* @Created Date 29-09-2017
*
*/
public class FileDownloadByRobotClass extends SuperTestNG {
@Test
public void testFileDownloadByRobotClass() {
System.out.println("==========starting testFileDownloadByRobotClass() =========");
try {
driver.get("http://only-testing-blog.blogspot.in/2014/05/login.html");
// Download Text File
driver.findElement(By.linkText("Download Text File")).click();
System.out.println("Download Text File link is clicked");
// downloadByRobotClass() method
downloadByRobotClass();
// press enter key of keyboard to perform above selected action
System.out.println("File Download successfully.");
System.out.println("==========ending testFileDownloadByRobotClass() =========");
} catch (Exception e) {
e.printStackTrace();
Assert.fail();
}
}
public void downloadByRobotClass() throws AWTException, InterruptedException {
Robot robot = new Robot();
// For clicking on the Arrow Down on the dialog box
robot.keyPress(KeyEvent.VK_DOWN);
// For clicking on the Ok button on the dialog box
robot.keyPress(KeyEvent.VK_ENTER);
//robot.keyRelease(KeyEvent.VK_ENTER);
Thread.sleep(2000);
}
}
Tuesday, 26 September 2017
Code Example - Append URL
package com.practiceCode;
import org.testng.annotations.Test;
/**
* @Blog Name : Selenium Code Example
* @author Deepak Gupta
* @Created Date 26-09-2017
*
*/
public class AppendURL extends SuperTestNG {
@Test
public void testAppendURL() {
try {
driver.get("https://seleniumcodeexample.blogspot.in/");
String beforeURL = driver.getCurrentUrl();
System.out.println("Before append url : " + beforeURL);
String newURL = beforeURL + "2017/08/code-for-handling-get-current-url.html";
driver.navigate().to(newURL);
System.out.println("After append url : " + driver.getCurrentUrl());
}catch (Exception e) {
e.printStackTrace();
Assert.fail();
}
}
}
Subscribe to:
Posts (Atom)
Code Example - File Download By Robot Class In Firefox Browser
Exported from Notepad++ package com . practiceCode ; import java . awt . AWTException ; import java . awt . Robot ; import j...
-
package com.test.automation.uiAutomation.testBase; import java.io.File; import java.io.FileInputStream; import java.io.IOException...
-
Exported from Notepad++ package com . practiceCode ; import org . openqa . selenium . WebDriver ; import org . openqa . seleni...
-
package com.practiceCode; import java.util.HashMap; import java.util.Map; import java.util.concurrent.TimeUnit; import org.openqa.sel...