SAPUI5 code samples (Java SDK)

Select an item from a list

This example locates and selects an item in a list box using a property-based description.

@Test
public void verify_listBoxSelectListItemByIndex() throws Exception {
	// Launch the Internet Explorer browser.
	Browser browser = BrowserFactory.launch(BrowserType.INTERNET_EXPLORER);

	try{
		// Navigate to the web site.
		browser.navigate("https://sapui5.netweaver.ondemand.com/sdk/#test-resources/sap/ui/commons/ListBox.html");

		// Identify the list box object.
		ListBox listBox = browser.describe(ListBox.class, new ListBoxDescription.Builder()
			.tagName("DIV").id("lb3").build());
			
		// Select the first item in the list by index.
		listBox.select(1);
			
		// Verify that only one item in the list box is selected.
		Verify.areEqual(1, listBox.getSelectedItems().size(), "Verify_ListBoxSelectListItemByIndex", "Verify that only one item in the list box is selected.");
	}
	catch(Error e){
		Reporter.reportEvent("verify_listBoxSelectListItemByIndex","Failed during test",Status.Failed, e);
		throw e;
	}
	finally{
		browser.close();
	}
}

Back to top

Delete an item from a list

This example deletes an item from a list box using a property-based description.

@Test
public void verify_listBoxFunctionalityForSubType() throws Exception {
	// Launch the Internet Explorer browser
	Browser browser = BrowserFactory.launch(BrowserType.INTERNET_EXPLORER);

	try {
		// Navigate to the web site.
		browser.navigate("https://sapui5.hana.ondemand.com/sdk/test-resources/sap/m/List.html");

		// Navigate to the List box object.				
		browser.describe(ListBox.class, new ListBoxDescription.Builder()
			.tagName("DIV").name("List Overview").build()).select("Standard List Thumb");

		// Make the list box items able to be deleted.        
		browser.describe(Button.class, new ButtonDescription.Builder()
			.tagName("BUTTON").buttonType("submit").name("Delete").build()).click();

		// Identify the list box object.
		ListBox listBox = browser.describe(ListBox.class, new ListBoxDescription.Builder()
			.tagName("DIV").name("Travel [List-Mode: Delete]").build());

		// Delete an item from the list box.
		listBox.getMobile().delete("Travel Settings");
	} catch (Error e) {
		Reporter.reportEvent("verify_listBoxFunctionalityForSubType", "Failed during test", Status.Failed, e);
		throw e;
	} finally {
		browser.close();
	}
}

Back to top

See also: