コード例 #1
0
 /**
  * This test verifies that an attribute nameed 'value' can be successfully updated from a partial
  * response (over Ajax).
  */
 @Test
 public void testScript() throws Exception {
   HtmlPage page = webClient.getPage(webUrl + "faces/script.xhtml");
   assertTrue(page.asXml().contains("SCRIPT EXECUTED!"));
   HtmlSubmitInput button = (HtmlSubmitInput) page.getElementById("form1:button1");
   page = button.click();
   assertTrue(page.asXml().contains("SCRIPT EXECUTED!"));
 }
コード例 #2
0
ファイル: Issue1660IT.java プロジェクト: gilsondev/jsf2-api
  @Test
  public void testConverterInstallation() throws Exception {
    HtmlPage page = webClient.getPage(webUrl + "faces/issue1660.xhtml");
    assertTrue(page.asXml().matches("(?s).*Simple\\s+value\\s+is\\s+VALUE1.*"));

    HtmlSubmitInput button = (HtmlSubmitInput) page.getElementById("button");
    page = button.click();
    assertTrue(page.asXml().matches("(?s).*Simple\\s+value\\s+is\\s+VALUE1.*"));
  }
コード例 #3
0
 @JsfTest(JsfVersion.JSF_2_2_5)
 @Test
 public void testSetForEach() throws Exception {
   webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
   HtmlPage page = webClient.getPage(webUrl + "faces/setForEach.xhtml");
   assertEquals(200, page.getWebResponse().getStatusCode());
   assertTrue(page.asXml().indexOf("foo") == -1);
   assertTrue(page.asXml().indexOf("bar") != -1);
   assertTrue(page.asXml().indexOf("baz") != -1);
 }
コード例 #4
0
ファイル: Issue2629IT.java プロジェクト: ivartanian/mojarra
 @Test
 public void testFieldSetAjaxBehavior() throws Exception {
   webClient.setJavaScriptEnabled(true);
   webClient.setJavaScriptTimeout(60000);
   HtmlPage page = webClient.getPage(webUrl + "/faces/fieldset.xhtml");
   HtmlFieldSet fieldset = (HtmlFieldSet) page.getHtmlElementById("fieldset4");
   page = fieldset.click();
   webClient.waitForBackgroundJavaScript(60000);
   assertTrue(page.asXml().contains("fieldset4 Event: begin"));
   assertTrue(page.asXml().contains("fieldset4 Event: complete"));
   assertTrue(page.asXml().contains("fieldset4 Event: success"));
 }
コード例 #5
0
ファイル: Issue2629IT.java プロジェクト: ivartanian/mojarra
 @Test
 public void testLabelAjaxBehavior() throws Exception {
   webClient.setJavaScriptEnabled(true);
   webClient.setJavaScriptTimeout(60000);
   HtmlPage page = webClient.getPage(webUrl + "/faces/label.xhtml");
   HtmlElement label = page.getHtmlElementById("label2");
   page = (HtmlPage) label.mouseOver();
   webClient.waitForBackgroundJavaScript(60000);
   assertTrue(page.asXml().contains("label2 Event: begin"));
   assertTrue(page.asXml().contains("label2 Event: complete"));
   assertTrue(page.asXml().contains("label2 Event: success"));
 }
コード例 #6
0
 /** This test verifies ajax behavior was programmatically attached to input text component. */
 @Test
 public void testProgrammaticAjaxBehavior() throws Exception {
   String expectedString =
       "<input id="
           + '"'
           + "form:input1"
           + '"'
           + " type="
           + '"'
           + "text"
           + '"'
           + " name="
           + '"'
           + "form:input1"
           + '"'
           + " value="
           + '"'
           + "hi"
           + '"'
           + " onfocus="
           + '"'
           + "mojarra.ab(this,event,'focus',0,0)"
           + '"';
   HtmlPage page = webClient.getPage(webUrl + "faces/issue2674.xhtml");
   assertTrue(page.asXml().contains(expectedString));
 }
コード例 #7
0
ファイル: Core.java プロジェクト: pcmistloginov/java
  public static void main(String[] args) throws Exception {

    //    	WebClient webClient = new WebClient(BrowserVersion.FIREFOX_24, "54.186.230.121", 3128);
    WebClient webClient = new WebClient(BrowserVersion.FIREFOX_24);

    webClient.getOptions().setThrowExceptionOnScriptError(false);
    webClient.setJavaScriptTimeout(10000);
    webClient.getOptions().setJavaScriptEnabled(true);
    webClient.setAjaxController(new NicelyResynchronizingAjaxController());
    webClient.getOptions().setTimeout(10000);

    //    	webClient.getOptions().setJavaScriptEnabled(false);
    //		webClient.getOptions().setAppletEnabled(false);
    //		webClient.getOptions().setCssEnabled(false);

    //		webClient.getOptions().setThrowExceptionOnScriptError(false);
    //		webClient.setJavaScriptTimeout(10000);
    //		webClient.getOptions().setJavaScriptEnabled(true);
    //		webClient.setAjaxController(new NicelyResynchronizingAjaxController());
    //		webClient.getOptions().setTimeout(10000);

    //		webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
    //		webClient.getOptions().setThrowExceptionOnScriptError(false);

    HtmlPage currentPage = webClient.getPage("http://www.yandex.ru/");
    //    	HtmlPage currentPage = webClient.getPage("http://www.google.ru");

    //    	HtmlDivision div = currentPage.getHtmlElementById("del_competitors-1_42");

    //    	HtmlElement clickable = (HtmlElement)
    // currentPage.getHtmlElementById("del_competitors-1_42");
    //    	currentPage = (HtmlPage) clickable.click();

    HtmlAnchor advancedSearchAn = currentPage.getAnchorByText("Завести ящик");
    currentPage = advancedSearchAn.click();

    HtmlImage image = currentPage.<HtmlImage>getFirstByXPath("//img[@src='images/ash2008.jpg']");
    currentPage = (HtmlPage) image.click();

    System.out.println(currentPage.asXml());

    //    	HtmlImage image =
    // currentPage.<HtmlImage>getFirstByXPath("//img[@src='images/ash2008.jpg']");
    //    	currentPage = (HtmlPage) image.click();

    //    	HtmlImage imagetosave =
    // currentPage.<HtmlImage>getFirstByXPath("//img[@src='//yastatic.net/www/1.977/yaru/i/logo.png']");

    //    	HtmlImage image = currentPage.<HtmlImage>getHtmlElementById("add_competitors-1_3");
    //    	currentPage = (HtmlPage) image.click();

    //    	File imageFile = new File("test_new.jpg");
    //    	image.saveAs(imageFile);

    //    	System.out.println(currentPage.asXml());

    System.out.println("It is done.");

    webClient.closeAllWindows();
  }
