当前位置: 首页>>代码示例>>Java>>正文


Java WebResponse.getElementWithID方法代码示例

本文整理汇总了Java中com.meterware.httpunit.WebResponse.getElementWithID方法的典型用法代码示例。如果您正苦于以下问题:Java WebResponse.getElementWithID方法的具体用法?Java WebResponse.getElementWithID怎么用?Java WebResponse.getElementWithID使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.meterware.httpunit.WebResponse的用法示例。


在下文中一共展示了WebResponse.getElementWithID方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testDeleteAllSubnets

import com.meterware.httpunit.WebResponse; //导入方法依赖的package包/类
public void testDeleteAllSubnets() throws InstantiationException, IllegalAccessException, 
ClassNotFoundException, SQLException, IOException, SAXException
{
	TestUtils theTestUtils = new TestUtils();		
	WebResponse response = loadUrl (theTestUtils);
	WebForm configurationForm = response.getFormWithID("config");
	
	int numSubnets = Integer.parseInt(configurationForm.getParameterValue("numSubnets"));
	String aux = "?";
	for (int i = 1; i <= numSubnets; i++)
		aux += "delSubnet"+i+"=delSubnet"+i+"&";
	aux +="numSubnets="+numSubnets;			
	WebRequest request = new GetMethodWebRequest(theTestUtils.getUrlPmgraph() + "configure.jsp"+aux);
    response = m_conversation.getResponse(request);
	
	configurationForm = response.getFormWithID("config");
	int newNumSubnets = Integer.parseInt(configurationForm.getParameterValue("numSubnets"));
	assertEquals(numSubnets, newNumSubnets);		
    HTMLElement result = response.getElementWithID("unsuccessResult");
    String resultString = result.getNode().getFirstChild().getNextSibling().getFirstChild().getNodeValue();
    assertTrue(resultString.equals("You can't delete all the subnets"));
}
 
开发者ID:aptivate,项目名称:pmgraph,代码行数:23,代码来源:TestMultiSubnets.java

示例2: testLegendPortView

import com.meterware.httpunit.WebResponse; //导入方法依赖的package包/类
public void testLegendPortView() throws Exception
{
	// port graph		
	WebRequest request = new GetMethodWebRequest(
			m_testUtils.getUrlPmgraph()
					+ "index.jsp?report=totals&start=0&end=300000&resultLimit=15&view=LOCAL_PORT");
	WebResponse response = m_conversation.getResponse(request);

	// Get the table data from the page
	WebTable table = (WebTable) response
			.getElementWithID(TestUtils.LEGEND_TBL);
	
	long[] downloaded = { 9750, 1687, 4125, 562};
	long[] uploaded = { 6000, 9375, 6750, 0};

	
	/* The values for upload and download shown on the screen and tested for above have 
	 been truncated so using these values to calculate the average does not work
	 (is 9 really 9.3 or 9.6 when used in the calculation ?).  So for the purposes of having 
	 a test that checks against future changes, the expected values have been set to match the actual 
	 values we get when the test is run
	*/
	
	long[] averageDownloaded= { 260, 45, 110 ,15};
	long[] averageUploaded = { 160, 250, 180, 0};

	String ports[] = { "110",  "80", "443", "443"};
	String portName[] = { "pop3", "http", "https", "https"};
	String services[] = {"tcp", "tcp", "tcp", "udp"};
	checkUploadDownloadLegendTable(table, downloaded, uploaded, ports,portName, services, averageDownloaded, averageUploaded);		
}
 
开发者ID:aptivate,项目名称:pmgraph,代码行数:32,代码来源:LegendTestPortView.java

示例3: testLimitResults

import com.meterware.httpunit.WebResponse; //导入方法依赖的package包/类
/**
 * Check if the limit results works when the view is a port view.
 * 
 * @throws ClassNotFoundException
 * @throws IllegalAccessException
 * @throws InstantiationException
 * @throws IOException
 * @throws SQLException
 * @throws SAXException
 */
