@Test
  public void testRemoteWebDriver() {
    DesiredCapabilities cap = new DesiredCapabilities();
    cap.setPlatform(Platform.ANY);
    cap.setBrowserName("opera");
    RemoteWebDriver driver = null;
    try {
      driver = new RemoteWebDriver(new URL("http://192.168.1.176:4444/wd/hub"), cap);
    } catch (MalformedURLException e) {
      e.printStackTrace();
    }
    // Navigate to Google using firefox
    driver.get("http://www.google.com");
    driver
        .findElement(By.name("q"))
        .sendKeys("selenium automation using grid on windows 8.1 with firefox machine");
    driver = (RemoteWebDriver) new Augmenter().augment(driver);
    File srcFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
    try {
      FileUtils.copyFile(srcFile, new File("remoteScreenshot.jpg"));
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    System.out.println(driver.getCurrentUrl());
    driver.quit();
  }
  @Ignore
  @Test
  public void TestCase_00X() throws Exception {
    LogGenerator.addLog(Level.INFO, "Starting Test Case_00X");
    driver.get("http://myitlabgrader.com/HTML5/SIMFrame.html");
    synchronized (driver) {
      driver.wait(6000);
    }

    driver.findElement(By.id("viewallbutton")).click();
    driver.findElement(By.xpath("//div[@id='ViewAllDlg']/div/table/tbody/tr[5]/td[2]")).click();
    driver.findElement(By.xpath("(//button[@type='button'])[2]")).click();
    driver
        .findElement(By.xpath("//div[@class='excelWorkBook']/div/div/div[2]/ul[3]/li[2]/div"))
        .click();

    ((JavascriptExecutor) driver)
        .executeScript("$('div#12_selectionBorder1.selectionBorderDiv').dblclick();");
    //
    // ((JavascriptExecutor)driver).executeScript("$('div#12_selectionBorder1.selectionBorderDiv').focus();")  ;

    driver.findElement(By.xpath("//*[@id='12_editableDiv1']/div")).sendKeys("Semester 1");
    //
    //	driver.findElement(By.xpath("//div[@class='excelWorkBook']/div/div/div[2]/ul[3]/li[4]/div")).click();

    driver.findElement(By.xpath("//*[@id='12_editableDiv1']/div")).sendKeys(Keys.RETURN);

    //					 ((JavascriptExecutor)driver).executeScript("$('div#12_editableDiv1').keypress(function
    // (e){if(e.keyCode == 13) });")  ;
    synchronized (driver) {
      driver.wait(6000);
    }
    String name = (new Exception().getStackTrace()[0].getMethodName());
    CaptureScreenshot.takeScreenshot(driver, name);
  }
  @Ignore
  @Test
  public void TestCase_003() throws Exception {

    LogGenerator.addLog(Level.INFO, "Starting Test Case_003");
    driver.get("http://grader3/ui/pctlogin.aspx");

    assertEquals("Project Creation Tool", driver.getTitle());
    String name = (new Exception().getStackTrace()[0].getMethodName());
    CaptureScreenshot.takeScreenshot(driver, name);
    driver.switchTo().frame(0);
    driver.findElement(By.id("UserNameTextBox")).clear();
    driver.findElement(By.id("UserNameTextBox")).sendKeys("qa");
    driver.findElement(By.id("PasswordTextBox")).clear();
    driver.findElement(By.id("PasswordTextBox")).sendKeys("qa");
    driver.findElement(By.id("LoginButton")).click();
    driver.findElement(By.id("CreateProj")).click();
    driver.findElement(By.id("NameInput")).clear();
    driver.findElement(By.id("NameInput")).sendKeys("New Project 19 July");
    driver.findElement(By.id("DescriptionInput")).clear();
    driver.findElement(By.id("DescriptionInput")).sendKeys("Test Project");
    driver.findElement(By.xpath("(//button[@type='button'])[2]")).click();
    assertEquals("Project Creation Tool", driver.getTitle());
    assertEquals("Project Creation Tool", driver.getTitle());
    driver.findElement(By.id("LogOut_Link")).click();
    assertEquals("Project Creation Tool", driver.getTitle());
  }
  @Ignore
  @Test
  public void TestCase_002() throws Exception {

    LogGenerator.addLog(Level.INFO, "Starting Test Case_002");

    driver.get("http://www.google.com");
    String name = (new Exception().getStackTrace()[0].getMethodName());
    CaptureScreenshot.takeScreenshot(driver, name);

    // Find the text input element by its name
    WebElement element = driver.findElement(By.name("q"));
    element.sendKeys("Junit");
    element.submit();

    synchronized (driver) {
      driver.wait(12000);
    }

    LogGenerator.addLog(Level.INFO, "my info message in test case 002");

    CaptureScreenshot.takeScreenshot(driver, name);
    // assertEquals("junit - Google Search", driver.getTitle());

    LogGenerator.addLog(Level.INFO, "Completing Test Case_002");
  }
Beispiel #5
0
  @Parameters("browser")
  @Test
  public void testLogin(String browser) throws MalformedURLException, InterruptedException {
    System.out.println(browser);

    DesiredCapabilities cap = null;

    if (browser.equals("firefox")) {
      cap = DesiredCapabilities.firefox();
      cap.setBrowserName("firefox");
      cap.setPlatform(Platform.ANY);
    } else if (browser.equals("chrome")) {
      cap = DesiredCapabilities.chrome();
      cap.setBrowserName("chrome");
      cap.setPlatform(Platform.ANY);
    } else if (browser.equals("iexplorer")) {
      cap = DesiredCapabilities.internetExplorer();
      cap.setBrowserName("iexplore");
      cap.setPlatform(Platform.WINDOWS);
    }
    driver = new RemoteWebDriver(new URL("http://192.168.1.133:5555/wd/hub"), cap);
    // driver.manage().window().maximize();
    driver.get("http://gmail.com");
    driver.findElement(By.id("Email")).sendKeys("Hello");
    Thread.sleep(10000L);
  }
 @Parameters("browser")
 @Test
 public void dropdownTest(String b) throws MalformedURLException, Throwable {
   DesiredCapabilities cap = null;
   if (b.equals("firefox")) {
     cap = DesiredCapabilities.firefox();
     cap.setBrowserName("firefox");
     cap.setPlatform(Platform.ANY);
   } else if (b.equals("chrome")) {
     cap = DesiredCapabilities.chrome();
     cap.setBrowserName("chrome");
     cap.setPlatform(Platform.WINDOWS);
   }
   RemoteWebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wb/hub"), cap);
   driver.get("http://newtours.demoaut.com"); // Dropdown prgm copy paste.
   driver.findElement(By.linkText("REGISTER")).click();
   Thread.sleep(3000);
   WebElement drop = driver.findElement(By.name("country"));
   List<WebElement> dropdown = drop.findElements(By.tagName("option"));
   int a = MyRandomNo(dropdown.size() - 1);
   dropdown.get(a).click();
   if (dropdown.get(a).isSelected()) {
     System.out.println(dropdown.get(a).getText() + "is active");
   } else {
     System.out.println(dropdown.get(a).getText() + "is not active");
   }
 }
  @Parameters("browser")
  @Test
  public void dropdownTest(String b) throws MalformedURLException {
    System.out.println(b);
    DesiredCapabilities cap = null;
    if (b.equals("firefox")) {
      cap = DesiredCapabilities.firefox();
      cap.setBrowserName("firefox");
      cap.setPlatform(Platform.ANY);
    } else if (b.equals("chrome")) {
      cap = DesiredCapabilities.chrome();
      cap.setBrowserName("chrome");
      cap.setPlatform(Platform.WINDOWS);
    }
    RemoteWebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), cap);
    driver.get("http://newtours.demoaut.com");
    driver.findElement(By.linkText("REGISTER")).click();
    WebElement drop = driver.findElement(By.name("country"));
    List<WebElement> dropdown = drop.findElements(By.tagName("option"));
    System.out.println(dropdown.size());
    for (int i = 0; i < dropdown.size(); i++) {
      dropdown.get(i).click();

      if (dropdown.get(i).isSelected()) {
        System.out.println(dropdown.get(i).getText() + " is active");
      } else {
        System.out.println(dropdown.get(i).getText() + " is inactive");
      }
    }
  }
 @Before
 public void openBrowser() {
   driver = driverFactory.getBrowserDriver(browserType);
   driver.manage().window().maximize();
   driver.get("http://avoin-test.csc.fi/");
   driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
   setPortalLanguageToFI();
 }
Beispiel #9
0
 @BeforeMethod(alwaysRun = true)
 public void reportHeader(Method method) throws Throwable {
   // itc = ctx;
   Date date = new Date();
   SimpleDateFormat sdf = new SimpleDateFormat("dd_MMM_yyyy hh mm ss SSS");
   String formattedDate = sdf.format(date);
   ReportStampSupport.calculateTestCaseStartTime();
   if (browser.equalsIgnoreCase("firefox")) {
     ProfilesIni profile = new ProfilesIni();
     FirefoxProfile ffprofile = new FirefoxProfile();
     ffprofile.setEnableNativeEvents(true);
     webDriver = new FirefoxDriver(ffprofile);
   } else if (browser.equalsIgnoreCase("ie")) {
     File file = new File("Drivers\\IEDriverServer.exe");
     System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
     DesiredCapabilities caps = DesiredCapabilities.internetExplorer();
     caps.setCapability(InternetExplorerDriver.IE_ENSURE_CLEAN_SESSION, true);
     webDriver = new InternetExplorerDriver(caps);
     i = i + 1;
   } else if (browser.equalsIgnoreCase("chrome")) {
     System.setProperty("webdriver.chrome.driver", "Drivers\\chromedriver.exe");
     DesiredCapabilities capabilities = new DesiredCapabilities();
     ChromeOptions options = new ChromeOptions();
     options.addArguments("test-type");
     capabilities.setCapability(ChromeOptions.CAPABILITY, options);
     webDriver = new ChromeDriver(capabilities);
   } else if (browser.equalsIgnoreCase("iphone")) {
     Iosdriver.resetApp();
   } else if (browser.equalsIgnoreCase("android")) {
     AndroidDriver2.resetApp();
   }
   flag = false;
   if ((!(browser.equalsIgnoreCase("Android"))) & (!(browser.equalsIgnoreCase("iPhone")))) {
     driver = /*new EventFiringWebDriver*/ (webDriver);
     /*ActionEngineSupport myListener = new ActionEngineSupport();
     driver.register(myListener);*/
     driver.manage().window().maximize();
     driver.manage().timeouts().implicitlyWait(3, TimeUnit.MINUTES);
     driver.get(url);
   }
   HtmlReportSupport.tc_name = method.getName().toString() + "-" + formattedDate;
   String[] ts_Name = this.getClass().getName().toString().split("\\.");
   HtmlReportSupport.packageName = ts_Name[0] + "." + ts_Name[1] + "." + ts_Name[2];
   HtmlReportSupport.testHeader(HtmlReportSupport.tc_name, browser);
   stepNum = 0;
   PassNum = 0;
   FailNum = 0;
   testName = method.getName();
   logger.info("Current Test : " + testName);
 }
  protected void doSimpleWebdriverTest(BrowserWebDriverContainer rule) {
    RemoteWebDriver driver = setupDriverFromRule(rule);
    System.out.println("Selenium remote URL is: " + rule.getSeleniumAddress());
    System.out.println("VNC URL is: " + rule.getVncAddress());

    // Runtime.getRuntime().exec("open " + rule.getVncUrl(driver)); // For debugging, on a Mac

    driver.get("http://www.google.com");
    driver.findElement(By.name("q")).sendKeys("testcontainers");
    driver.findElement(By.name("q")).submit();
    assertEquals(
        "the word 'testcontainers' appears in the search box",
        "testcontainers",
        driver.findElement(By.name("q")).getAttribute("value"));
  }
  protected void doSimpleExplore(BrowserWebDriverContainer rule) {
    RemoteWebDriver driver = setupDriverFromRule(rule);
    driver.get("http://en.wikipedia.org/wiki/Randomness");

    loop:
    for (int i = 0; i < 5; i++) {
      Random random = new Random();
      List<WebElement> webElements = driver.findElements(By.tagName("a"));
      for (WebElement webElement : webElements) {
        if (random.nextInt(10) == 0 && webElement.isDisplayed() && webElement.isEnabled()) {
          webElement.click();
          break loop;
        }
      }
    }
  }