コード例 #8
0
 /** Validates a not enforced resources. */
 @Test(
     groups = {
       "ldapv3",
       "ldapv3_sec",
       "s1ds",
       "s1ds_sec",
       "ad",
       "ad_sec",
       "amsdk",
       "amsdk_sec",
       "jdbc",
       "jdbc_sec"
     })
 public void evaluateNotEnforced() throws Exception {
   entering("evaluateNotEnforced", null);
   webClient = new WebClient();
   try {
     URL urlLoc = new URL(resourceNotProtected);
     page = (HtmlPage) webClient.getPage(urlLoc);
     log(Level.FINEST, "evaluateNotEnforced", "Resource Page :\n" + page.asXml());
     iIdx = -1;
     iIdx = getHtmlPageStringIndex(page, "Notenforced Page");
     assert (iIdx != -1);
   } catch (Exception e) {
     log(Level.SEVERE, "evaluateNotEnforced", e.getMessage());
     e.printStackTrace();
     throw e;
   }
   exiting("evaluateNotEnforced");
 }
コード例 #9
0
 public String getParsedPage() {
   List<String> alertHandler = new LinkedList<String>();
   ;
   WebClient webClient = new WebClient(BrowserVersion.FIREFOX_24); // CHROME);
   webClient.setAjaxController(new MyNicelyResynchronizingAjaxController());
   webClient.getOptions().setJavaScriptEnabled(true);
   webClient.getOptions().setTimeout(3500);
   webClient.getOptions().setThrowExceptionOnScriptError(true);
   webClient.getOptions().setCssEnabled(true);
   webClient.getOptions().isRedirectEnabled();
   webClient.setAlertHandler(
       new CollectingAlertHandler(alertHandler)); // 将JavaScript中alert标签产生的数据保存在一个链表中
   // webClient.getOptions().setThrowExceptionOnScriptError(false);
   HtmlPage page = null;
   JavaScriptEngine engine = new JavaScriptEngine(webClient);
   webClient.setJavaScriptEngine(engine);
   try {
     page = webClient.getPage(data);
   } catch (FailingHttpStatusCodeException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   } catch (MalformedURLException e) {
     e.printStackTrace();
   } catch (IOException e) {
     e.printStackTrace();
   }
   if (page != null) {
     return page.asXml();
   }
   return null;
 }
コード例 #10
0
 @Test
 public void testDecoratedFactories() throws Exception {
   HtmlPage page = webClient.getPage(webUrl);
   String pageXml = page.asXml();
   assertTrue(pageXml.contains("MyFacesContextFactory$MyFacesContext"));
   assertTrue(pageXml.contains("MyExceptionHandlerFactory$MyExceptionHandler"));
 }
コード例 #11
0
ファイル: Issue2502IT.java プロジェクト: codylerum/mojarra
  @Test
  public void testEscape() throws Exception {

    String expected1 = "&lt;i&gt;test1&lt;/i&gt;";
    String expected2 = "&lt;i&gt;test2&lt;/i&gt;";
    String expected3 = "&lt;i&gt;test3&lt;/i&gt;";

    /*
     * We don't want this to be simulated as an IE browser since IE
     * does some automatic replacing.
     */
    webClient = new WebClient(BrowserVersion.FIREFOX_31);
    HtmlPage page = webClient.getPage(webUrl + "faces/outputEscape.xhtml");
    assertTrue(page.asXml().contains(expected1));
    assertTrue(page.asXml().contains(expected2));
    assertTrue(page.asXml().contains(expected3));
  }
コード例 #12
0
 @Test
 @JsfTest(
     value = JsfVersion.JSF_2_3_0_M01,
     excludes = {WEBLOGIC_12_1_4})
 public void testInjectExternalContext() throws Exception {
   HtmlPage page = webClient.getPage(webUrl + "faces/injectExternalContext.xhtml");
   assertTrue(page.asXml().contains("com.sun.faces.context.ExternalContextImpl"));
 }
コード例 #13
0
ファイル: Issue1508IT.java プロジェクト: ivartanian/mojarra
 /**
  * Test to validate empty fields.
  *
  * <p>Note: this test is excluded on Tomcat because the included EL parser requires a System
  * property for this test to work, which would cause problems with other tests. See
  * http://tomcat.apache.org/tomcat-7.0-doc/config/systemprops.html and look for COERCE_TO_ZERO
  */
 @Test
 public void testValidateEmptyFields() throws Exception {
   HtmlPage page = webClient.getPage(webUrl + "faces/index.xhtml");
   if (page.getWebResponse().getResponseHeaderValue("Server") == null
       || !page.getWebResponse().getResponseHeaderValue("Server").startsWith("Apache-Coyote")) {
     page = webClient.getPage(webUrl + "faces/validateEmptyFields.xhtml");
     HtmlSubmitInput button = (HtmlSubmitInput) page.getElementById("form:submitButton");
     page = button.click();
     assertTrue(page.asXml().contains("We got called!"));
   }
 }
コード例 #14
0
  @Test
  @JsfTest(
      value = JSF_2_3_0_M03,
      excludes = {WEBLOGIC_12_1_4})
  public void testRequestParameterMap() throws Exception {

    HtmlPage page = webClient.getPage(webUrl + "request.xhtml?foo=bar");

    // Request parameter value should be printed on the page
    assertTrue(page.asXml().contains("foo:bar"));
  }
コード例 #15
0
  @Test
  public void canDropFailureCause() throws Exception {
    ClaimBuildAction action =
        applyClaimWithFailureCauseSelected("claim", CAUSE_NAME_2, REASON, CAUSE_DESCRIPTION_2);

    HtmlPage page = whenNavigatingtoClaimPage();
    page.getElementById("dropClaim").click();
    page = whenNavigatingtoClaimPage();
    assertThat(action.isClaimed(), is(false));
    assertTrue(page.asXml().contains(IDENTIFIED_PROBLEMS));
    assertTrue(page.asXml().contains("No identified problem"));
  }
コード例 #16
0
 public static void main(String[] args) throws Exception {
   HtmlPage page;
   final WebClient webClient = new WebClient();
   String url = "http://www.google.com";
   if (args.length >= 1) url = args[0];
   /*
   webClient.setJavaScriptEnabled(false);
   */
   page = webClient.getPage(url);
   System.out.println(page.asXml());
   webClient.closeAllWindows();
 }
コード例 #17
0
 /**
  * This test verifies that an attribute named 'checked' can be successfully updated from a partial
  * response (over Ajax).
  */
 @Test
 public void testUpdateAttributeNamedChecked() throws Exception {
   HtmlPage page = webClient.getPage(webUrl + "faces/attributeNameIsChecked.xhtml");
   HtmlCheckBoxInput cbox = (HtmlCheckBoxInput) page.getElementById("form1:foo");
   assertTrue(cbox.isChecked() == false);
   assertTrue(page.asXml().contains("foo"));
   HtmlSubmitInput button = (HtmlSubmitInput) page.getElementById("form1:button");
   page = button.click();
   webClient.waitForBackgroundJavaScript(60000);
   cbox = (HtmlCheckBoxInput) page.getElementById("form1:foo");
   assertTrue(cbox.isChecked() == true);
 }
コード例 #18
0
  @Test
  public void canClaimFailureCause() throws Exception {
    ClaimBuildAction action =
        applyClaimWithFailureCauseSelected("claim", CAUSE_NAME_2, REASON, CAUSE_DESCRIPTION_2);

    assertThat(action.getClaimedBy(), is("user1"));
    assertThat(action.getReason(), is(REASON));
    assertThat(action.isClaimed(), is(true));
    assertThat(action.isBFAEnabled(), is(true));

    HtmlPage page = whenNavigatingtoClaimPage();
    assertTrue(page.asXml().contains(IDENTIFIED_PROBLEMS));
    assertTrue(page.asXml().contains(CAUSE_NAME_2));
  }
コード例 #19
0
  @Test
  public void testTable() throws Exception {

    /*
     * Make sure the dynamically added table and table values are in place.
     */
    HtmlPage page = webClient.getPage(webUrl + "faces/table.xhtml");
    assertTrue(page.asXml().indexOf("encodeBegin") < page.asXml().indexOf("Foo"));
    assertTrue(page.asXml().indexOf("Foo") < page.asXml().indexOf("Bar"));
    assertTrue(page.asXml().indexOf("Bar") < page.asXml().indexOf("Baz"));
    assertTrue(page.asXml().indexOf("Baz") < page.asXml().indexOf("encodeEnd"));

    /**
     * After clicking make sure the added component is still in its proper place. Also verify the
     * validation required error message appears as the third input component has required attribute
     * set to true.
     */
    HtmlSubmitInput button = (HtmlSubmitInput) page.getElementById("button");
    page = button.click();
    assertTrue(page.asXml().indexOf("encodeBegin") < page.asXml().indexOf("Foo"));
    assertTrue(page.asXml().indexOf("Foo") < page.asXml().indexOf("Bar"));
    assertTrue(page.asXml().indexOf("Bar") < page.asXml().indexOf("Baz"));
    assertTrue(page.asXml().indexOf("Baz") < page.asXml().indexOf("encodeEnd"));
  }
コード例 #20
0
  protected Set getLinksForData(HtmlPage page) {

    Set links = new HashSet();

    String strPage = page.asXml();

    Pattern p = Pattern.compile("bt-ofrd(.*?)htm");
    Matcher m = p.matcher(strPage);

    while (m.find()) {
      // System.out.println(HOST+m.group());
      links.add(HOST + m.group());
    }
    this.countLinks += links.size();
    return links;
  }