public void testLimitResults() throws ClassNotFoundException,
		IllegalAccessException, InstantiationException, IOException,
		SQLException, SAXException
{		
	// Obtain the upload page on web site
	WebRequest request = new GetMethodWebRequest(
			m_testUtils.getUrlPmgraph()
					+ "index.jsp?report=totals&start=0&end=300000&resultLimit=1&view=LOCAL_PORT");
	WebResponse response = m_conversation.getResponse(request);

	WebTable table = (WebTable) response
			.getElementWithID(TestUtils.LEGEND_TBL);
	long uploaded[] = { 6000, 16125 };
	long downloaded[] = { 9750, 6375 };
	String ports[] = { "110", "Others" };
	String portName[] = {"pop3", "" };
	String services[] = {"tcp", ""};
	
	/* The values for upload and download shown on the screen and tested for above have 
	 been truncated so using these values to calculate the average does not work
	 (is 9 really 9.3 or 9.6 when used in the calculation ?).  So for the purposes of having 
	 a test that checks against future changes, the expected values have been set to match the actual 
	 values we get when the test is run
	*/
	
	long averageDownloaded[] = {260, 170};
	long averageUploaded[] = {160, 430};

	checkUploadDownloadLegendTable(table, downloaded, uploaded, ports, portName, services, averageDownloaded, averageUploaded);
}
 
开发者ID:aptivate,项目名称:pmgraph,代码行数:41,代码来源:LegendTestPortView.java

示例4: testCheckDataTranslationAndRepresentation

import com.meterware.httpunit.WebResponse; //导入方法依赖的package包/类
public void testCheckDataTranslationAndRepresentation() throws Exception
{
	TestUtils testUtils = new TestUtils();
	testUtils.CreateTable();

	// Insert rows into table
	for (int i = 0; i < 100; i++)
	{
		// Set the values
		testUtils.insertNewRow(250000, new Timestamp((timeInMinutes - 5) * 60000),
				"224.0.0.255", "10.0.156.10", false);
		testUtils.insertNewRow(500000, new Timestamp((timeInMinutes - 5) * 60000),
				"10.0.156.10", "224.0.0.255", false);

		testUtils.insertNewRow(200000, new Timestamp((timeInMinutes - 5) * 60000),
				"224.0.0.251", "10.0.156.1", false);
		testUtils.insertNewRow(100000, new Timestamp((timeInMinutes - 5) * 60000),
				"10.0.156.1", "224.0.0.251", false);

		testUtils.insertNewRow(250000, new Timestamp((timeInMinutes - 5) * 60000),
				"10.0.156.110", "10.0.156.120", false);
		testUtils.insertNewRow(500000, new Timestamp((timeInMinutes - 5) * 60000),
				"10.0.156.120", "10.0.156.110", false);
	}

	// Open a graph page

	// Obtain the upload page on the website
	WebRequest request = new GetMethodWebRequest(testUtils.getUrlPmgraph());
	WebResponse response = m_conversation.getResponse(request);

	// Get the table data from the page
	WebTable table = (WebTable) response.getElementWithID(TestUtils.LEGEND_TBL);

	long uploaded[] = { 47, 9 };
	long downloaded[] = { 23, 19 };
	String ips[] = { "10.0.156.10", "10.0.156.1" };
	checkUploadDownloadLegendTable(table, downloaded, uploaded, ips, View.LOCAL_IP);
}
 
开发者ID:aptivate,项目名称:pmgraph,代码行数:40,代码来源:LegendTest.java

示例5: testLimitResultsSpecificPort

import com.meterware.httpunit.WebResponse; //导入方法依赖的package包/类
/**
 * test the case where you have limit=1 when you are looking into a specific
 * port
 * 
 * @throws ClassNotFoundException
 * @throws IllegalAccessException
 * @throws InstantiationException
 * @throws IOException
 * @throws SQLException
 * @throws SAXException
 */
public void testLimitResultsSpecificPort() throws ClassNotFoundException,
		IllegalAccessException, InstantiationException, IOException, SQLException, SAXException
{		
	// Obtain the upload page on web site
	WebRequest request = new GetMethodWebRequest(m_testUtils.getUrlPmgraph()
			+ "index.jsp?report=totals&start=0&end=300000&resultLimit=1&port=110");
	WebResponse response = m_conversation.getResponse(request);

	WebTable table = (WebTable) response.getElementWithID(TestUtils.LEGEND_TBL);
	long uploaded[] = { 4, 0 };
	long downloaded[] = { 5, 4 };
	String ips[] = { "10.0.156.110", "Others" };
	checkUploadDownloadLegendTable(table, downloaded, uploaded, ips, View.LOCAL_PORT);
}
 
开发者ID:aptivate,项目名称:pmgraph,代码行数:26,代码来源:LegendTest.java

示例6: testTrimAttributeFalse

import com.meterware.httpunit.WebResponse; //导入方法依赖的package包/类
public void testTrimAttributeFalse () throws Exception {
  
  WebResponse resp = wc.getResponse(webedTestLocation
      + "/test/FieldTag/testTrimAttributeFalse.jsp");
  String original = wc.getResponse(webedTestLocation
      + "/test/FieldTag/value.txt").getText();

  HTMLElement field = resp.getElementWithID("FLD");
  WebForm form = resp.getForms()[0];
  String value = form.getParameterValue(field.getName());

  // Trimming should not be carried out
  assertEquals("Trimming occurred", original, value);

}
 
开发者ID:ontopia,项目名称:ontopia,代码行数:16,代码来源:FieldTagTest.java

示例7: getFieldValue

import com.meterware.httpunit.WebResponse; //导入方法依赖的package包/类
/**
 * Check the contents of a given input field.
 * @param fieldID The ID of the field.
 * @throws SAXException
 */
protected String getFieldValue(String fieldID, WebResponse response)
    throws SAXException {
  HTMLElement field = response.getElementWithID(fieldID);
  assertNotNull(field);
  WebForm forms[] = response.getForms();
  assertTrue(forms.length > 0);
  WebForm form = forms[1];
  return form.getParameterValue(field.getName());
}
 
开发者ID:ontopia,项目名称:ontopia,代码行数:15,代码来源:FieldTagTest.java

示例8: changeField

import com.meterware.httpunit.WebResponse; //导入方法依赖的package包/类
/**
 * Change the contents of a given input field.
 * @param fieldID The ID of the field.
 * @param newValue The new value to put in the input field.
 * @throws SAXException
 */
protected void changeField(String fieldID, String newValue, 
    WebResponse response)
    throws SAXException {
  HTMLElement field = response.getElementWithID(fieldID);
  assertNotNull(field);
  WebForm forms[] = response.getForms();
  assertTrue(forms.length > 0);
  WebForm form = forms[1];
  form.setParameter(field.getName(), newValue);
}
 
开发者ID:ontopia,项目名称:ontopia,代码行数:17,代码来源:FieldTagTest.java

示例9: testFormatSubnetZeros

import com.meterware.httpunit.WebResponse; //导入方法依赖的package包/类
public void testFormatSubnetZeros() throws InstantiationException, IllegalAccessException, 
ClassNotFoundException, SQLException, IOException, SAXException
{	
	TestUtils theTestUtils = new TestUtils();		
	WebResponse response = loadUrl (theTestUtils);
	WebForm configurationForm = response.getFormWithID("config");
	WebTable table = response.getTableWithID("TableLocalSubnets");
	int oldNumSubnets = table.getRowCount() - SIZE_HEADS;
	String newSubnet = "99.99.99.";		
	configurationForm.setParameter("newSubnet", newSubnet);
	configurationForm.submit();		
	String newSubnet2 = "000.015.255.";
	configurationForm.setParameter("newSubnet", newSubnet2);
	response = configurationForm.submit();
	HTMLElement result = response.getElementWithID("unsuccessResult");
    String resultString =  result.getNode().getFirstChild().getNextSibling().getFirstChild().getNodeValue();
    assertEquals("Incorrect new subnet format. Please try again as follows: 0-255.0-255.0-255.", resultString);
    
	theTestUtils = new TestUtils();
	response = loadUrl (theTestUtils);
	table = response.getTableWithID("TableLocalSubnets");
	int numSubnets = table.getRowCount() - SIZE_HEADS;
	assertTrue(numSubnets > oldNumSubnets);
    	assertEquals(newSubnet, table.getCellAsText((numSubnets),0));
    	//assertEquals(table., "0.15.255.");
    	
    	WebRequest request = new GetMethodWebRequest(theTestUtils.getUrlPmgraph() + "configure.jsp?newSubnet=099.099.099.&numSubnets="+numSubnets);
    response = m_conversation.getResponse(request);
    result = response.getElementWithID("unsuccessResult");
    resultString =  result.getNode().getFirstChild().getNextSibling().getFirstChild().getNodeValue();
    assertEquals("Incorrect new subnet format. Please try again as follows: 0-255.0-255.0-255.", resultString);
	
    response = loadUrl (theTestUtils);
    	configurationForm = response.getFormWithID("config");
    FormControl aux = configurationForm.getControlWithID("delSubnet"+numSubnets);
	aux.toggle();
	configurationForm.submit();	
	
	response = loadUrl (theTestUtils);
	table = response.getTableWithID("TableLocalSubnets");
	numSubnets = table.getRowCount() - SIZE_HEADS;
	assertEquals(oldNumSubnets, numSubnets);
}
 
开发者ID:aptivate,项目名称:pmgraph,代码行数:44,代码来源:TestMultiSubnets.java

示例10: testColourGraphAndLegend

import com.meterware.httpunit.WebResponse; //导入方法依赖的package包/类
public void testColourGraphAndLegend() throws Exception
{
	// Open a graph page and get the tab
	// Obtain the upload page on the website
	WebRequest request = new GetMethodWebRequest(m_testUtil.getUrlPmgraph()
			+ "?start=0&end=300000");
	WebResponse response = m_conversation.getResponse(request);
	// Get the table data from the page
	WebTable legend = (WebTable) response.getElementWithID(TestUtils.LEGEND_TBL);
	
	// Get the data from the chart. We use the renderer object to get the colour.
	JFreeChart chart;
	GraphFactory graphFactory = new GraphFactory();		
	RequestParams requestParams = new RequestParams(0, 300000, View.LOCAL_IP, 5);
	chart = graphFactory.stackedThroughputGraph(requestParams);
	XYPlot plot = (XYPlot) chart.getPlot();
	XYItemRenderer renderer = plot.getRenderer();

	// The two first rows are for the header
	for (int i = 2; i < legend.getRowCount() - 1; i++)
	{
		// Get the first cell of each row in html format and get the style
		// attribute which is the one used to define the colour in the
		// legend
		TableCell colourLegend = legend.getTableCell(i, 0);
		String legendStyle = colourLegend.getAttribute("style");
		
		// Go through the legendStyle string and extract the colour substring which starts with #
		String colourHex = null;
		for (int n = 0; n < legendStyle.length(); n++)
		{
			if (legendStyle.charAt(n) == '#')
			{
				colourHex = legendStyle.substring(n, n + 7);
			}
		}
		// Now we can compare the Graph Colour to the Legend Colour
		//
		// Get the colour for each graph series in RGB format, and 
		// convert it to hexadecimal format in the assertEquals
		Color graphColour = (Color) renderer.getSeriesPaint(i - 2);
		assertEquals("Colour check", "#"
				+ Integer.toHexString(graphColour.getRGB() & 0x00ffffff), colourHex);
	}
}
 
开发者ID:aptivate,项目名称:pmgraph,代码行数:46,代码来源:ColourTest.java

示例11: testCheckDataTranslationAndRepresentation

