Browser Template

It's common to develop a robotic process to interact with a web page. The types of interactions can vary from quite simple (loading a URL) to more complex (filling out a form). No matter how complicated the task, the robotic process will need to use some basic methods from the Browser module.

To help accelerate your development process, Appian RPA includes a Browser template by default to showcase some basic functionality of the corresponding module. This page describes each part of the Browser template, including line-by-line annotations of what each method does.

When downloading and using this template, it's important to make sure that the selenium driver, server version, and browser version match. Visit the Browser module page to learn more about the required components.

Workflow

browser-robot-workflow.png

The template workflow includes four actions: Start, Open browser, Navigate, and End. The Browser template is relatively straightforward in its functionality – it opens a web browser and navigates to a given URL. You can use this template as a starting point in your robotic processes that go to websites to monitor updates, download data, fill out forms, check for outages, and other common tasks.

If you click the list icon on any action, you'll see it is associated with a method. These methods are in the source code generated from the template. Within the source code, Appian has provided an outline of how you can configure each method.

Source code

The source code contains a class named RobotBrowserTemplate that implements the IRobot interface and is annotated with @Robot. Every Appian RPA robotic process must have the IRobot interface and @Robot annotation to allow the Appian RPA API to identify the class as a robot.

RobotBrowserTemplate includes several methods and attributes. Some of the methods are directly associated with workflow actions; however, the browser template also generates additional methods that are called by the platform to prepare a robotic process or clean up a resource after the process ends.

The class contains the following methods:

Method Description Associated Action
startUp() Always called by the platform prior to the execution of the actions in the workflow. -
start() Provides initial information to the process. Start
openBrowser() Opens the web browser on the resource. Open browser
navigateToWeb() Navigates to a URL in the web browser. Navigate
cleanUp() and browserCleanUp() Always called by the platform after all workflow actions have been executed, regardless of the execution's results, or if any situation causes the robotic process to end. -
end() Provides any final information to the process. End

Attributes

The first few lines in the template's source code reference the attributes and a constant related to the robotic process:

  • HOME_URL (line 22) is a constant that contains the URL the robotic process should open.
  • IJidokaServer (line 25) is responsible for communicating with the Appian RPA Server. The server is what communicates information to the console. This interface also lets the robotic process retrieve information stored in the configuration, such as variables.
  • IClient (line 28) is the interface that enables the robotic process to interact with windows on the resource.
  • IWebBrowserSupport (line 31) is the interface that enables the robotic process to interact with the web browser.
  • browserType (line 34) is a string parameter to define the browser to use. By default, the template uses Chrome, but you can specify the browser here or in the console as a robotic process variable.
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
    /**
	 * URL to navigate to.
	 */
	private static final String HOME_URL = "https://www.appian.com";
	
	/** The JidokaServer instance. */
	private IJidokaServer<?> server;
	
	/** The IClient module. */
	private IClient client;
	
	/** WebBrowser module */
	private IWebBrowserSupport browser;

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

startUp() method

The startUp() method can be used to verify conditions on your resource before executing the actions in your workflow. For example, you can verify if an application is available, determine the screen resolution, or verify that the robotic process can be executed. The startUp() method is also where you can initialize the different instances needed by the robotic process.

If this method is not implemented by the robotic process, the platform will call the default implementation present in the interface IRobot.

Within the source code, you'll see the following declarations:

  • @Override (line 41) tells the platform to ignore the default implementation listed in the IRobot interface and instead use the following implementation.
  • server = JidokaFactory.getServer(); (line 44) initializes IJidokaServer.
  • client = IClient.getInstance(this); (line 46) initializes IClient, where this refers to the class that implements the IRobot interface. From the template, this would be the class RobotBrowserTemplate.
  • browser = IWebBrowserSupport.getInstance(this, client); (line 48) initializes IWebBrowserSupport, where this refers to the class that implements the IRobot interface. It also uses client as a parameter.
  • return IRobot.super.startUp(); (line 50) determines that the robotic process won't run until these conditions are satisfied.
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
    /**
	 * Action "startUp".
	 * 
	 * This method is overridden 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 is used to define the initial actions of the workflow and is associated with the Start action. You could use this method to initialize the browser, but this module contains a method to do that specifically and will be described later.

In this template, the start() method only sets the number of items.

  • setNumberOfItems (line 58) indicates the number of items to process.
54
55
56
57
58
59
60
61
/**
 * 
 * Action "start".
 *
 */
public void start() {
	server.setNumberOfItems(1);
}

openBrowser() method

The openBrowser() method opens the web browser. 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, it will use Chrome.

  • browserType = server.getParameters().get("Browser"); (line 68) communicates with the console to see if Browser has been set as a robotic process variable in the configuration.
  • if (StringUtils.isBlank(browserType)) (line 71-80) is a condition to set Chrome as the default browser if the browserType parameter is left blank. It sends a message to the server in both cases.
  • browser.setTimeoutSeconds(60); (line 83) sets the browser's timeout if it becomes unresponsive. Here, it's set to 60 seconds.
  • browser.initBrowser(); (line 86) initializes the browser module to call other browser methods. When you execute this method, the browser will be open on the resource's screen.
  • if (EBrowsers.INTERNET_EXPLORER.name().equals(browserType)) (lines 89-92) Internet Explorer requires an additional action to click on the center of the screen. This line checks to see if the browser is Internet Explorer, and if so, performs the action.
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
	/**
	 * 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);
			browserType = selectedBrowser.name();
			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 used to make the page visible on the desktop (IExplore issue)
		if (EBrowsers.INTERNET_EXPLORER.name().equals(browserType)) {
			client.clickOnCenter();
			client.pause(3000);
		}

	}

The navigateToWeb() method tells the web browser to go to the URL defined in HOME_URL.

  • server.setCurrentItem(1, HOME_URL); (line 103) tells the server which item is being processed. The first parameter is the item number, and the second parameter is how it's identified in the log.
  • browser.navigate(HOME_URL); (line 106) navigates to the URL contained in the HOME_URL constant.
  • server.sendScreen("Screen after load page: " + HOME_URL); (line 109) takes a screenshot of the resource after the page loads and sends it to the server.
  • server.setCurrentItemResultToOK("Success"); (line 111) send a success message to the server when the page loads successfully.
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/**
	 * 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");
	}

cleanUp() and browserCleanUp() methods

The cleanUp() method is always invoked by the platform when all actions in the workflow have finished their execution, or if the process ended with errors or failed.

The purpose of this method is to leave the resource in the same state it was before the robotic process started its execution. This is where you can add tasks to clean up the resource, like closing an application or logging out.

The cleanUp() method also returns output files that can be downloaded directly from the robotic process execution page. To send files to the server, this method must return an array of strings referring to the local paths of the generated files.

If this method is not implemented by the robotic process, the platform will call the default implementation present in the interface IRobot.

The browserCleanUp() method closes the browser if it's still running. It uses a conditional statement to close the browsers open on the resource.

114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/**
	 * @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
		}

	}

end() method

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

171
172
173
174
175
176
/**
  Action to end the robot.
 */
public void end() {
	server.info("End process");
}
Open in Github

On This Page

FEEDBACK