Mobile code samples

Tap a button on a mobile device

This example shows how to tap a button on an AUT and verify that the required string is displayed in an edit field.

it("Should successfully tap a button on a mobile device application",function(done){
	Mobile.Lab.lockDeviceByName("Nexus 7").then(function (device){
		var app = device.$(Mobile.Application({
		identifier: "com.sample.UICatalog"
		}));

		app.restart().then(function(){
			var table = app.$(Mobile.Table({
				className:"Table",
				resourceId:"list"
			}));
			table.select(14);

			var button = app.$(Mobile.Button({
				className:"Button",
				resourceId:"button1",
				text:"Tap Me"
			}));
			button.tap();

			var editField = app.$(Mobile.EditField({
				className:"Input",
				resourceId:"editText1"
			}));
			expect(editField.text().toEqual("You tapped me"));
		});

		LFT.whenDone(done);
	});
});

Back to top

Perform a search in a WebView

This example shows the use of a WebView using Mobile and Web technologies by accessing the Google search page in a WebView and performing a search.

it("Should perform a search on Google using LeanFT's Mobile WebView",function(done){
	Mobile.Lab.lockDeviceByName("Nexus 7").then(function (device){
		var app = device.$(Mobile.Application({
			identifier: "com.sample.UICatalog"
		}));

		app.restart().then(function(){
			var table = app.$(Mobile.Table({
				className:"Table",
				resourceId:"list"
			}));
			table.select(16);

			// Describe the WebView.
var webView = app.$(Mobile.WebView({ className:"WebView", resourceId:"webview", mobileCenterIndex:0 })); // Describe the page in the WebView.
var webViewPage = webView.$(Web.Page({ })); // Describe the Web EditField of the Google search.
var searchEditField = webViewPage.$(Web.Edit({ type:"search", tagName:"Input", name:"q" })); // Enter some text in the edit field searchEditField.setValue("HP LeanFT"); // Describe the Search Web button.
var searchGoButton = webViewPage.$(Web.Edit({ buttonType:"submit", tagName:"BUTTON", name:"btnG" })); // Perform the search. searchGoButton.click(); }); LFT.whenDone(done); }); });

Back to top

Lock device based on device properties

This example shows how to lock a device based on particular device properties: Android OS and version later than 4.4.0.

It then taps a button on an AUT and verifies that the required string is displayed in an edit field.

It then unlocks the device at the end of the session.

it("Should successfully select a device and lock it using device properties",function(done){
	Mobile.Lab.lockDevice(Mobile.Device({
			osType: "ANDROID",
			osVersion: ">4.4.0"
		})).then(function (device){
		var app = device.$(Mobile.Application({
			identifier: "com.sample.UICatalog"
		}));

		app.restart().then(function(){
			var table = app.$(Mobile.Table({
				className:"Table",
				resourceId:"list"
			}));
			table.select(14);

			var button = app.$(Mobile.Button({
				className:"Button",
				resourceId:"button1",
				text:"Tap Me"
			}));
			button.tap();

			var editField = app.$(Mobile.EditField({
				className:"Input",
				resourceId:"editText1"
			}));
			expect(editField.text().toEqual("You tapped me"));
		});

		LFT.whenDone(done);
	});
});

Back to top

List devices in the Mobile Center lab

This example shows how to list of all the devices in the Mobile Center lab.

it("Should print the name of all the devices in the mobile lab",function(done){
	Mobile.Lab.getDeviceList().then(function (deviceList){
		console.log("Number of devices:" + deviceList.length)
		deviceList.forEach(function(device){
			console.log(device.name);
		});
	});

	LFT.whenDone(done);
});

Back to top

See also: