private void setPortalLanguageToFI() {
   WebElement langElem = driver.findElementByCssSelector("#heading .language-selection a");
   if (!langElem.getText().equals("In English")) {
     langElem.click();
     driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
   }
 }
Example #2
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");
   }
 }
  @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();
  }
Example #5
0
  @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");
  }
  @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();
 }
  private void customiseText(RemoteWebDriver driver) {
    List<WebElement> elementList = driver.findElements(By.className("UIATextView"));

    for (WebElement element : elementList) {
      element.click();
      driver.findElement(By.className("UIATextView")).sendKeys("test");
      driver.findElement(By.name("Done")).click();
    }
  }
Example #9
0
  @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);
  }
  @Test
  public void whenGetCapabilitiesFromRunningSessionThenItShouldBeSerializable() {
    RemoteWebDriver driver = new RemoteWebDriver(HUB_URL, DesiredCapabilities.firefox());

    Capabilities initializedCapabilities = driver.getCapabilities();

    assertTrue(
        "Capabilities obtained from running session should be serializable",
        initializedCapabilities instanceof Serializable);

    driver.quit();
  }
 private void customiseImages(RemoteWebDriver driver) {
   driver.findElement(By.name("Choose an existing image")).click();
   WebDriverWait wait = new WebDriverWait(driver, 10);
   wait.until(ExpectedConditions.visibilityOfElementLocated(By.name("Albums")));
   driver.findElement(By.name("Saved Photos")).click();
   wait.until(ExpectedConditions.visibilityOfElementLocated(By.name("UIACollectionView")));
   driver
       .findElement(By.className("UIACollectionView"))
       .click(); // from Louis's  .FindElements(By.ClassName("UIACollectionCell"))[0]
                 // .ClickMiddleUsingCoordinates();
   wait.until(ExpectedConditions.elementToBeClickable(By.name("confirm edit icon")));
   driver.findElement(By.name("confirm edit icon")).click();
 }
Example #12
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"));
  }
Example #14
0
  @Before
  public void setUp() throws Exception {
    if (!initialized) {
      EhourServer ehourServer = EhourTestApplication.start();
      dataSource = ehourServer.getDataSource();
    }

    Driver = new FirefoxDriver();
    Driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

    screenshotTestRule = new ScreenshotTestRule(Driver);

    Runtime.getRuntime()
        .addShutdownHook(
            new Thread() {
              @Override
              public void run() {
                try {
                  Driver.quit();
                } catch (Exception e) {
                  //
                }
              }
            });

    clearDatabase();

    initialized = true;
  }
  /**
   * Download all the report attachments with a certain type. type - video, image, vital, network
   * Examples: downloadAttachment("video", "C:\\test\\video", "flv"); downloadAttachment("image",
   * "C:\\test\\Image", "jpg");
   */
  private void downloadAttachment(
      RemoteWebDriver driver, String type, String fileName, String suffix) throws IOException {
    try {
      String command = "mobile:report:attachment";
      boolean done = false;
      int index = 0;

      while (!done) {
        Map<String, Object> params = new HashMap<>();

        params.put("type", type);
        params.put("index", Integer.toString(index));

        String attachment = (String) driver.executeScript(command, params);

        if (attachment == null) {
          done = true;
        } else {
          File file = new File(fileName + index + "." + suffix);
          BufferedOutputStream output = new BufferedOutputStream(new FileOutputStream(file));
          byte[] bytes = OutputType.BYTES.convertFromBase64Png(attachment);
          output.write(bytes);
          output.close();
          index++;
        }
      }
    } catch (Exception ex) {
      System.out.println("Got exception " + ex);
    }
  }
  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;
        }
      }
    }
  }
Example #17
0
 /** Initialises remoteWebDriver by invoking factory and set timeouts when needed */
 public void initRemoteWebDriver() {
   if (driver == null) {
     log.debug("Initialising driver.");
     try {
       driver = webDriverFactory.make(webDriverConfig);
       if (implicitlyWaitDriverTimeout != null) {
         driver.manage().timeouts().implicitlyWait(implicitlyWaitDriverTimeout, TimeUnit.SECONDS);
       }
       if (pageLoadDriverTimeout != null) {
         driver.manage().timeouts().pageLoadTimeout(pageLoadDriverTimeout, TimeUnit.SECONDS);
       }
     } catch (Exception e) {
       throw new RuntimeException("Test run failed: unable to create driver.", e);
     }
   }
 }
  public Object apply(Object result) {
    if (result instanceof Collection<?>) {
      Collection<?> results = (Collection<?>) result;
      return Lists.newArrayList(Iterables.transform(results, this));
    }

    if (result instanceof Map<?, ?>) {
      Map<?, ?> resultAsMap = (Map<?, ?>) result;
      if (resultAsMap.containsKey("ELEMENT")) {
        RemoteWebElement element = newRemoteWebElement();
        element.setId(String.valueOf(resultAsMap.get("ELEMENT")));
        element.setFileDetector(driver.getFileDetector());
        return element;
      } else {
        return Maps.transformValues(resultAsMap, this);
      }
    }

    if (result instanceof Number) {
      if (result instanceof Float || result instanceof Double) {
        return ((Number) result).doubleValue();
      }
      return ((Number) result).longValue();
    }

    return result;
  }
Example #19
0
  protected void setUp() throws Exception {
    if (!isConfigured()) {
      DOMConfigurator.configure("log4j.xml");
      iConfigured = true;
    }
    configProperties = new Properties();
    try {
      configProperties.load(
          TestBase.class.getClassLoader().getResourceAsStream("config.properties"));
    } catch (IOException e) {
      e.printStackTrace();
    }

    useRemote = Boolean.parseBoolean(configProperties.getProperty("use_remote"));

    bro = configProperties.getProperty("browser");
    chromeDriver = configProperties.getProperty("chromedriver");
    ieDriver = configProperties.getProperty("iedriver");

    if (useRemote) {
      File profileDir = new File(getClass().getResource("/seleniumProfile").getFile());
      FirefoxProfile profile = new FirefoxProfile(profileDir);
      DesiredCapabilities capabilities = DesiredCapabilities.firefox();
      capabilities.setCapability(FirefoxDriver.PROFILE, profile);
      capabilities.setCapability("binary", "/usr/bin/firefox");
      String remoteUrl = configProperties.getProperty("selenium_remote_url");
      driver = new RemoteWebDriver(new URL(remoteUrl), capabilities);
      ((RemoteWebDriver) driver).setFileDetector(new LocalFileDetector());
    } else {
      if (bro.toLowerCase().equals("firefox")) {

        File profileDir = null;
        profileDir = new File(getClass().getResource("/seleniumProfile").getFile());
        FirefoxProfile profile = new FirefoxProfile(profileDir);
        driver = new FirefoxDriver(profile);
      }
      if (bro.toLowerCase().equals("chrome")) {
        System.setProperty("webdriver.chrome.driver", chromeDriver);
        Map<String, Object> prefs = new HashMap<String, Object>();
        prefs.put("download.default_directory", "target");
        DesiredCapabilities caps = DesiredCapabilities.chrome();
        ChromeOptions options = new ChromeOptions();
        options.setExperimentalOption("prefs", prefs);
        caps.setCapability(ChromeOptions.CAPABILITY, options);
        driver = new ChromeDriver(caps);
      }
      if (bro.toLowerCase().equals("ie")) {
        DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
        capabilities.setCapability(
            InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
        System.setProperty("webdriver.ie.driver", ieDriver);
        capabilities.setCapability("ignoreZoomSetting", true);
        capabilities.setCapability("nativeEvents", false);
        driver = new InternetExplorerDriver(capabilities);
      }
    }
    int timeout = Integer.parseInt(configProperties.getProperty("driver_timeout"));
    driver.manage().timeouts().implicitlyWait(timeout, TimeUnit.SECONDS);
  }
Example #20
0
  @After
  public void tearDown() throws Exception {
    // SetupDriver.exit();
    if (driver != null) driver.quit();

    System.out.println("Driver ShutDown");
    // process.destroy();
  }
Example #21
0
 /** Resets the script's progress and closes the driver if needed. */
 public void reset() {
   log.debug("Resetting test run.");
   vars.clear();
   stepIndex = -1;
   if (driver != null) {
     driver.quit();
   }
 }
Example #22
0
 /** @return True if there is another step to execute. */
 public boolean hasNext() {
   boolean hasNext = stepIndex < script.steps.size() - 1;
   if (!hasNext && driver != null) {
     log.debug("Quitting driver.");
     driver.quit();
   }
   return hasNext;
 }
 protected boolean isElementPresent(By locatorKey) {
   try {
     driver.findElement(locatorKey);
     return true;
   } catch (NoSuchElementException e) {
     return false;
   }
 }
Example #24
0
 /** This method will close the app using mobile command */
 public void closeApp() {
   try {
     Object result = remoteWebDriver.executeScript("mobile: closeApp");
     logger.info(result.toString());
   } catch (WebDriverException e) {
     logger.error(e.getMessage());
   }
 }
 /** Attempts to shut down {@link RemoteWebDriver} and destroys all related information */
 @Override
 public void destroy() {
   if (enclosedDriver == null) return;
   try {
     enclosedDriver.quit();
   } catch (WebDriverException e) { // it may be already dead
     return;
   }
 }
Example #26
0
 /**
  * This method will use the bundlId parameter to un-install the app from the attached iOS device.
  *
  * @param bundleId of the app you would like to remove (e.g. com.gamesys.jackpotjoy)
  */
 public void unInstallApp(String bundleId) {
   try {
     Object result =
         remoteWebDriver.executeScript("mobile: removeApp", "{\"bundleId\":\"" + bundleId + "\"}");
     logger.info(result.toString());
   } catch (WebDriverException e) {
     logger.error(e.getMessage());
   }
 }
Example #27
0
 /**
  * This method will use the appPath parameter to install the app on the attached iOS device.
  * Please make sure the appPath is accessible by the appium server.
  *
  * @param appPath to a local (zipped) app file or a url for a zipped app file.
  */
 public void installApp(String appPath) {
   try {
     Object result =
         remoteWebDriver.executeScript("mobile: installApp", "{\"appPath\":\"" + appPath + "\"}");
     logger.info(result.toString());
   } catch (WebDriverException e) {
     logger.error(e.getMessage());
   }
 }
Example #28
0
  @Test
  public void goToGoogle() {
    PlatFormDTO platform = new PlatFormDTO("win7", "internet explorer");
    RemoteWebDriver remote = new UsingSeleniumGrid().getRemoteWebDriver(platform);

    Sample_page su = PageFactory.initElements(remote, Sample_page.class);

    int size = su.getCheckboxSize();
    ArrayList<String> al = new Recursive().getRecursive(1, size);
    remote.quit();

    for (int i = 0; i < al.size(); i++) {
      Sample_page s =
          PageFactory.initElements(
              new UsingSeleniumGrid().getRemoteWebDriver(platform), Sample_page.class);
      s.getCheckboxtabname(al.get(i));
    }
    assertThat(true, is(false));
  }
Example #29
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();
  }
Example #30
0
  @Before
  public void setUp() {

    SetupDriver swd = new SetupDriver(browserchoice);
    driver = swd.setDriver();
    driver.manage().window().maximize();
    System.out.println("ss");
    Assume.assumeTrue(swd.valid == true);
    System.out.println("after assume");
    LogGenerator lg = new LogGenerator(driver);
  }