Skip to content

Latest commit

 

History

History
147 lines (113 loc) · 4.61 KB

README.md

File metadata and controls

147 lines (113 loc) · 4.61 KB

message-web

Browser interaction messages

javadoc

  • ../message Implementations of the Message interface

Usage

After importing the bom:

<dependency>
  <!-- browser interaction message type -->
  <groupId>com.mastercard.test.flow</groupId>
  <artifactId>message-web</artifactId>
</dependency>

Defining a form submission sequence:

/**
 * Builds an interaction to provoke a histogram via the web ui
 *
 * @return A web sequence that visits the web UI's main page and requests a
 *         histogram analysis
 */
public static WebSequence directHistogram() {
	return new WebSequence()
			.set( "web_ui_url", "http://determinedatruntime.com/web" )
			.set( "subject", "" )
			.set( "characters", "" )
			.operation( "populate and submit",
					( driver, params ) -> {
						driver.navigate()
								.to( params.get( "web_ui_url" ) );
						driver.findElement( By.id( "subject_input" ) )
								.sendKeys( params.get( "subject" ) );
						driver.findElement( By.id( "characters_input" ) )
								.sendKeys( params.get( "characters" ) );
						driver.findElement( By.id( "submit_button" ) )
								.click();
					} )
			.masking( RNG, m -> m
					.replace( "web_ui_url", "not asserted" ) );
}

Snippet context

Defining result extraction sequence:

/**
 * Builds an interaction to extract the interesting bits from the web UI's
 * results page
 *
 * @return A web sequence that extracts result fields from the web UI
 */
public static WebSequence results() {
	return new WebSequence()
			.set( "subject", "" )
			.set( "characters", "" )
			.set( "results", "" )
			.set( "page_source", "" )
			.operation( "extract results", ( driver, params ) -> {
				params.put( "subject", driver.findElement( By.id( "subject_output" ) ).getText() );
				params.put( "characters", driver.findElement( By.id( "characters_output" ) ).getText() );
				params.put( "results", driver.findElement( By.id( "results_output" ) ).getText() );
				params.put( "page_source", driver.getPageSource() );
			} )
			.masking( BORING, m -> m
					.replace( "page_source", "not asserted" ) );
}

Snippet context

These message definitions are included in the flow called empty in Web. The parameter maps are updated in the hello flow, like so:

.update( WEB_UI,
		rq( "subject", "Hello web!",
				"characters", "aeiou" ),
		rs( "subject", "Hello web!",
				"characters", "aeiou",
				"results", "  e = 2\n  o = 1" ) )

Snippet context

The messages are processed like so:

if( assrt.expected().request() instanceof WebSequence
		&& assrt.expected().response() instanceof WebSequence ) {
	WebSequence actions = (WebSequence) assrt.expected().request().child();
	actions.set( "web_ui_url",
			"http://localhost:" + clusterManager.getWebUiPort() + "/web" );
	WebDriver driver = Browser.get();
	byte[] actionResults = actions.process( driver );
	assrt.actual().request( actionResults );

	WebSequence results = (WebSequence) assrt.expected().response();
	response = results.process( driver );
}

Snippet context

Note how:

  • The actual URL for the page is populated at runtime on a child() of the request sequence. This means that the runtime-sourced data will be highlighted in the full diff view of the execution report.
  • We're grabbing the full page source in the extracted results, but we're also masking it as not interesting. This allows users to see the page source in the execution report, but doesn't condemn us to exhaustively tracking every non-functional change to the HTML in the test suite.