/**
  * 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());
   }
 }
Exemplo n.º 2
0
  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();
  }
Exemplo n.º 3
0
 public static boolean onCaptcha(HtmlPage page) {
   try {
     page.getAnchorByText("Use re-captcha");
     return true;
   } catch (ElementNotFoundException e) {
     return false;
   }
 }
  /**
   * Creates a new freestyle project and builds the project with a string parameter. If the build is
   * succesful, a rebuild of the last build is done. The rebuild on the project level should point
   * to the last build
   *
   * @throws Exception Exception
   */
  public void testWhenProjectWithParamsThenRebuildProjectExecutesRebuildOfLastBuild()
      throws Exception {
    FreeStyleProject project = createFreeStyleProject();

    // Build (#1)
    project
        .scheduleBuild2(
            0,
            new Cause.UserIdCause(),
            new ParametersAction(new StringParameterValue("name", "test")))
        .get();
    HtmlPage rebuildConfigPage = createWebClient().getPage(project, "1/rebuild");
    // Rebuild (#2)
    submit(rebuildConfigPage.getFormByName("config"));

    HtmlPage projectPage = createWebClient().getPage(project);
    WebAssert.assertLinkPresentWithText(projectPage, "Rebuild Last");

    HtmlAnchor rebuildHref = projectPage.getAnchorByText("Rebuild Last");
    assertEquals(
        "Rebuild Last should point to the second build",
        rebuildHref.getHrefAttribute(),
        "/" + project.getUrl() + "2/rebuild");
  }
  @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());
    }
  }