Beispiel #12
0
  //				@Ignore
  @Test
  public void testCase4() throws Exception {
    driver.get("http://myitlabgrader.com/HTML5/SIMFrame.html");
    synchronized (driver) {
      driver.wait(12000);
    }
    driver.findElement(By.id("viewallbutton")).click();
    driver.findElement(By.xpath("//div[@id='ViewAllDlg']/div/table/tbody/tr[2]/td[2]")).click();
    //					driver.findElement(By.cssSelector("td.DatagridSelectedTD")).click();
    driver.findElement(By.xpath("(//button[@type='button'])[2]")).click();
    synchronized (driver) {
      driver.wait(18000);
    }

    // Select Option A in Q#1

    driver.findElement(By.cssSelector("p.MsoNormal > span")).click();

    //					WebElement flash4 = driver.findElement(By.cssSelector("p.MsoNormal"));
    //
    //
    //
    //					JavascriptExecutor js4 = (JavascriptExecutor) driver;
    //					js4.executeScript( "document.getElementById('MsoNormal').select();", flash4);
    //					System.out.println("a"+flash4);
    //					synchronized (driver)
    {
      driver.wait(6000);
    }
    //
    //					driver.findElement(By.className("MsoNormal"));
    //
    //					String s = driver
    // .findElement(By.xpath("//div[@class='contentHolder']/p[@class='MsoNormal]")).getText().toString();
    //
    //					((JavascriptExecutor)driver).executeScript("$('p#MsoNormal').select();", s)  ;
    //					String flash =
    // driver.findElement(By.xpath("//div[@class='contentHolder']/p[@class='MsoNormal]")).getText().toString();
    //					JavascriptExecutor js = (JavascriptExecutor) driver;
    //					js.executeScript( "arguments[0].select();", flash);

    //					driver.findElement(By.cssSelector("contentHolder")).
    driver.findElement(By.cssSelector("#Bold > img.topMargin")).click();
    driver.findElement(By.xpath("//div[@id='Align Center']/img")).click();
    driver.findElement(By.id("ButtonDivFontTheme1")).click();
    driver.findElement(By.xpath("//div[@id='mcs_container_FontSize']/div/div/div/div[7]")).click();
  }
