本文整理汇总了Java中com.gargoylesoftware.htmlunit.html.HtmlButton类的典型用法代码示例。如果您正苦于以下问题:Java HtmlButton类的具体用法?Java HtmlButton怎么用?Java HtmlButton使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HtmlButton类属于com.gargoylesoftware.htmlunit.html包,在下文中一共展示了HtmlButton类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testCreateNewDatastream
import com.gargoylesoftware.htmlunit.html.HtmlButton; //导入依赖的package包/类
@Test
@Ignore("The htmlunit web client can't handle the HTML5 file API")
public void testCreateNewDatastream() throws IOException {
final String pid = randomUUID().toString();
// can't do this with javascript, because HTMLUnit doesn't speak the HTML5 file api
final HtmlPage page = webClient.getPage(serverAddress);
final HtmlForm form = (HtmlForm)page.getElementById("action_create");
final HtmlInput slug = form.getInputByName("slug");
slug.setValueAttribute(pid);
final HtmlSelect type = (HtmlSelect)page.getElementById("new_mixin");
type.getOptionByValue("binary").setSelected(true);
final HtmlFileInput fileInput = (HtmlFileInput)page.getElementById("datastream_payload");
fileInput.setData("abcdef".getBytes());
fileInput.setContentType("application/pdf");
final HtmlButton button = form.getFirstByXPath("button");
button.click();
final HtmlPage page1 = javascriptlessWebClient.getPage(serverAddress + pid);
assertEquals(serverAddress + pid, page1.getTitleText());
}
示例2: allowAccess
import com.gargoylesoftware.htmlunit.html.HtmlButton; //导入依赖的package包/类
private HtmlPage allowAccess(WebClient webClient, HtmlPage allowAccessPage) throws IOException {
HtmlButton allowAccessButton = (HtmlButton) allowAccessPage.getElementById("submit_approve_access");
if (allowAccessButton == null) {
throw new RuntimeException("Cannot find allow access button in html page :\n" + allowAccessPage.asXml());
}
webClient.waitForBackgroundJavaScriptStartingBefore(WAIT_DELAY_MS);
// allowAccessButton.click() does not work because
// allowAccessButton.isVisible() is false
// for some reason (click() was working with htmlunit 2.23)
HtmlPage tokenPage = clickButtonIgnoringVisibility(allowAccessButton);
return tokenPage;
}
示例3: testCreateTasks
import com.gargoylesoftware.htmlunit.html.HtmlButton; //导入依赖的package包/类
@Test
public void testCreateTasks() throws Exception {
HtmlPage createTaskPage = webClient.getPage("http://localhost:8080/tasks/new");
HtmlForm form = createTaskPage.getHtmlElementById("form");
HtmlTextInput nameInput = createTaskPage.getHtmlElementById("name");
nameInput.setValueAttribute("My first task");
HtmlTextArea descriptionInput = createTaskPage.getHtmlElementById("description");
descriptionInput.setText("Description of my first task");
HtmlButton submit = form.getOneHtmlElementByAttribute("button", "type", "submit");
HtmlPage taskListPage = submit.click();
Assertions.assertThat(taskListPage.getUrl().toString()).endsWith("/tasks");
// String id = taskListPage.getHtmlElementById("todolist").getTextContent();
// assertThat(id).isEqualTo("123");
// String summary = newMessagePage.getHtmlElementById("summary").getTextContent();
// assertThat(summary).isEqualTo("Spring Rocks");
// String text = newMessagePage.getHtmlElementById("text").getTextContent();
// assertThat(text).isEqualTo("In case you didn't know, Spring Rocks!");
}
示例4: createAndVerifyObjectWithIdFromRootPage
import com.gargoylesoftware.htmlunit.html.HtmlButton; //导入依赖的package包/类
private HtmlPage createAndVerifyObjectWithIdFromRootPage(final String pid) throws IOException {
final HtmlPage page = webClient.getPage(serverAddress);
final HtmlForm form = (HtmlForm)page.getElementById("action_create");
final HtmlSelect type = (HtmlSelect)page.getElementById("new_mixin");
type.getOptionByValue("container").setSelected(true);
final HtmlInput new_id = (HtmlInput)page.getElementById("new_id");
new_id.setValueAttribute(pid);
final HtmlButton button = form.getFirstByXPath("button");
button.click();
try {
final HtmlPage page1 = webClient.getPage(serverAddress + pid);
assertEquals("Page had wrong title!", serverAddress + pid, page1.getTitleText());
return page1;
} catch (final FailingHttpStatusCodeException e) {
fail("Did not successfully retrieve created page! Got HTTP code: " + e.getStatusCode());
return null;
}
}
示例5: testCreateNewDatastreamWithNoFileAttached
import com.gargoylesoftware.htmlunit.html.HtmlButton; //导入依赖的package包/类
@Test
public void testCreateNewDatastreamWithNoFileAttached() throws IOException {
final String pid = randomUUID().toString();
// can't do this with javascript, because HTMLUnit doesn't speak the HTML5 file api
final HtmlPage page = webClient.getPage(serverAddress);
final HtmlForm form = (HtmlForm)page.getElementById("action_create");
final HtmlInput slug = form.getInputByName("slug");
slug.setValueAttribute(pid);
final HtmlSelect type = (HtmlSelect)page.getElementById("new_mixin");
type.getOptionByValue("binary").setSelected(true);
final HtmlButton button = form.getFirstByXPath("button");
button.click();
javascriptlessWebClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
final int status = javascriptlessWebClient.getPage(serverAddress + pid).getWebResponse().getStatusCode();
assertEquals(NOT_FOUND.getStatusCode(), status);
}
示例6: testCreateNewObjectAndSetProperties
import com.gargoylesoftware.htmlunit.html.HtmlButton; //导入依赖的package包/类
@Test
@Ignore
public void testCreateNewObjectAndSetProperties() throws IOException {
final String pid = createNewObject();
final HtmlPage page = javascriptlessWebClient.getPage(serverAddress + pid);
final HtmlForm form = (HtmlForm)page.getElementById("action_sparql_update");
final HtmlTextArea sparql_update_query = (HtmlTextArea)page.getElementById("sparql_update_query");
sparql_update_query.setText("INSERT { <> <info:some-predicate> 'asdf' } WHERE { }");
final HtmlButton button = form.getFirstByXPath("button");
button.click();
final HtmlPage page1 = javascriptlessWebClient.getPage(serverAddress + pid);
assertTrue(page1.getElementById("metadata").asText().contains("some-predicate"));
}
示例7: roomBooking
import com.gargoylesoftware.htmlunit.html.HtmlButton; //导入依赖的package包/类
public void roomBooking( User user, Meeting meeting ) throws Exception
{
List< String > errorMessages = new ArrayList< String >();
HtmlPage page = navigateToPage( user, BOOKING, true );
logger.debug( "Page loaded" );
HtmlForm form = page.getForms().get( 0 );
HtmlButton button = form.getFirstByXPath( "//*[@id=\"Submit\"]" );
HtmlSelect select = (HtmlSelect)page.getElementById( "ConferenceRooms" );
HtmlOption option = select.getOptionByText( meeting.getRoom() );
select.setSelectedAttribute( option, true );
Date date = meeting.getDate();
if( date != null )
{
HtmlTextInput startDate = form.getFirstByXPath( ".//*[@id='StartDate']" );
DateFormat formatter = new SimpleDateFormat( "MM/dd/yyyy" );
startDate.setAttribute( "value", formatter.format( date ) );
}
HtmlInput inputStartTime = form.getInputByName( "StartTime" );
inputStartTime.setValueAttribute( meeting.getFromTime() );
HtmlInput inputEndTime = form.getInputByName( "EndTime" );
inputEndTime.setValueAttribute( meeting.getToTime() );
HtmlInput inputReason = form.getInputByName( "Title" );
inputReason.type( meeting.getReason() );
List< String > attendeesList = meeting.getAttendees();
if( attendeesList != null && attendeesList.size() > 0 )
{
HtmlSelect attendees = (HtmlSelect)page.getElementById( "AttendeesIds" );
for( String participant : attendeesList )
{
attendees.getOptionByText( participant ).setSelected( true );
}
}
logger.debug( "Page filled, clicking button" );
HtmlPage nextPage = button.click();
String pageUrl = new StringBuilder( "http://" ).append( WEBSITE ).append( SHOW_MY_BOOKINGS ).toString();
if( !nextPage.getBaseURI().equals( pageUrl ) )
{
errorMessages.add( "Room already booked" );
logger.error( errorMessages );
throw new InvalidInputException( errorMessages );
}
// Error check
DomNodeList< DomElement > list = page.getElementsByTagName( "span" );
for( DomElement domElement : list )
{
if( domElement.getAttribute( "class" ).contains( "field-validation-error" ) )
{
errorMessages.add( domElement.getTextContent() );
}
}
if( errorMessages.size() > 0 )
{
logger.error( errorMessages );
throw new InvalidInputException( errorMessages );
}
}
示例8: selectEmailRecoveryAsSignInChallenge
import com.gargoylesoftware.htmlunit.html.HtmlButton; //导入依赖的package包/类
private HtmlPage selectEmailRecoveryAsSignInChallenge(WebClient webClient, HtmlPage signInChallengePage)
throws IOException {
List<HtmlForm> forms = signInChallengePage.getForms();
Optional<HtmlForm> kpeForm = forms.stream()
.filter(form -> "/signin/challenge/kpe/2".equals(form.getActionAttribute())).findFirst();
if (!kpeForm.isPresent()) {
throw new RuntimeException(
"Cannot find recovery by email form in html page :\n" + signInChallengePage.asXml());
}
HtmlButton button = (HtmlButton) kpeForm.get().getElementsByTagName("button").get(0);
HtmlPage htmlPage = button.click();
webClient.waitForBackgroundJavaScriptStartingBefore(WAIT_DELAY_MS);
return htmlPage;
}
示例9: globalConfiguration_shouldSaveConfig
import com.gargoylesoftware.htmlunit.html.HtmlButton; //导入依赖的package包/类
@Test
public void globalConfiguration_shouldSaveConfig() throws IOException, SAXException {
HtmlForm form = jenkins.createWebClient().goTo("configure").getFormByName("config");
form.getInputByName("_.hubImage").setValueAttribute(hubImage);
ArrayList<HtmlElement> elements = (ArrayList<HtmlElement>) form.getHtmlElementsByTagName("button");
HtmlButton button = (HtmlButton) elements.get(elements.size() - 1);
form.submit(button);
assertEquals(hubImage, new TestgridBuildWrapper(new ArrayList<BrowserInstance>(), false).getDescriptor().getHubImage());
}
示例10: testLoseLockSave
import com.gargoylesoftware.htmlunit.html.HtmlButton; //导入依赖的package包/类
public void testLoseLockSave() throws Exception {
HtmlPage pageUser1 = loseLockHelper("save");
// User 1 Save (again)
pageUser1 = (HtmlPage) ((HtmlButton) pageUser1.getByXPath("//button[@name='save']").iterator().next()).click();
// Should be a Save button (content has changed error)
assertEquals(1, pageUser1.getByXPath("//button[@name='save']").size());
// User 1 Save (again)
pageUser1 = (HtmlPage) ((HtmlButton) pageUser1.getByXPath("//button[@name='save']").iterator().next()).click();
// Should NOT be a Save button (allowed user to merge changes)
assertEquals(0, pageUser1.getByXPath("//button[@name='save']").size());
assertTrue(pageUser1.asText().contains(USER1_EDIT_CONTENT));
}
示例11: loseLockHelper
import com.gargoylesoftware.htmlunit.html.HtmlButton; //导入依赖的package包/类
private HtmlPage loseLockHelper(final String buttonName) throws Exception, IOException, JaxenException {
final String name = uniqueWikiPageName("LoseLockPreviewTest");
// User 1 make page
editWikiPage(name, "content", "", "", true);
// User 1 edit
HtmlPage pageUser1 = clickEditLink(getWikiPage(name));
// Set the content to "user1"
((HtmlTextArea) pageUser1.getByXPath("id('contentArea')").iterator().next()).setText(USER1_EDIT_CONTENT);
// User 2 unlock and edit
switchUser();
HtmlPage pageUser2 = getWikiPage(name);
pageUser2 = (HtmlPage) ((HtmlSubmitInput) pageUser2.getByXPath("//input[@value='Unlock']").iterator().next()).click();
pageUser2 = clickEditLink(pageUser2);
// Set the content to "user2"
((HtmlTextArea) pageUser2.getByXPath("id('contentArea')").iterator().next()).setText(USER2_EDIT_CONTENT);
// User 1 Save/Preview
switchUser();
pageUser1 = (HtmlPage) ((HtmlButton) pageUser1.getByXPath("//button[@name='" + buttonName + "']").iterator().next()).click();
// Should be a Save button
assertEquals(1, pageUser1.getByXPath("//button[@name='save']").size());
// Should be a flash with "lock" in the message
assertTrue(getErrorMessage(pageUser1).toLowerCase().contains("lock"));
// Should be a diff
assertTrue(pageUser1.getByXPath("//*[@class='diff']").size() > 0);
// User 2 Save
switchUser();
pageUser2 = (HtmlPage) ((HtmlButton) pageUser2.getByXPath("//button[@name='save']").iterator().next()).click();
// Should NOT be a Save button
assertEquals(0, pageUser2.getByXPath("//button[@name='save']").size());
// Return User 1 page
switchUser();
return pageUser1;
}
示例12: testLeaveCalendarPage
import com.gargoylesoftware.htmlunit.html.HtmlButton; //导入依赖的package包/类
@Test
public void testLeaveCalendarPage() throws Exception {
// get the page and Login
HtmlPage leaveCalendarPage = HtmlUnitUtil
.gotoPageAndLogin(getWebClient(), TkTestConstants.Urls.LEAVE_CALENDAR_URL+"?documentId=" + documentId, true);
Assert.assertNotNull("Leave Request page not found" ,leaveCalendarPage);
//this.setWebClient(leaveCalendarPage.getWebClient());
Assert.assertTrue("Page does not have Current calendar ", leaveCalendarPage.asText().contains("March 2012"));
// Check for next document
HtmlButton nextButton = (HtmlButton) leaveCalendarPage
.getElementById("nav_next_lc");
Assert.assertNotNull(nextButton);
//TODO: click not working. Not even getting to the 'execute' method in LeaveCalendarAction
HtmlPage page = nextButton.click();
Assert.assertNotNull(page);
synchronized (page) {
page.wait(5000);
}
String pageText = page.asText();
LOG.info(pageText);
// Check for previous document
HtmlButton prevButton = (HtmlButton) page
.getElementById("nav_prev_lc");
Assert.assertNotNull(prevButton);
page = prevButton.click();
Assert.assertNotNull(page);
}
示例13: whenQuarantiningTestOnPage
import com.gargoylesoftware.htmlunit.html.HtmlButton; //导入依赖的package包/类
private void whenQuarantiningTestOnPage(HtmlPage page) throws Exception {
((HtmlAnchor) page.getElementById("quarantine")).click();
HtmlForm form = page.getFormByName("quarantine");
HtmlTextArea textArea = (HtmlTextArea) last(form.selectNodes(".//textarea"));
textArea.setText(quarantineText);
form.submit((HtmlButton) last(form.selectNodes(".//button")));
}
示例14: testCreateNewNodeWithGeneratedId
import com.gargoylesoftware.htmlunit.html.HtmlButton; //导入依赖的package包/类
@Test
public void testCreateNewNodeWithGeneratedId() throws IOException {
final HtmlPage page = webClient.getPage(serverAddress);
final HtmlForm form = (HtmlForm)page.getElementById("action_create");
final HtmlSelect type = (HtmlSelect)page.getElementById("new_mixin");
type.getOptionByValue("container").setSelected(true);
final HtmlButton button = form.getFirstByXPath("button");
button.click();
final HtmlPage page1 = javascriptlessWebClient.getPage(serverAddress);
assertTrue("Didn't see new information in page!", !page1.asText().equals(page.asText()));
}
示例15: testSparqlSearch
import com.gargoylesoftware.htmlunit.html.HtmlButton; //导入依赖的package包/类
@Test
@Ignore("htmlunit can't see links in the HTML5 <nav> element..")
public void testSparqlSearch() throws IOException {
final HtmlPage page = webClient.getPage(serverAddress);
logger.error(page.toString());
page.getAnchorByText("Search").click();
final HtmlForm form = (HtmlForm)page.getElementById("action_sparql_select");
final HtmlTextArea q = form.getTextAreaByName("q");
q.setText("SELECT ?subject WHERE { ?subject a <" + REPOSITORY_NAMESPACE + "Resource> }");
final HtmlButton button = form.getFirstByXPath("button");
button.click();
}