/** * Tests that the details of cargo with tracking Id DEF789 can be viewed through the admin * interface. */ @Test @RunAsClient public void testViewDetailsId4() { log.log( Level.INFO, "Starting automated test to view details for Id \"" + trackingId4 + "\" through admin interface."); try { System.out.println(landingPageResponse.getUrl()); // Stores the adminDashboard as a HtmlPage object. HtmlPage adminDashboard = landingPageResponse.getElementById("adminLandingLink").click(); Assert.assertThat( "Page title was not as expected for the admin dashboard. Expected \"Cargo Dashboard\" but actual was \"" + adminDashboard.getTitleText() + "\".", adminDashboard.getTitleText(), is("Cargo Dashboard")); // Stores the details page as a HtmlPage object. HtmlPage detailsPage = adminDashboard.getAnchorByText(trackingId4).click(); Assert.assertTrue( "Expected \"Not routed\" message was not found.", detailsPage.asText().contains("Not routed")); } catch (IOException ex) { Assert.fail( "An IOException was thrown during the test for class \"" + ViewDetailTest.class.getSimpleName() + "\" at method \"" + testName.getMethodName() + "\" with message: " + ex.getMessage()); } }
public boolean athenticated() { web = new WebClient(); try { page1 = web.getPage(url); } catch (FailingHttpStatusCodeException | IOException e) { e.printStackTrace(); } HtmlForm form = page1.getFormByName("form2"); form.getInputByName("txtUserName").setAttribute("value", username); form.getInputByName("txtPassword").setAttribute("value", password); try { page2 = form.getInputByName("LoginButton").click(); } catch (ElementNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } if (page2.getUrl().toString().equals("http://78.39.200.210/Default.aspx")) { return true; } else { web.closeAllWindows(); return false; } }
@Override public String[] getRowCSV(HtmlPage page) { String title = page.getTitleText(); String video = null; List<HtmlElement> anchorsBgcover = page.getHtmlElementById("bgcover").getHtmlElementsByTagName("a"); if (!anchorsBgcover.isEmpty()) { video = anchorsBgcover.get(0).getAttribute("href"); } String rating = null; List<HtmlElement> spansBgcover = page.getHtmlElementById("bgcover").getHtmlElementsByTagName("span"); if (!spansBgcover.isEmpty()) { rating = spansBgcover.get(0).asText(); if (rating.equals("MYMO NET RO?")) { rating = null; } } String[] idArray = page.getUrl().toString().split("/"); String id = idArray[idArray.length - 1]; String[] elementRow = {id, title, video, rating}; System.out.println(title); return elementRow; }
@Override protected String getCallbackUrl(final HtmlPage authorizationPage) throws Exception { HtmlForm form = authorizationPage.getFormByName("loginform"); final HtmlTextInput login = form.getInputByName("log"); login.setValueAttribute("testscribeup"); final HtmlPasswordInput passwd = form.getInputByName("pwd"); passwd.setValueAttribute("testpwdscribeup"); HtmlElement button = (HtmlElement) authorizationPage.createElement("button"); button.setAttribute("type", "submit"); form.appendChild(button); // HtmlButton button = form.getButtonByName("wp-submit"); final HtmlPage confirmPage = button.click(); form = confirmPage.getFormByName("loginform"); button = (HtmlElement) confirmPage.createElement("button"); button.setAttribute("type", "submit"); form.appendChild(button); // button = form.getButtonByName("wp-submit"); final HtmlPage callbackPage = button.click(); final String callbackUrl = callbackPage.getUrl().toString(); logger.debug("callbackUrl : {}", callbackUrl); return callbackUrl; }
public void parse2File(HtmlPage page, PrintWriter writer) throws Exception { String content = this.parse(page); if (content.equals("")) { log.write(page.getUrl().toString() + " " + " error.(Ignore this error) \r\n"); return; } IO.writeStr(content + "\r\n", writer); }
@Override protected String getCallbackUrlForCancel(final HtmlPage authorizationPage) throws Exception { final HtmlForm form = authorizationPage.getForms().get(0); final HtmlSubmitInput submit = form.getInputByValue("Cancel"); final HtmlPage callbackPage = submit.click(); final String callbackUrl = callbackPage.getUrl().toString(); logger.debug("callbackUrl : {}", callbackUrl); return callbackUrl; }
@Override public boolean verifySuccess(HtmlPage page, Object param) { // no success defined, means always pass if (xpathsSuccess == null) { return true; } for (int i = 0; i < xpathsSuccess.length; i++) { if (xpathsSuccess[i] != null) { Object result = page.getFirstByXPath(xpathsSuccess[i]); if (result == null) { logger.warn( String.format( "xpath:%s not found on page %s", xpathsSuccess[i], page.getUrl().toExternalForm())); ; return false; } else { String strResult = CrawlTaskEval.getStringValue(result); if (expectedValues != null) { if (strResult != null) { if (!expectedValues[i].equals(strResult)) { logger.warn( String.format( "result get from xpath %s on page %s is [%s] different then expected [%s]", xpathsSuccess[i], page.getUrl().toExternalForm(), strResult, expectedValues[i])); return false; } } else { logger.warn(String.format("xpath result:%s can't be transformed to string.", result)); return false; } } } } } return true; }
@Override protected String getCallbackUrl(final WebClient webClient, final HtmlPage authorizationPage) throws Exception { final HtmlForm form = authorizationPage.getForms().get(0); final HtmlPasswordInput password = form.getInputByName("password"); password.setValueAttribute("testpwdpac4j"); final HtmlSubmitInput submit = form.getInputByValue("Sign In"); final HtmlPage callbackPage = submit.click(); /*form = confirmPage.getForms().get(0); HtmlButton continueButton = (HtmlButton) form.getElementById("continue-button"); HtmlPage callbackPage = continueButton.click();*/ final String callbackUrl = callbackPage.getUrl().toString(); logger.debug("callbackUrl : {}", callbackUrl); return callbackUrl; }
@Override protected String getCallbackUrl(final WebClient webClient, final HtmlPage authorizationPage) throws Exception { webClient.waitForBackgroundJavaScript(5000); HtmlForm form = authorizationPage.getForms().get(0); final HtmlTextInput login = form.getInputByName("login_email"); login.setValueAttribute("*****@*****.**"); final HtmlPasswordInput passwd = form.getInputByName("login_password"); passwd.setValueAttribute("testpwdscribeup"); HtmlButton submit = form.getButtonByName(""); HtmlPage confirmPage = submit.click(); confirmPage = (HtmlPage) confirmPage.refresh(); webClient.waitForBackgroundJavaScript(5000); form = confirmPage.getForms().get(0); HtmlButton submit2 = form.getButtonByName("allow_access"); final HtmlPage callbackPage = submit2.click(); final String callbackUrl = callbackPage.getUrl().toString(); logger.debug("callbackUrl : {}", callbackUrl); return callbackUrl; }
public static HtmlPage solveCaptcha(HtmlPage page) throws Exception { System.out.println("Solving captcha..."); String url = page.getUrl().toString(); page = wc.getPage(url + "?bypass=1"); HtmlImage captchaImage = (HtmlImage) page.getElementById("recaptcha_image").getFirstChild(); captchaImage.saveAs(new File("captcha-image.jpg")); CaptchaSolver captchaSolver = new CaptchaSolver(new SocketClient("trialaccount", "Cappie1!"), "captcha-image.jpg"); captchaSolver.run(); Captcha captcha = captchaSolver.getCaptcha(); HtmlTextInput textField = (HtmlTextInput) page.getElementById("recaptcha_response_field"); textField.setValueAttribute(captcha.text); HtmlElement element = (HtmlElement) page.getElementByName("submit"); page = element.click(); System.out.println("Captcha entered."); return wc.getPage(url); }
private int ExtractAndInsertSeedUrls( HtmlPage page, String text, int pageNumber, int prevExtractedUrlCount, String searchEngineName) { int pageContentId = insertPageContent(text, pageNumber, searchEngineName, crawlId); HashSet<String> previousUrls = new HashSet<String>(); int count = 0; int urlStartIndex = 0; List<String> links = getAnchorLinks(page, "url"); for (String url : links) { try { if (!isExcludedFileType(url, searchEngineName)) { if (getSearchEngineFromName(searchEngineName).getUseUrlRedirection().equals("true") && url.contains("url")) { HtmlPage p = getPage(url); url = p.getUrl().toString(); Thread.sleep(200); } if (!includesExcludedKeyword(url, searchEngineName) && !previousUrls.contains(url)) { String encodedurl = ""; try { encodedurl = URLDecoder.decode(url, "ISO-8859-1"); url = encodedurl; } catch (Exception ex) { } count++; insertSeedLink(url, searchEngineName, prevExtractedUrlCount + count, pageContentId); previousUrls.add(url); target.dispatchEvent( new EventSearchWorker(target, searchEngineName + ":" + url + "\n", count, "")); // } } } catch (Exception ex) { System.out.println(ex.getMessage()); } } while (urlStartIndex > -1) { // index = text.indexOf("href=\"/url?q=http", index + 1); int indexencoded = text.indexOf("http://", urlStartIndex + 1); int indexnotencoded = text.indexOf("http%3a%2f%2f", urlStartIndex + 1); urlStartIndex = returnMinPositiveInteger(indexencoded, indexnotencoded); int indexOfNextQuote = text.indexOf('"', urlStartIndex + 10); int indexOfNextCloseParanthesis = text.indexOf(')', urlStartIndex + 10); int urlEndIndex = returnMinPositiveInteger(indexOfNextCloseParanthesis, indexOfNextQuote); try { String rawurl = text.substring(urlStartIndex, urlEndIndex); if (urlStartIndex > -1) { String url; if (indexencoded == urlStartIndex) { url = refineUrlString(rawurl, true); } else { url = refineUrlString(rawurl, false); } if (!isExcludedFileType(url, searchEngineName)) { if (!includesExcludedKeyword(url, searchEngineName) && !previousUrls.contains(url)) { String encodedurl = ""; try { encodedurl = URLDecoder.decode(url, "ISO-8859-1"); url = encodedurl; } catch (Exception ex) { } count++; insertSeedLink(url, searchEngineName, prevExtractedUrlCount + count, pageContentId); previousUrls.add(url); target.dispatchEvent( new EventSearchWorker(target, searchEngineName + ":" + url + "\n", count, "")); // } } } } catch (Exception ex) { } } return count; }