コード例 #21
0
  @Test
  public void testAddComponent() throws Exception {

    /*
     * Make sure the added component is contained within the outer component.
     */
    HtmlPage page = webClient.getPage(webUrl + "faces/add.xhtml");
    assertTrue(
        page.asXml().indexOf("encodeBegin") < page.asXml().indexOf(" Dynamically added child"));
    assertTrue(
        page.asXml().indexOf(" Dynamically added child") < page.asXml().indexOf("encodeEnd"));

    /** After clicking make sure the added component is still in its proper place. */
    HtmlSubmitInput button = (HtmlSubmitInput) page.getElementById("button");
    page = button.click();
    assertTrue(
        page.asXml().indexOf("encodeBegin") < page.asXml().indexOf(" Dynamically added child"));
    assertTrue(
        page.asXml().indexOf(" Dynamically added child") < page.asXml().indexOf("encodeEnd"));
  }
コード例 #22
0
 /** Validates the value of REMOTE_USER for anonymous user. */
 @Test(
     groups = {
       "ldapv3",
       "ldapv3_sec",
       "s1ds",
       "s1ds_sec",
       "ad",
       "ad_sec",
       "amsdk",
       "amsdk_sec",
       "jdbc",
       "jdbc_sec"
     })
 public void evaluateAnonymous() throws Exception {
   entering("evaluateAnonymous", null);
   boolean checkSupport = isAnonymousSupported();
   if (checkSupport) {
     webClient = new WebClient();
     try {
       URL urlLoc = new URL(resourceNotProtected);
       page = (HtmlPage) webClient.getPage(urlLoc);
       log(Level.FINEST, "evaluateAnonymous", "Resource Page :\n" + page.asXml());
       page = (HtmlPage) webClient.getPage(url);
       iIdx = -1;
       iIdx = getHtmlPageStringIndex(page, "REMOTE_USER:anonymous");
       assert (iIdx != -1);
     } catch (Exception e) {
       log(Level.SEVERE, "evaluateAnonymous", e.getMessage());
       e.printStackTrace();
       throw e;
     }
   } else {
     log(
         Level.FINEST,
         "evaluateAnonymous",
         "REMOTE_USER test for anonymous user not " + "valid for J2EE Agents");
   }
   exiting("evaluateAnonymous");
 }
コード例 #23
0
  public static void main(String[] args) throws IOException {

    WebClient client = new WebClient(BrowserVersion.CHROME);
    CookieManager cookie = new CookieManager();
    client.setCookieManager(cookie);
    client.getOptions().setJavaScriptEnabled(true);
    client.getOptions().setActiveXNative(false);
    client.getOptions().setCssEnabled(false);
    client.getOptions().setThrowExceptionOnScriptError(false);
    client.getOptions().setThrowExceptionOnFailingStatusCode(false);
    client.getOptions().setDoNotTrackEnabled(true);
    client.getOptions().setPrintContentOnFailingStatusCode(false);
    client.setAjaxController(new NicelyResynchronizingAjaxController());
    client.setJavaScriptTimeout(Long.MAX_VALUE);

    List<Integer> TopCategory = new LinkedList<Integer>(TopCategoryUrl.keySet());
    Collections.sort(TopCategory);

    long today = new Date().getTime();
    long ymd = today - 1000 * 60 * 60 * 24;
    String date = sdf.format(ymd);
    FileWriter fw = new FileWriter("ShuTaobaoTop/search-" + date, false);
    BufferedWriter bw = new BufferedWriter(fw);

    while (TopCategory.size() > 0) {
      int cid = TopCategory.get(0);
      //			if(cid<50002766)
      //			{
      //				TopCategory.remove(0);
      //				continue;
      //			}
      String cname = TopCategoryUrl.get(cid);
      String pid = "0", pname = "";
      String topUrl = "http://shu.taobao.com/top/" + cid + "/search";

      boolean success = false;
      ArrayList<String> result = new ArrayList<String>();
      try {
        //				client.getOptions().setJavaScriptEnabled(true);
        do {
          System.out.println("剩余类目数=" + TopCategory.size());
          // ProxyUnit.configProxy(client, ProxyUnit.CHECKURL);
        } while (false == AccountLogin.loginTaoBao(client, AccountLogin.TAOBAOLOGINURL, true));
        //				client.getOptions().setJavaScriptEnabled(false);

        HtmlPage queryTrade = client.getPage(topUrl);
        Thread.sleep(1000L);
        System.out.println(queryTrade.getTitleText());

        /*
         * 解析
         */
        Document doc = Jsoup.parse(queryTrade.asXml());
        Element time = doc.getElementsByAttributeValue("class", "time").get(0);
        String startTime =
            time.text().substring(6, 16).replace("-", ""); // 统计时间: 2014-05-17 - 2014-05-23
        String endTime = time.text().substring(19).replace("-", "");
        Elements elements =
            doc.getElementsByAttributeValueStarting(
                "class", "mod "); // <div class="mod odd mod-10 sm-ua"> <h3 class="title">
        for (Element element : elements) {
          String title = element.getElementsByTag("h3").get(0).text();
          System.out.println(title);
          Elements lis =
              element.getElementsByTag("ol").get(0).getElementsByTag("li"); // <li class="up ">
          for (Element li : lis) {
            Elements spans = li.getElementsByTag("span");
            String rank = spans.get(0).text();
            String key = spans.get(1).text();
            String rise = spans.get(2).text();
            rise = rise.substring(0, rise.length() - 1);

            URL href =
                new URL(
                    URLDecoder.decode(
                        "http://shu.taobao.com"
                            + spans.get(1).getElementsByTag("a").get(0).attr("href"),
                        "utf-8"));
            String hrefQuery = href.getQuery();
            if (hrefQuery.contains("cid=")) {
              if ("0".equals(pid)) {
                pid = String.valueOf(cid);
                pname = cname;
              }
              cid = Integer.parseInt(hrefQuery.split("cid=")[1].split("&")[0]);
              cname = title;
            }

            System.out.println(
                startTime + "\001" + endTime + "\001" + cid + "\001" + cname + "\001" + pid + "\001"
                    + pname + "\001" + rank + "\001" + key + "\001" + rise);
            result.add(
                startTime + "\001" + endTime + "\001" + cid + "\001" + cname + "\001" + pid + "\001"
                    + pname + "\001" + rank + "\001" + key + "\001" + rise);
          }
        }
        success = true;
      } catch (Exception e) {
        // TODO Auto-generated catch block
        // e.printStackTrace();
      }
      if (success) {
        TopCategory.remove(0);
        System.out.println("剩余类目数=" + TopCategory.size());
        for (String r : result) {
          bw.write(r + "\n");
        }
      }
    }
    bw.close();
    fw.close();
  }
コード例 #24
0
ファイル: Issue2051IT.java プロジェクト: ivartanian/mojarra
 @Test
 public void testNotRendered() throws Exception {
   HtmlPage page = webClient.getPage(webUrl + "faces/debugNotRendered.xhtml");
   assertFalse(page.asXml().contains("faceletsDebug"));
 }
コード例 #25
0
  @Test
  public void testStable() throws Exception {

    String inputValue1 = "value=" + '"' + "1" + '"';
    String inputValue2 = "value=" + '"' + "2" + '"';
    String idText3 = "id=" + '"' + "text3" + '"';

    /*
     * Make sure the three dynamically added input components are in their proper place.
     */
    HtmlPage page = webClient.getPage(webUrl + "faces/stable.xhtml");
    assertTrue(page.asXml().indexOf("encodeBegin") < page.asXml().indexOf(inputValue1));
    assertTrue(page.asXml().indexOf(inputValue1) < page.asXml().indexOf(inputValue2));
    assertTrue(page.asXml().indexOf(inputValue2) < page.asXml().indexOf(idText3));
    assertTrue(page.asXml().indexOf("text3") < page.asXml().indexOf("encodeEnd"));

    /**
     * After clicking make sure the added component is still in its proper place. Also verify the
     * validation required error message appears as the third input component has required attribute
     * set to true.
     */
    HtmlSubmitInput button = (HtmlSubmitInput) page.getElementById("button");
    page = button.click();
    assertTrue(page.asXml().contains("text3: Validation Error: Value is required."));
    assertTrue(page.asXml().indexOf("encodeBegin") < page.asXml().indexOf(inputValue1));
    assertTrue(page.asXml().indexOf(inputValue1) < page.asXml().indexOf(inputValue2));
    assertTrue(page.asXml().indexOf(inputValue2) < page.asXml().indexOf(idText3));
    assertTrue(page.asXml().indexOf("text3") < page.asXml().indexOf("encodeEnd"));
  }
コード例 #26
0
  @Override
  public HtmlPage getData() {
    // TODO Auto-generated method stub
    MainDataBean mainDataBean =
        (MainDataBean) UserBeanFactory.getBeanFactoryObject().getBean("mainDataBean");
    String URL = mainDataBean.getRedBusUrl();
    URL = "https://www.redbus.in/";
    ClientFactory cf =
        (ClientFactory) UserBeanFactory.getBeanFactoryObject().getBean("clientFactory");
    WebClient client = cf.getWebClient();
    //		try {
    //			client.getOptions().setJavaScriptEnabled(true);
    //			client.getOptions().setThrowExceptionOnScriptError(false);
    //			new InterceptWebConnection(client);
    //			HtmlPage page = client.getPage(URL);
    //			client.waitForBackgroundJavaScript(10000);
    //			System.out.print(page.asXml());
    //		} catch (Exception e) {
    //			// TODO Auto-generated catch block
    //			e.printStackTrace();
    //		}
    String html;
    try {
      //			client.getOptions().setUseInsecureSSL(true);
      //			client.se
      // client.getOptions().setJavaScriptEnabled(true);
      // client.getOptions().setThrowExceptionOnScriptError(false);
      new InterceptWebConnection(client);
      // client.addRequestHeader("Host", "www.redbus.in");
      // client.addRequestHeader("Referer", "https://www.redbus.in/");
      // Booking/SelectBus.aspx?fromCityId=248&toCityId=134&doj=12-Dec-2015&busType=Any&opId=0
      HtmlPage page = client.getPage("https://www.redbus.in/");
      client.waitForBackgroundJavaScript(1000);

      DomElement source = page.getElementById("txtSource");
      DomElement destination = page.getElementById("txtDestination");
      DomElement date = page.getElementById("txtOnwardCalendar");
      DomElement search = page.getElementById("searchBtn");
      //			List<DomElement> inputs = (List<DomElement>)
      // page.getByXPath("//input[@class='XXinput']");
      //			HtmlTextInput source=null,destination=null,date1=null;
      //			for (DomElement domElement : inputs) {
      //				System.out.println("Coming  into sourrce");
      //				if(domElement.getAttribute("id").equals("txtSource")){
      //					System.out.println("Coming  into sourrce");
      //					source = (HtmlTextInput) domElement;
      //				}else if (domElement.getAttribute("id").equals("txtDestination")){
      //					System.out.println("Coming  into destination");
      //					destination =(HtmlTextInput) domElement;
      //				}
      //			}
      //			List<DomElement> Cal_inputs = (List<DomElement>) page.getByXPath("//input[@class='XXinput
      // calendar']");
      //			HtmlElement searchButton = (HtmlElement) page.getFirstByXPath("//button[@class='RB
      // Xbutton']");
      //			for (DomElement domElement : Cal_inputs) {
      //				if(domElement.getAttribute("id").equals("txtOnwardCalendar")){
      //					System.out.println("Coming  into calandar");
      //					date1 =(HtmlTextInput) domElement;
      //				}
      //			}
      source.setAttribute("value", "Visakapatnam");
      // source.setValueAttribute("Visakapatnam");
      destination.setAttribute("value", "Vijayawada");
      // destination.setValueAttribute("Vijayawada");
      date.setAttribute("value", "12-12-2015");

      // date.setValueAttribute("27-10-2015");
      //			client.getOptions().setThrowExceptionOnScriptError(false);
      //			client.getOptions().setThrowExceptionOnFailingStatusCode(false);
      //
      HtmlPage page1 = search.click();
      client.waitForBackgroundJavaScript(200);
      html = page1.asXml();
      System.out.println(html);
    } catch (Exception e) {
      e.printStackTrace();
    }

    return null;
  }
コード例 #27
0
ファイル: FlashIT.java プロジェクト: javaserverfaces/mojarra
  @JsfTest(
      value = JSF_2_2_0_M02,
      excludes = {WEBLOGIC_12_1_4})
  @Test
  public void testFlash() throws Exception {
    // Get the first page
    HtmlPage page = webClient.getPage(webUrl + "faces/index.xhtml");
    String pageText = page.asXml();
    // (?s) is an "embedded flag expression" for the "DOTALL" operator.
    // It says, "let . match any character including line terminators."
    // Because page.asXml() returns a big string with lots of \r\n chars
    // in it, we need (?s).
    // the page contains a table tag with a frame attribute whose value is hsides.

    // the page contains the following span, with the following id, with no contents
    assertTrue(pageText.matches("(?s)(?m).*<span.*id=\"fooValueId\">\\s*</span>.*"));

    // Click the reload button
    HtmlSubmitInput button = (HtmlSubmitInput) page.getHtmlElementById("reload");
    page = (HtmlPage) button.click();
    pageText = page.asXml();
    // verify that fooValue is there, indicating that it's been stored in the flash
    assertTrue(pageText.matches("(?s)(?m).*<span.*id=\"fooValueId\">\\s*fooValue\\s*</span>.*"));

    // Get the first page, again
    page = webClient.getPage(webUrl + "faces/index.xhtml");

    // the page contains the following span, with the following id, with no contents
    // meaning the flash has no value for foo
    // assertTrue(pageText.matches("(?s)(?m).*<span.*id=\"fooValueId\">\\s*</span>.*"));
    // fill in "addMessage" in the textBox
    HtmlTextInput text = (HtmlTextInput) page.getHtmlElementById("inputText");
    text.setValueAttribute("addMessage");

    // go to the next page
    button = (HtmlSubmitInput) page.getHtmlElementById("next");
    page = (HtmlPage) button.click();
    pageText = page.asXml();
    // See that it has fooValue
    assertTrue(
        pageText.matches("(?s)(?m).*<span.*id=\"flash2FooValueId\">\\s*fooValue\\s*</span>.*"));
    // See that it has barValue
    assertTrue(
        pageText.matches("(?s)(?m).*<span.*id=\"flash2BarValueId\">\\s*barValue\\s*</span>.*"));
    // See that it has the message
    assertTrue(-1 != pageText.indexOf("test that this persists across the redirect"));

    // click the reload button
    button = (HtmlSubmitInput) page.getHtmlElementById("reload");
    page = (HtmlPage) button.click();
    pageText = page.asXml();

    // See that it doesn't have the message
    assertTrue(-1 == pageText.indexOf("test that this persists across the redirect"));

    // Click the back button
    button = (HtmlSubmitInput) page.getHtmlElementById("back");
    page = (HtmlPage) button.click();

    // Click the next button
    button = (HtmlSubmitInput) page.getHtmlElementById("next");
    page = (HtmlPage) button.click();
    pageText = page.asXml();

    // See that the page does not have the message
    assertTrue(-1 == pageText.indexOf("test that this persists across the redirect"));

    // Click the next button
    button = (HtmlSubmitInput) page.getHtmlElementById("next");
    page = (HtmlPage) button.click();
    pageText = page.asXml();

    // See that it has banzai
    assertTrue(
        pageText.matches("(?s)(?m).*<span.*id=\"flash3NowValueId\">\\s*banzai\\s*</span>.*"));

    // Click the next button
    button = (HtmlSubmitInput) page.getHtmlElementById("next");
    page = (HtmlPage) button.click();
    pageText = page.asXml();

    // See that it still has banzai
    assertTrue(
        pageText.matches("(?s)(?m).*<span.*id=\"flash4BuckarooValueId\">\\s*banzai\\s*</span>.*"));

    // click the link
    HtmlAnchor link = (HtmlAnchor) page.getElementById("link");
    page = link.click();

    // on flash5
    link = (HtmlAnchor) page.getElementById("link");
    page = link.click();

    assertTrue(page.asText().contains("Value is 1."));

    // click the link on the next page
    link = (HtmlAnchor) page.getElementById("link");
    page = link.click();

    assertTrue(page.asText().contains("Value is 1."));

    // click the link on the same page
    link = (HtmlAnchor) page.getElementById("link");
    page = link.click();

    assertTrue(page.asText().contains("Value is 1."));

    // click the link on the same page
    link = (HtmlAnchor) page.getElementById("link");
    page = link.click();

    assertTrue(page.asText().contains("Value is 1."));

    link = (HtmlAnchor) page.getElementById("link2");
    page = link.click();

    assertTrue(page.asText().contains("Value is 1."));

    link = (HtmlAnchor) page.getElementById("link");
    page = link.click();

    // it went away because there was no keep
    assertTrue(page.asText().contains("Value is ."));

    page = webClient.getPage(webUrl + "faces/flash9.xhtml");

    text = (HtmlTextInput) page.getHtmlElementById("valueA");
    text.setValueAttribute("a value");

    text = (HtmlTextInput) page.getHtmlElementById("valueB");
    text.setValueAttribute("b value");

    text = (HtmlTextInput) page.getHtmlElementById("valueC");
    text.setValueAttribute("c value");

    button = (HtmlSubmitInput) page.getHtmlElementById("keep");
    page = (HtmlPage) button.click();

    pageText = page.asText();

    assertTrue(pageText.contains("valueA: a value"));
    assertTrue(pageText.contains("valueB: b value"));
    assertTrue(pageText.contains("valueC: c value"));

    link = (HtmlAnchor) page.getElementById("flash9");
    page = link.click();

    text = (HtmlTextInput) page.getHtmlElementById("valueA");
    assertEquals(text.getValueAttribute(), "a value");

    text = (HtmlTextInput) page.getHtmlElementById("valueB");
    assertEquals(text.getValueAttribute(), "b value");

    text = (HtmlTextInput) page.getHtmlElementById("valueC");
    assertEquals(text.getValueAttribute(), "c value");

    page = webClient.getPage(webUrl + "faces/flash9.xhtml");
    text = (HtmlTextInput) page.getHtmlElementById("valueA");
    assertEquals(text.getValueAttribute(), "");

    text = (HtmlTextInput) page.getHtmlElementById("valueB");
    assertEquals(text.getValueAttribute(), "");

    text = (HtmlTextInput) page.getHtmlElementById("valueC");
    assertEquals(text.getValueAttribute(), "");

    text = (HtmlTextInput) page.getHtmlElementById("valueA");
    text.setValueAttribute("A value");

    text = (HtmlTextInput) page.getHtmlElementById("valueB");
    text.setValueAttribute("B value");

    text = (HtmlTextInput) page.getHtmlElementById("valueC");
    text.setValueAttribute("C value");

    button = (HtmlSubmitInput) page.getHtmlElementById("nokeep");
    page = (HtmlPage) button.click();

    pageText = page.asText();

    assertTrue(pageText.contains("valueA: A value"));
    assertTrue(pageText.contains("valueB: B value"));
    assertTrue(pageText.contains("valueC: C value"));

    button = (HtmlSubmitInput) page.getHtmlElementById("reload");
    page = (HtmlPage) button.click();

    pageText = page.asText();

    assertTrue(!pageText.contains("valueA: A value"));
    assertTrue(!pageText.contains("valueB: B value"));
    assertTrue(!pageText.contains("valueC: C value"));

    // content from Sebastian Hennebrueder
    page = webClient.getPage(webUrl + "faces/flash12.xhtml");
    button = (HtmlSubmitInput) page.getHtmlElementById("start");
    page = (HtmlPage) button.click();

    pageText = page.asText();
    assertTrue(pageText.contains("4711"));

    page = (HtmlPage) page.refresh();

    pageText = page.asText();
    assertTrue(!pageText.contains("4711"));

    // Test for JAVASERVERFACES-2087
    page = webClient.getPage(webUrl + "faces/flash13.xhtml");
    button = (HtmlSubmitInput) page.getHtmlElementById("flashbtn");
    page = (HtmlPage) button.click();

    pageText = page.asText();
    assertTrue(pageText.contains("read strobist"));

    page = webClient.getPage(webUrl + "faces/flash13.xhtml");
    pageText = page.asText();
    assertTrue(!pageText.contains("read strobist"));

    page = webClient.getPage(webUrl + "faces/flash13.xhtml");
    pageText = page.asText();
    assertTrue(!pageText.contains("read strobist"));

    page = webClient.getPage(webUrl + "faces/flash14.xhtml");
    pageText = page.asText();
    assertTrue(
        pageText.matches(
            "(?s).*\\[received javax.faces.event.PreClearFlashEvent source:\\{\\}\\].*"));
  }