Beispiel #13
0
  @Ignore
  @Test
  public void TestCase_005() throws Exception {

    LogGenerator.addLog(Level.INFO, "Starting Test Case_004");
    driver.get("http://myitlabgrader.com/HTML5/SIMFrame.html");
    // assertEquals("SIMs Demo", driver.getTitle());
    synchronized (driver) {
      driver.wait(12000);
    }
    System.out.println("test1");

    WebElement we = driver.findElement(By.cssSelector("#msword > img"));

    Actions action = new Actions(driver);
    action.doubleClick(we);
    action.perform();

    synchronized (driver) {
      driver.wait(12000);
    }

    String name = (new Exception().getStackTrace()[0].getMethodName());
    CaptureScreenshot.takeScreenshot(driver, name);

    synchronized (driver) {
      driver.wait(6000);
    }

    driver.findElement(By.cssSelector("span.ribbon-title.IDFileTab")).click();

    driver
        .findElement(By.xpath("html/body/div/div/div[3]/div/div/div/div/div[3]/div/div/div[4]"))
        .click();

    driver
        .findElement(
            By.xpath("/html/body/div/div/div[3]/div/div/div/div/div[3]/div/div[4]/div[3]/p[5]/img"))
        .click();

    we =
        driver.findElementByXPath(
            "/html/body/div/div/div[6]/div/div[2]/div/div/div[3]/div/div[2]/div[8]/img");

    action.doubleClick(we);
    action.perform();
  }
Beispiel #14
0
 public void openUrl(final String url) {
   driver.get(URL);
 }