import com.meterware.httpunit.WebResponse; //导入方法依赖的package包/类
public void testCheckDataTranslationAndRepresentation() throws Exception
{
	TestUtils testUtils = new TestUtils();
	testUtils.CreateTable();

	// Insert rows into table
	for (int i = 0; i < 100; i++)
	{
		// Set the values
		testUtils.insertNewRow(250000, new Timestamp((timeInMinutes - 5) * 60000),
				"224.0.0.255", "10.0.156.10", false);
		testUtils.insertNewRow(500000, new Timestamp((timeInMinutes - 5) * 60000),
				"10.0.156.10", "224.0.0.255", false);

		testUtils.insertNewRow(200000, new Timestamp((timeInMinutes - 5) * 60000),
				"224.0.0.251", "10.0.156.1", false);
		testUtils.insertNewRow(100000, new Timestamp((timeInMinutes - 5) * 60000),
				"10.0.156.1", "224.0.0.251", false);			
		
		testUtils.insertNewRow(200000, new Timestamp((timeInMinutes - 5) * 60000),
				"224.0.0.251", "10.0.223.15", false);
		testUtils.insertNewRow(100000, new Timestamp((timeInMinutes - 5) * 60000),
				"10.0.223.15", "224.0.0.251", false);	
		
		testUtils.insertNewRow(200000, new Timestamp((timeInMinutes - 5) * 60000),
				"224.0.0.255", "10.1.223.8", false);
		testUtils.insertNewRow(100000, new Timestamp((timeInMinutes - 5) * 60000),
				"10.1.223.8", "224.0.0.255", false);	
	}		

	// Obtain the upload page on the website
	WebRequest request = new GetMethodWebRequest(testUtils.getUrlPmgraph());
	WebResponse response = m_conversation.getResponse(request);
	
	// Get the table data from the page
	WebTable table = (WebTable) response.getElementWithID(TestUtils.LEGEND_TBL);

	long uploaded[] = { 47, 9 };
	long downloaded[] = { 23, 19 };
	String ips[] = { "10.0.156.10", "10.0.156.1" };
	checkUploadDownloadLegendTable(table, downloaded, uploaded, ips, View.LOCAL_IP);
}
 
开发者ID:aptivate,项目名称:pmgraph,代码行数:43,代码来源:TestMultiSubnetsLegend.java

示例12: testHostName

import com.meterware.httpunit.WebResponse; //导入方法依赖的package包/类
/**
 * Test hostname for different IPs
 * 
 * @throws ClassNotFoundException
 * @throws IllegalAccessException
 * @throws InstantiationException
 * @throws IOException
 * @throws SQLException
 * @throws SAXException
 */

public void testHostName() throws ClassNotFoundException, IllegalAccessException,
		InstantiationException, IOException, SQLException, SAXException
{
	TestUtils testUtils = new TestUtils();
	testUtils.CreateTable();
	// Insert rows into table
	for (int i = 0; i < 100; i++)
	{
		// Set the values
		testUtils.insertNewRow(500000, testUtils.t1, "224.0.0.255", "10.0.156.10", false);
		testUtils.insertNewRow(300000, testUtils.t1, "10.0.156.10", "224.0.0.254", false);

		testUtils.insertNewRow(100000, testUtils.t1, "224.0.0.251", "10.0.156.22", false);
		testUtils.insertNewRow(150000, testUtils.t2, "10.0.156.22", "224.0.0.251", false);

		testUtils.insertNewRow(400000, testUtils.t2, "224.0.0.255", "10.0.156.33", false);
		testUtils.insertNewRow(1140000, testUtils.t2, "10.0.156.33", "224.0.0.255", false);
	}

	String hostname1 = "fen-ndiyo3.fen.aptivate.org.";
	String hostname2 = "ap.int.aidworld.org.";
	String hostname3 = "Unknown Host";
	// Open a graph page

	// Obtain the upload page on web site
	WebRequest request = new GetMethodWebRequest(testUtils.getUrlPmgraph()
			+ "index.jsp?report=totals&start=0&end=300000&resultLimit=15");
	WebResponse response = m_conversation.getResponse(request);

	// get the table
	WebTable table = (WebTable) response.getElementWithID(TestUtils.LEGEND_TBL);

	if (table != null)
	{
		// Row 2
		String hostN1 = table.getCellAsText(2, 2);
		assertEquals("Check the host name", hostname1, hostN1);
		// Row 3
		String hostN2 = table.getCellAsText(3, 2);
		assertEquals("Check the host name", hostname2, hostN2);
		// Row 4
		String hostN3 = table.getCellAsText(4, 2);
		assertEquals("Check the host name", hostname3, hostN3);
	}
}
 
开发者ID:aptivate,项目名称:pmgraph,代码行数:57,代码来源:LegendTest.java

示例13: testUnitsThroughput

import com.meterware.httpunit.WebResponse; //导入方法依赖的package包/类
public void testUnitsThroughput() throws IOException, SAXException, InstantiationException,
		IllegalAccessException, ClassNotFoundException, SQLException, ConfigurationException
{
	// Time periods to check, in minutes.
	long timePeriod[] = { 8, 250, 15500 };

	for (int i = 0; i < timePeriod.length; i++)
	{
		LegendData data = new LegendData();
		RequestParams requestParams = new RequestParams(0, timePeriod[i] * 60000,
				View.LOCAL_IP, 5);
		Hashtable<Integer,List<DataPoint>> resultsHash = data.getLegendData(requestParams.getSortBy(),
						requestParams.getOrder(), requestParams, false);
		String addUrl = "?start=0&end=" + (timePeriod[i] * 60000);			
		// Obtain the upload page on web site
		WebRequest request = new GetMethodWebRequest(m_testUtils.getUrlPmgraph() + addUrl);
		WebResponse response = m_conversation.getResponse(request);

		WebTable legend = (WebTable) response.getElementWithID(TestUtils.LEGEND_TBL);
		
		//Check if the legend units matches the period of time
		String totalThroughput = legend.getCellAsText(0, 3);
		String expectedLabel = null;
		if (timePeriod[i] < 10)
		{
			expectedLabel = "Totals (KB)";
		}
		else
		{
			if ((timePeriod[i] >= 10) && (timePeriod[i] < 14400))
			{
				expectedLabel ="Totals (MB)";
			}
			else
			{
				expectedLabel = "Totals (GB)";
			}
		}
		
		assertEquals("Check if the header in the legend matches the units we are using",
				totalThroughput, expectedLabel);
		
		//Check the values shown are correct
		long bitsToDivideBy;
		for (int j = 2; j < legend.getRowCount() - 1; j++)
		{
			// KB
			if (timePeriod[i] < 10)
				bitsToDivideBy = 1024;
			else{
				// MB
				if ((timePeriod[i] >= 10) && (timePeriod[i] < 14400))
					bitsToDivideBy = 1024*1024;
				// GB
				else
					bitsToDivideBy = 1024*1024*1024;
			}
			for (Enumeration e = resultsHash.keys (); e.hasMoreElements ();) 
			{
				int key = (Integer) e.nextElement();
				List<DataPoint> throughput = resultsHash.get(key);
				
				String databaseValueDown = String.valueOf(throughput.get(j-2).getDownloaded()/bitsToDivideBy);
				//if the result is zero change it for "<1" as in the legend
				if (databaseValueDown.equals("0"))
					databaseValueDown = "<1";
				String databaseValueUp = String.valueOf(throughput.get(j-2).getUploaded()/bitsToDivideBy);
				if (databaseValueUp.equals("0"))
					databaseValueUp = "<1";
				assertEquals(
					"Check if the downloaded throughput in the legend matches the units we are using",
						legend.getCellAsText(j, 3), databaseValueDown);
				assertEquals(
					"Check if the uploaded throughput in the legend matches the units we are using",
						legend.getCellAsText(j, 4), databaseValueUp );
			}
		}
	}
}
 
开发者ID:aptivate,项目名称:pmgraph,代码行数:80,代码来源:LegendTest.java


注:本文中的com.meterware.httpunit.WebResponse.getElementWithID方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。