Browser Robot Template

The Browser robotic process template shows a basic example of how to use the Browser module. The robotic process functionality is only to open a browser and access to a web page. This template is simple by design to help demonstrate how to use each method in the module.

The Browser module is relatively straightforward in its functionality – it opens a web browser and navigates to a given URL. However, you can use this module in your robotic processes that go to websites to monitor updates, download data, fill out forms, check for outages, and other common tasks.

When downloading and using this template, it's important to make sure that the selenium driver, server version, and browser version match.

Workflow

The template workflow includes four actions: Start, Open browser, Navigate, and End.

browser-robot-workflow.png

Implementation

This section explains the RobotBrowserTemplate class that's included in the project. First, declare variables and constants that will be referenced in later code samples.

Declaring variables and constants

For this robotic process, we have defined the following items:

  1. Constant URL we're navigating to:

    1
    2
    3
    4
    
     /**
     * URL to navigate to.
      */
     private static final String HOME_URL = "https://www.appian.com";
    
  2. Appian RPA API objects to be used during the robotic process execution:

    1
    2
    3
    4
    5
    6
    7
    8
    
     /** The JidokaServer instance. */
     private IJidokaServer<?> server;
        	
     /** The IClient module. */
     private IClient client;
        	
     /** WebBrowser module */
     private IWebBrowserSupport browser;
    
  3. The browserType. By default, the template uses Chrome. An activity of this tutorial will be change the Browser.

    1
    2
    
     /** Browser type parameter **/
     private String browserType = null;
    

startUp() method

The startUp() method initializes the Appian RPA modules used in the robotic process.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/**
 * Action "startUp".
 * 
 * This method is override to initialize the Appian RPA modules instances.
 */
@Override
public boolean startUp() throws Exception {
		
	server = (IJidokaServer< ? >) JidokaFactory.getServer();

	client = IClient.getInstance(this);
		
	browser = IWebBrowserSupport.getInstance(this, client);

	return IRobot.super.startUp();

}

start() method

The start() method initializes all applications used in the robotic process. You could initialize the browser, but this module contains a method to do that specifically and will be described in the next action. In this template, this method only sets the number of items.

1
2
3
4
5
6
7
8
/**
 * 
 * Action "start".
 *
 */
public void start() {
	server.setNumberOfItems(1);
}

openBrowser() method

This method starts the Browser module. When you initialize it, you must specify which browser to use. In this case, the robotic process checks the browserType parameter to determine which one. If this parameter is not found, it will use the browser set by default in this case (Google Chrome).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/**
 * Open Web Browser
 * @throws Exception
 */
public void openBrowser() throws Exception  {

	browserType = server.getParameters().get("Browser");
		
	// Select browser type
	if (StringUtils.isBlank(browserType)) {
		server.info("Browser parameter not present. Using the default browser CHROME");
		browser.setBrowserType(EBrowsers.CHROME);
		browserType = EBrowsers.CHROME.name();
	} else {
		EBrowsers selectedBrowser = EBrowsers.valueOf(browserType);
		browser.setBrowserType(selectedBrowser);
		server.info("Browser selected: " + selectedBrowser.name());
	}
	
	// Set timeout to 60 seconds
	browser.setTimeoutSeconds(60);

	// Init the browser module
	browser.initBrowser();

	//This command is uses to make visible in the desktop the page (IExplore issue)
	if (browserType.equals(EBrowsers.INTERNET_EXPLORER)) {
		client.clickOnCenter();
		client.pause(3000);
	}
}

In this method we are navigating to a URL defined in the constant HOME_URL.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/**
 * Navigate to Web Page
 * @throws Exception
 */
public void navigateToWeb() throws Exception  {

	server.setCurrentItem(1, HOME_URL);
		
	// Navigate to HOME_URL address
	browser.navigate(HOME_URL);
	
	// we save the screenshot, it can be viewed in robot execution trace page on the console
	server.sendScreen("Screen after load page: " + HOME_URL);
		
	server.setCurrentItemResultToOK("Success");
}

end() method

The end() method is the last action called in the workflow. In this template, it sends a message to the server that the process is over.

1
2
3
4
5
6
/**
  Action to end the robot.
 */
public void end() {
	server.info("End process");
}

cleanUp() and browserCleanUp() methods

The robotic process ends by closing the browser in the cleanUp method. This method ensures that the browser is always closed, even if there are exceptions. You can do that by invoking the browserCleanUp() method.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/**
 * @see com.novayre.jidoka.client.api.IRobot#cleanUp()
 */
@Override
public String[] cleanUp() throws Exception {
	browserCleanUp();
	return null;
}

/**
 * Close the browser.
 */
private void browserCleanUp() {

	// If the browser was initialized, close it
	if (browser != null) {
		try {
			browser.close();
			browser = null;

		} catch (Exception e) { // NOPMD
		// Ignore exception
		}
	}

	try {
			
		if(browserType != null) {
				
			switch (EBrowsers.valueOf(browserType)) {

			case CHROME:
				client.killAllProcesses("chromedriver.exe", 1000);
				break;
			case INTERNET_EXPLORER:
				client.killAllProcesses("IEDriverServer.exe", 1000);
				break;
			case FIREFOX:
				client.killAllProcesses("geckodriver.exe", 1000);
				break;
			default:
				break;
			}
		}

	} catch (Exception e) { // NOPMD
		// Ignore exception
	}

}
Open in Github

On This Page

FEEDBACK