Пример #1
0
  public static void main(String[] args) {
    String baseUrl = "http://newtours.demoaut.com/";
    WebDriver driver = new FirefoxDriver();
    String underConsTitle = "Under Construction: Mercury Tours"; // Creates result string
    driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);

    driver.get(baseUrl);
    List<WebElement> linkElements =
        driver.findElements(By.tagName("a")); // Creates lists from <a> tags
    String[] linkTexts = new String[linkElements.size()];
    int i = 0;

    // extract the link texts of each link element
    for (WebElement e : linkElements) {
      linkTexts[i] = e.getText();
      i++;
    }

    // test each link by looping over them
    for (String t : linkTexts) {
      driver.findElement(By.linkText(t)).click();
      if (driver.getTitle().equals(underConsTitle)) {
        System.out.println("\"" + t + "\"" + " is under construction.");
      } else {
        System.out.println(
            "\""
                + t
                + "\"" // print results to console
                + " is working.");
      }
      driver.navigate().back();
    }
    driver.quit();
  }
Пример #2
0
 @After
 public void tearDown() throws Exception {
   driver.quit();
   String verificationErrorString = verificationErrors.toString();
   if (!"".equals(verificationErrorString)) {
     fail(verificationErrorString);
   }
 }
Пример #3
0
 @Before
 public void setUp() throws Exception {
   FirefoxBinary binary = new FirefoxBinary(new File(FIREFOX_LOCATION));
   FirefoxProfile profile = new FirefoxProfile();
   driver = new FirefoxDriver(binary, profile);
   RegisterCustomerPage registerCustomerPage = new RegisterCustomerPage(driver);
   this.customerId =
       registerCustomerPage
           .registerCustomer(FIRSTNAME, LASTNAME, ADDRESS, ZIP, CITY, EMAIL, PASSWORD)
           .getCustomerId();
   driver.quit();
   driver = new FirefoxDriver(binary, profile);
 }
 @Override
 public void run() {
   try {
     log.info("Trying to close the browser " + webdriver + " ...");
     webdriver.quit();
   } catch (UnreachableBrowserException e) {
     // It happens for Firefox. It's ok: browser is already closed.
     log.log(FINE, "Browser is unreachable", e);
   } catch (WebDriverException cannotCloseBrowser) {
     log.severe(
         "Cannot close browser normally: "
             + Cleanup.of.webdriverExceptionMessage(cannotCloseBrowser));
   } finally {
     killBrowser(webdriver);
   }
 }
Пример #5
0
  public static void main(String[] args) throws Exception {

    DesiredCapabilities capabillities = DesiredCapabilities.firefox();
    capabillities.setCapability("version", "8");
    capabillities.setCapability("platform", Platform.WINDOWS);

    WebDriver driver =
        new RemoteWebDriver(
            new URL(
                "http://*****:*****@hub.testingbot.com:4444/wd/hub"),
            capabillities);

    driver.get("http://www.google.com");
    WebElement search = driver.findElement(By.name("q"));
    search.sendKeys("Hello, WebDriver");
    search.submit();
    System.out.println(driver.getTitle());
    driver.quit();
  }
 @After
 public void quitDriver() throws Exception {
   if (driver2 != null) {
     driver2.quit();
   }
 }
Пример #7
0
 private void tearDownDriver() {
   System.out.println("Exitting..");
   driver.quit();
 }
Пример #8
0
 public static void stopDriver(WebDriver driver) {
   if (driver != null) {
     webDriverLocal.remove();
     driver.quit();
   }
 }
 @After
 public void tearDown() throws Exception {
   driver.quit();
 }
Пример #10
0
  // li.active>span.next
  public static void main(String[] args) {

    if (args.length < 2) {
      System.out.println("please input two paremeter!");
      System.exit(0);
    }
    String filePath = args[0];
    String phantomJsPath = args[1];

    DesiredCapabilities cap = DesiredCapabilities.phantomjs();
    cap.setCapability(
        PhantomJSDriverService.PHANTOMJS_CLI_ARGS,
        new String[] {
          //                       "--webdriver-loglevel=DEBUG",
          //			"--proxy=org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
        });
    cap.setCapability(
        PhantomJSDriverService.PHANTOMJS_PAGE_CUSTOMHEADERS_PREFIX + "Accept-Language", "zh_CN");
    // cap.setCapability("phantomjs.page.settings.userAgent","Mozilla/5.0 (Macintosh; Intel Mac OS X
    // 10.9; rv:25.0) Gecko/20100101 Firefox/25.0");
    // "C:\\Users\\Administrator\\Desktop\\phantomjs-2.0.0-windows\\bin\\phantomjs.exe"
    cap.setCapability("phantomjs.binary.path", phantomJsPath);
    cap.setJavascriptEnabled(true);
    driver = new PhantomJSDriver(cap);

    WebDriverWait wait = null;
    wait = new WebDriverWait(driver, 60);
    driver.get(URL);
    /*try {
        Thread.currentThread().sleep(5000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }*/
    // screenShot((TakesScreenshot) driver, "/home/admin/"+"mo9"+c+".png");
    List<WebElement> nextElement = null;
    ArrayList<String> credits = new ArrayList<String>();

    int prePage = 1;
    int curPage = c;
    BufferedWriter br = null;
    File f = new File(filePath);
    try {
      br = new BufferedWriter(new FileWriter(f, true));
      br.write("mo9账号,真实姓名,身份证号,欠款金额,逾期天数");
      br.write("\r\n");
    } catch (IOException e1) {
      e1.printStackTrace();
    } finally {
      if (br != null) {
        try {
          br.close();
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    }

    while (!isLast) {
      List<WebElement> elements = null;
      try {
        elements =
            wait.until(
                ExpectedConditions.visibilityOfAllElementsLocatedBy(
                    By.cssSelector("div.faith-list>dl.fs12")));

      } catch (Exception e) {
        e.printStackTrace();
        driver.close();
        driver.quit();
        while (elements == null) {
          try {

            Thread.currentThread().sleep(720000);
            // c=((curPage/15)*15)+1;
            // curPage=c;
            driver = new PhantomJSDriver(cap);
            // driver=new FirefoxDriver(binary,profile);

            wait = new WebDriverWait(driver, 60);
            driver.get("https://www.mo9.com/creditCenter/p/" + curPage);
            elements =
                wait.until(
                    ExpectedConditions.visibilityOfAllElementsLocatedBy(
                        By.cssSelector("div.faith-list>dl.fs12")));
          } catch (Exception e1) {
            e1.printStackTrace();
          }
        }
      }

      System.out.println(curPage);
      for (WebElement element : elements) {
        StringBuffer sb = new StringBuffer();
        String acount =
            element.findElement(By.cssSelector("div.faith-list>dl.fs12>dt.row01")).getText();
        String name =
            element.findElement(By.cssSelector("div.faith-list>dl.fs12>dd.row02")).getText();
        String certiCard =
            element.findElement(By.cssSelector("div.faith-list>dl.fs12>dd.row03")).getText();
        String debt =
            element.findElement(By.cssSelector("div.faith-list>dl.fs12>dd.row04")).getText();
        String overDue =
            element.findElement(By.cssSelector("div.faith-list>dl.fs12>dd.row05")).getText();
        sb.append(acount + "," + name + "," + certiCard + "," + debt + "," + overDue);
        credits.add(sb.toString());
      }
      nextElement = driver.findElements(By.cssSelector("li>a.next"));

      if (credits.size() % 150 == 0 || nextElement.size() == 0) {
        try {
          br = new BufferedWriter(new FileWriter(f, true));
          for (String str : credits) {
            br.write(str);
            br.write("\r\n");
          }
          credits.clear();
        } catch (IOException e) {
          e.printStackTrace();
        } finally {
          if (br != null) {
            try {
              br.close();
            } catch (IOException e) {
              e.printStackTrace();
            }
          }
        }
        try {
          // Random r=new Random(100);
          // int n=r.nextInt(90);
          Thread.currentThread().sleep(20000);
        } catch (InterruptedException e) {
          e.printStackTrace();
        }
      }

      if (nextElement.size() == 0) {
        isLast = true;
      } else {
        nextElement.get(0).click();
        curPage++;
        try {
          Thread.currentThread().sleep(2000);
        } catch (InterruptedException e) {
          e.printStackTrace();
        }
      }
    }
  }
Пример #11
0
 @AfterMethod
 public void cleanUp() throws InterruptedException {
   //  sleepFor(2);
   driver.quit();
 }
Пример #12
0
 /** The END - Stops the browser. */
 public void stopBrowser() {
   driver.quit();
 }
Пример #13
0
  @Override
  public Void call() {
    try {
      ChromeOptions options = new ChromeOptions();
      JsonObject prefs = new JsonObject();
      prefs.addProperty("profile.default_content_settings.geolocation", 2);
      options.setExperimentalOption("prefs", prefs);
      driver = new ChromeDriver(options);
      waitdriver = new WebDriverWait(driver, 60);

      log.info("Start from={} to={} ", from, to);
      driver.get("https://wizzair.com//en-GB/FlightSearch");

      clickElement(
          By.id(
              "ControlGroupRibbonAnonNewHomeView_AvailabilitySearchInputRibbonAnonNewHomeView_AutocompleteOriginStation"));
      waitVisible(By.className("inHeader"));

      selectFrom(from);
      selectTo(to);

      waitVisible(
          By.id(
              "ControlGroupRibbonAnonNewHomeView_AvailabilitySearchInputRibbonAnonNewHomeView_AutocompleteOriginStation"));
      waitVisible(
          By.id(
              "ControlGroupRibbonAnonNewHomeView_AvailabilitySearchInputRibbonAnonNewHomeView_AutocompleteDestinationStation"));
      fromDest =
          driver
              .findElement(
                  By.id(
                      "ControlGroupRibbonAnonNewHomeView_AvailabilitySearchInputRibbonAnonNewHomeView_AutocompleteOriginStation"))
              .getAttribute("value");
      toDest =
          driver
              .findElement(
                  By.id(
                      "ControlGroupRibbonAnonNewHomeView_AvailabilitySearchInputRibbonAnonNewHomeView_AutocompleteDestinationStation"))
              .getAttribute("value");
      log.info("Searching for fromDest={} toDest={}", fromDest, toDest);

      // TODO only CLJ
      if (!fromDest.contains("CLJ") && !toDest.contains("CLJ")) {
        return null;
      }

      log.info("cjcombinations.put({},{})", from, to);

      clickElement(
          By.id(
              "ControlGroupRibbonAnonNewHomeView_AvailabilitySearchInputRibbonAnonNewHomeView_ButtonSubmit"));

      waitVisible(By.className("flights-header"));

      fileIndex = 0;
      saveFile(driver);
      while (true) {

        if (!clickNext(driver)) {
          log.error("Not clickable ");
          return null;
        }

        waitVisible(By.className("flights-body"));

        if (driver
            .findElement(By.className("flights-body"))
            .getText()
            .contains("No flight found for your search.")) {
          log.info("No results, finishing");
          return null;
        }

        saveFile(driver);
      }
    } catch (Exception ex) {
      log.error(
          "Error while processing from={} to={} today={} fromDest={} toDest={} fileIndex={}",
          from,
          to,
          today,
          fromDest,
          toDest,
          fileIndex,
          ex);
    } finally {
      if (driver != null) {
        try {
          driver.quit();
        } catch (Exception ex) {
          log.error("Error closing driver", ex);
        }
      }
    }
    return null;
  }
Пример #14
0
 @After
 public void end() {
   driver.quit();
 }
Пример #15
0
 @After
 public void tearDown() throws Exception {
   driver.quit();
   BlaHelper.deleteCustomer(customerId);
 }