using Selenium + robot

This commit is contained in:
2017-07-03 12:58:49 +02:00
parent d62491cb07
commit 3f7e795ba4
@@ -2,6 +2,8 @@ package com.bayer.edam;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import java.awt.Robot;
import java.awt.event.KeyEvent;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.junit.After; import org.junit.After;
@@ -13,28 +15,63 @@ import org.openqa.selenium.NoAlertPresentException;
import org.openqa.selenium.NoSuchElementException; import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
public class ToolboxVideoExporter { public class ToolboxVideoExporter {
private WebDriver driver; private WebDriver driver;
private String baseUrl; private String baseUrl;
private boolean acceptNextAlert = true; private boolean acceptNextAlert = true;
private StringBuffer verificationErrors = new StringBuffer(); private StringBuffer verificationErrors = new StringBuffer();
private Robot robot;
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
System.setProperty("webdriver.gecko.driver", "F:\\Toolbox\\geckodriver.exe"); System.setProperty("webdriver.gecko.driver", "F:\\Toolbox\\geckodriver.exe");
driver = new FirefoxDriver(); FirefoxOptions options = new FirefoxOptions();
options.setBinary("C:\\Users\\gexce\\AppData\\Local\\Mozilla Firefox\\firefox.exe");
driver = new FirefoxDriver(options);
baseUrl = "https://bayertoolbox.com/"; baseUrl = "https://bayertoolbox.com/";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
robot = new Robot();
} }
@Test @Test
public void testCase() throws Exception { public void testCase() throws Exception {
driver.get(baseUrl + "/");
driver.findElement(By.id("MainContent_tbxUserName")).clear();
driver.findElement(By.id("MainContent_tbxUserName")).sendKeys("alexander.swagemakers@bayer.com");
driver.findElement(By.id("MainContent_tbxPassword")).clear();
driver.findElement(By.id("MainContent_tbxPassword")).sendKeys("bayer123");
driver.findElement(By.id("MainContent_RememberMe")).click();
driver.findElement(By.id("MainContent_btnLogin")).click();
driver.get(baseUrl + "/Assets/AssetDetailNational.aspx?AssetID=22936"); driver.get(baseUrl + "/Assets/AssetDetailNational.aspx?AssetID=22936");
driver.findElement(By.cssSelector("#MainContent_aDownload > strong")).click(); driver.findElement(By.cssSelector("#MainContent_aDownload > strong")).click();
driver.findElement(By.cssSelector("#MainContent_aDownload > strong")).click();
driver.findElement(By.id("MainContent_btnDownloadOk")).click();
driver.findElement(By.id("MainContent_btnDownloadOk")).click(); driver.findElement(By.id("MainContent_btnDownloadOk")).click();
robot.keyPress(KeyEvent.VK_ALT);
robot.keyPress(KeyEvent.VK_S);
robot.keyRelease(KeyEvent.VK_S);
robot.keyRelease(KeyEvent.VK_ALT);
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
robot.keyPress(KeyEvent.VK_1); robot.keyRelease(KeyEvent.VK_1);
robot.keyPress(KeyEvent.VK_2); robot.keyRelease(KeyEvent.VK_2);
robot.keyPress(KeyEvent.VK_3); robot.keyRelease(KeyEvent.VK_3);
robot.keyPress(KeyEvent.VK_A); robot.keyRelease(KeyEvent.VK_A);
robot.keyPress(KeyEvent.VK_PERIOD); robot.keyRelease(KeyEvent.VK_PERIOD);
robot.keyPress(KeyEvent.VK_Z); robot.keyRelease(KeyEvent.VK_Z);
robot.keyPress(KeyEvent.VK_I); robot.keyRelease(KeyEvent.VK_I);
robot.keyPress(KeyEvent.VK_P); robot.keyRelease(KeyEvent.VK_P);
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
} }
@After @After