コード例 #28
0
  @Test
  public void testAll() throws Exception {
    HtmlPage page = (HtmlPage) this.client.getContentPage();

    try {
      // Welcome page

      assertTrue(page.asText().contains("Welcome to Forge"));

      // Create an Owner

      page = page.getAnchorByText("Owner").click();
      assertTrue(page.asText().contains("Search Owner entities"));
      page = page.getAnchorByText("Create New").click();

      HtmlForm form = page.getFormByName("create");
      assertTrue(page.asText().contains("Create a new Owner"));
      form.getInputByName("create:ownerBeanOwnerFirstName").setValueAttribute("Owner Firstname #1");
      form.getInputByName("create:ownerBeanOwnerLastName").setValueAttribute("Owner Lastname #1");
      page = page.getAnchorByText("Save").click();

      // Edit the Owner

      assertTrue(page.asText().contains("Search Owner entities"));
      HtmlTable table = (HtmlTable) page.getHtmlElementById("search:ownerBeanPageItems");
      assertEquals("Owner Firstname #1", table.getCellAt(1, 0).getTextContent());
      assertEquals("Owner Lastname #1", table.getCellAt(1, 1).getTextContent());

      page = page.getAnchorByText("Owner Firstname #1").click();
      assertTrue(page.asText().contains("View existing Owner"));
      assertEquals(
          "Owner Firstname #1",
          page.getHtmlElementById("ownerBeanOwnerFirstName").getTextContent());
      assertEquals(
          "Owner Lastname #1", page.getHtmlElementById("ownerBeanOwnerLastName").getTextContent());
      assertEquals("", page.getHtmlElementById("ownerBeanOwnerAddress").getTextContent());
      page = page.getAnchorByText("Edit").click();

      form = page.getFormByName("create");
      form.getInputByName("create:ownerBeanOwnerAddress").setValueAttribute("Owner Address #1");
      page = page.getAnchorByText("Save").click();
      assertTrue(page.asText().contains("View existing Owner"));
      assertEquals(
          "Owner Address #1", page.getHtmlElementById("ownerBeanOwnerAddress").getTextContent());

      page = page.getAnchorByText("View All").click();
      assertTrue(page.asText().contains("Search Owner entities"));

      // Create a Pet and associate it with the Owner

      page = page.getAnchorByText("Pet").click();
      assertTrue(page.asText().contains("Search Pet entities"));
      page = page.getAnchorByText("Create New").click();

      form = page.getFormByName("create");
      form.getInputByName("create:petBeanPetName").setValueAttribute("Pet #1");
      form.getInputByName("create:petBeanPetType").setValueAttribute("2");
      form.getInputByName("create:petBeanPetSendReminders").setChecked(true);
      form.getSelectByName("create:petBeanPetOwner").setSelectedAttribute("1", true);
      page = page.getAnchorByText("Save").click();

      // Click through from the Pet to the Owner

      table = (HtmlTable) page.getHtmlElementById("search:petBeanPageItems");
      assertEquals("Pet #1", table.getCellAt(1, 0).getTextContent());
      assertEquals("2", table.getCellAt(1, 1).getTextContent());
      DomNode booleanNode = table.getCellAt(1, 2).getChildNodes().get(0).getChildNodes().get(0);

      assertEquals("span", booleanNode.getNodeName());
      assertEquals("", booleanNode.getTextContent());
      assertEquals(
          "boolean-true", booleanNode.getAttributes().getNamedItem("class").getNodeValue());

      assertEquals(
          "Owner firstName: Owner Firstname #1, lastName: Owner Lastname #1, address: Owner Address #1",
          table.getCellAt(1, 3).getTextContent());

      page = page.getAnchorByText("Pet #1").click();
      assertTrue(page.asText().contains("View existing Pet"));
      page =
          page.getAnchorByText(
                  "Owner firstName: Owner Firstname #1, lastName: Owner Lastname #1, address: Owner Address #1")
              .click();
      assertTrue(page.asText().contains("View existing Owner"));

      // Create a new Owner

      page = page.getAnchorByText("Create New").click();
      form = page.getFormByName("create");
      form.getInputByName("create:ownerBeanOwnerFirstName").setValueAttribute("Owner Firstname #2");
      form.getInputByName("create:ownerBeanOwnerLastName").setValueAttribute("Owner Lastname #2");
      page = page.getAnchorByText("Save").click();

      table = (HtmlTable) page.getHtmlElementById("search:ownerBeanPageItems");
      assertEquals("Owner Firstname #1", table.getCellAt(1, 0).getTextContent());
      assertEquals("Owner Lastname #1", table.getCellAt(1, 1).getTextContent());
      assertEquals("Owner Firstname #2", table.getCellAt(2, 0).getTextContent());
      assertEquals("Owner Lastname #2", table.getCellAt(2, 1).getTextContent());

      // Search for a Pet by Owner

      page = page.getAnchorByText("Pet").click();
      assertTrue(page.asText().contains("Search Pet entities"));

      table = (HtmlTable) page.getHtmlElementById("search:petBeanPageItems");
      assertEquals("Pet #1", table.getCellAt(1, 0).getTextContent());

      form = page.getFormByName("search");
      form.getSelectByName("search:petBeanExampleOwner").setSelectedAttribute("3", true);
      page = page.getAnchorByText("Search").click();
      table = (HtmlTable) page.getHtmlElementById("search:petBeanPageItems");
      assertEquals("", table.getCellAt(1, 0).getTextContent());

      form = page.getFormByName("search");
      form.getSelectByName("search:petBeanExampleOwner").setSelectedAttribute("1", true);
      page = page.getAnchorByText("Search").click();
      page = page.getAnchorByText("Pet #1").click();

      // Delete a Pet

      assertTrue(page.asText().contains("View existing Pet"));
      page = page.getAnchorByText("Edit").click();
      assertTrue(page.asText().contains("Edit existing Pet"));
      page = page.getAnchorByText("Cancel").click();
      assertTrue(page.asText().contains("View existing Pet"));
      page = page.getAnchorByText("Edit").click();
      page = page.getAnchorByText("Delete").click();
      assertTrue(page.asText().contains("Search Pet entities"));
      table = (HtmlTable) page.getHtmlElementById("search:petBeanPageItems");
      assertEquals("", table.getCellAt(1, 0).getTextContent());
    } catch (Throwable t) {
      t.printStackTrace();
      throw new RuntimeException(t);
    } finally {
      System.out.println(page.asXml());
    }
  }