SAP GUI code samples (JavaScript SDK)

Opening for SAP GUI test script

This example shows the opening for a SAP GUI test script.

var LFT = require("leanft");
var expect = require("leanft/expect");
var SAPGUI = LFT.SAPGUI;

var session;

jasmine.DEFAULT_TIMEOUT_INTERVAL = 120000;

describe("SAP GUI examples",function(){
	beforeAll(function(done){
		LFT.init();
		LFT.whenDone(done);
	});

	beforeEach(function(done){
		LFT.beforeTest();

		SAPGUI.GuiSessionFactory.launch("ECC 6.0", "800", "qa01", "55c1b303f6a77cb79fcbb321af78eed77befc906")
			.then(function(launched_session){
				session = launched_session;
			});

		LFT.whenDone(done);
	});

Back to top

Launch SAP GUI session instance and run transactions

This example shows how to use GuiSession and GuiSessionFactory to launch a SAP GUI session instance and run transactions.

it("GUISession and GUISessionFactory example", function (done) {
	// Enter a transaction code and verify that it runs successfully.
	session.reset("sbwp");
	expect(session.activeWindow()).toEqual("Business Workplace of QA01");

	// Enter another transaction code and verify that it runs successfully.
	// Unlike OKCode.setValue(code), you can use the Reset method at any point.
	session.reset("dwdm");
	expect(session.activeWindow()).toEqual("Enjoy Demo Center: Display");

	// Return to the initial session window and verify that the correct window opens.
	session.reset();
	expect(session.activeWindow()).toEqual("SAP Easy Access");

	LFT.whenDone(done);
});

Back to top

OKCode and Window objects for running transaction

This example shows how to use OKCode and Window objects to run a transaction.

it("OKCode example", function (done) {
	// Describe the parent window and OKCode objects.
	var window = session.$(SAPGUI.Window({
		transaction:"SESSION_MANAGER",
		program:"SAPLSMTR_NAVIGATION",
		type:SAPGUI.ComponentType.mainWindow,
		name:"wnd[0]"
	}));

	var okCode = window.$(SAPGUI.OKCode({type:SAPGUI.ComponentType.okCodeField}));

	// Enter the transaction code in the OKCode field.
	okCode.setValue("sbwp");

	// Commit the transaction by pressing the Enter key.
	window.sendKey(SAPGUI.SapFunctionKey.enter);

	// Verify navigation to the correct session window.
	expect(session.activeWindow()).toEqual("Business Workplace of QA01");

	LFT.whenDone(done);
});
		

Back to top

Activate item in tree node to navigate to table object, then set data for table cells

This example shows how to use treeView, treeViewNode, table, tableCell and their respective methods to activate an item in the tree node to navigate to a table object, and then set data for the table cells.

it("TreeView and Table example", function (done) {
	// Navigate to the session window where the tree view control resides.
	session.reset("dwdm");

	// Describe the tree view object.
	var treeView = session.$(SAPGUI.Window({
		transaction:"DWDM",
		program:"SAPMSDM1",
		type:SAPGUI.ComponentType.mainWindow,
		name:"wnd[0]"
	})).$(SAPGUI.TreeView({
		type:SAPGUI.ComponentType.ctrlTree,
		name:"shell"
	}));

	// Build the path to the node.
	var nodePath = treeView.buildNodePath("Workbench Demos", "Interface Elements", "Table Control");

	// Get the node object.
	var treeViewNode = treeView.getNode(nodePath);

	// Activate the specific item in the node to navigate to the table object.
	treeViewNode.activateItem("Table Control");

	// Describe the table without its parent window.
	var table = session.$(SAPGUI.Table({
		type:SAPGUI.ComponentType.tableControl,
		name:"RSDEMO_TABLE_CONTROLTABLE_CONTROL"
	}));

	// Verify the value of a table cell.
	expect(table.cells(0,0).value()).toEqual("American Airlines");

	// Set the value of the table cell.
	table.cells(0,0).setValue("Lauda Air");

	// Verify the table cell value.
	expect(table.cells(0,0).value()).toEqual("Lauda Air");

	LFT.whenDone(done);
});

Back to top

Set value for SAP GUI edit box

This example shows how to use editField to set a value for a SAP GUI edit box.

it("EditField example", function (done) {
	// Run a transaction to navigate to the edit box.
	session.reset("bibs");

	// Describe the edit box.
	var editField = session.$(SAPGUI.Edit({
		type:SAPGUI.ComponentType.textField,
		name:"F1"
	}));

	// Set text for the edit box.
	editField.setText("No #99");

	// Verify the text.
	expect( editField.text()).toEqual("No #99");

	LFT.whenDone(done);
});

Back to top

Select item in combo box

This example shows how to select an item in a combo box.

it("ComboBox example", function (done) {
	// Run a transaction and select a menu bar item that navigates to the combo box.
	session.reset("bibs");

	session.$(SAPGUI.Menubar({type:SAPGUI.ComponentType.menubar})).select("Goto;Elements;Dropdown List");

	// Describe the combo box.
	var comboBox = session.$(SAPGUI.ComboBox({
		type:SAPGUI.ComponentType.comboBox,
		name:"SCARR-CARRID"
	}));

	comboBox.items().then(function (items) {
		expect(items.length).toEqual(19);
	});

	// Make a selection.
	comboBox.select(3);

	// Verify the selection.
	comboBox.selectedItem().then(function (selectedItem) {
		expect(selectedItem.text()).toEqual("Air France");
		expect(selectedItem.key()).toEqual("AF");
	});

	LFT.whenDone(done);
});

Back to top

See also: