Silk Mobile

Table of Contents (Homepage)

CaptureElement

void captureElement(name, x, y, width, height, similarity)

Note: This command is available only from a code environment.

images/images/os-icons/os_ios_150x150.png

images/images/os-icons/os_android_150x150.png

images/images/os-icons/os_windows_150x150.png

images/images/os-icons/os_blackberry_150x150.png

images/images/os-icons/os_symbian02_150x150.png

images/images/os-icons/os_windows_mobile_150x150.png

Description

The command enables you to capture a screenshot of a part of the device’s screen in a given time and create a new element in zone "runtime" that you can use in later steps of your scripts.

Parameters

  • String name: Name that will be given to the captured Element

  • Int X: First point X

  • Int Y: First point Y

  • Width: Width of the captured area

  • Height: Height of the captured area

  • Similarity: Integer number between 80-100. Enables to define the tolerance of changes when searching for the image.

Usage

Designed command for image recognition during runtime.

This can be highly useful when the elements on the screen changes very often or for image comparisons.

Scenario: We will use captureElement command to capture the Calendar icon image during runtime and then click on the icon using this image.

Parameters:

  • name: Will be set to Calendar

  • X: will be set to 275

  • Y: will be set to 255

  • Width: will be set to 264

  • Height: will be set to 299

  • Similarity: will be set to 100

The values of the coordinates were retrieved using the offline tab.

images/download/attachments/3310592/sd.jpg

Once executed, new object is created on zone runtime with the name Calendar.

Which can be used to identify the element in order to operate on it.

We will add a click command to click on the icon

Code:

//package <set your test package>;
import com.experitest.client.*;
import org.junit.*;
/**
*
*
*/
public class captureElement {
private String host = "localhost";
private int port = 8889;
private String projectBaseDirectory = "C:\\Users\\user_12\\workspace\\project2";
protected Client client = null;
@Before
public void setUp(){
client = new Client(host, port, true);
client.setProjectBaseDirectory(projectBaseDirectory);
client.setReporter("xml", "reports", "EriBank");
}
@Test
public void testcaptureElement(){
client.setDevice("adb:Nexus 5");
client.captureElement("Calendar", 275, 255, 264, 299, 100)
client.click("runtime", "Calendar", 0, 1)
}
@After
public void tearDown(){
// Generates a report of the test case.
// For more information - http://supportline.microfocus.com/Documentation/books/ASQ/SilkMobile/90/help/Report+Of+Executed+Test
client.generateReport(false);
// Releases the client so that other clients can approach the agent in the near future.
client.releaseClient();
}
}

Code Examples

Java Example
client.captureElement("Calendar", 275, 255, 264, 299, 100)
client.click("runtime", "Calendar", 0, 1)
C# Example
client.captureElement("Calendar", 275, 255, 264, 299, 100)
client.click("runtime", "Calendar", 0, 1)
Python Example
self.client.captureElement("Calendar", 275, 255, 264, 299, 100)
self.client.click("runtime", "Calendar", 0, 1)