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
51
52
53
54
55
56
57
58
59
60
61
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_TEST_WEBDRIVER_WEBDRIVER_AUTOMATION_H_
#define CHROME_TEST_WEBDRIVER_WEBDRIVER_AUTOMATION_H_
#include <map>
#include <string>
#include <vector>
#include "base/command_line.h"
#include "base/file_path.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/task.h"
#include "chrome/common/automation_constants.h"
#include "ui/base/keycodes/keyboard_codes.h"
class AutomationProxy;
class ProxyLauncher;
struct WebKeyEvent;
namespace base {
class DictionaryValue;
class ListValue;
}
namespace webdriver {
class Error;
class FramePath;
class Point;
// Creates and controls the Chrome instance.
// This class should be created and accessed on a single thread.
// Note: All member functions are void because they are invoked
// by posting a task from NewRunnableMethod.
class Automation {
public:
struct BrowserOptions {
BrowserOptions();
~BrowserOptions();
// The command line to use for launching the browser. If no program is
// specified, the default browser executable will be used.
CommandLine command;
// The user data directory to be copied and used. If empty, a temporary
// directory will be used.
FilePath user_data_dir;
// The channel ID of an already running browser to connect to. If empty,
// the browser will be launched with an anonymous channel.
std::string channel_id;
// True if the Chrome process should only be terminated if quit is called.
// If false, Chrome will also be terminated if this process is killed or
// shutdown.
bool detach_process;
};
Automation();
virtual ~Automation();
// Start the system's default Chrome binary.
void Init(const BrowserOptions& options, Error** error);
// Terminates this session and disconnects its automation proxy. After
// invoking this method, the Automation can safely be deleted.
void Terminate();
// Executes the given |script| in the specified frame of the current
// tab. |result| will be set to the JSON result. Returns true on success.
void ExecuteScript(int tab_id,
const FramePath& frame_path,
const std::string& script,
std::string* result,
Error** error);
// Sends a webkit key event to the current browser. Waits until the key has
// been processed by the web page.
void SendWebKeyEvent(int tab_id,
const WebKeyEvent& key_event,
Error** error);
// Sends an OS level key event to the current browser. Waits until the key
// has been processed by the browser.
void SendNativeKeyEvent(int tab_id,
ui::KeyboardCode key_code,
int modifiers,
Error** error);
// Drag and drop the file paths to the given location.
void DragAndDropFilePaths(int tab_id,
const Point& location,
const std::vector<FilePath::StringType>& paths,
Error** error);
// Captures a snapshot of the tab to the specified path. The PNG will
// contain the entire page, including what is not in the current view
// on the screen.
void CaptureEntirePageAsPNG(int tab_id, const FilePath& path, Error** error);
void NavigateToURL(int tab_id, const std::string& url, Error** error);
void NavigateToURLAsync(int tab_id, const std::string& url, Error** error);
void GoForward(int tab_id, Error** error);
void GoBack(int tab_id, Error** error);
void Reload(int tab_id, Error** error);
void GetCookies(const std::string& url,
base::ListValue** cookies,
Error** error);
void DeleteCookie(const std::string& url,
const std::string& cookie_name,
Error** error);
void SetCookie(const std::string& url,
base::DictionaryValue* cookie_dict,
Error** error);
void MouseMove(int tab_id, const Point& p, Error** error);
void MouseClick(int tab_id,
const Point& p,
automation::MouseButton button,
Error** error);
void MouseDrag(int tab_id,
const Point& start,
const Point& end,
Error** error);
void MouseButtonDown(int tab_id, const Point& p, Error** error);
void MouseButtonUp(int tab_id, const Point& p, Error** error);
void MouseDoubleClick(int tab_id, const Point& p, Error** error);
// Get persistent IDs for all the tabs currently open. These IDs can be used
// to identify the tab as long as the tab exists.
void GetTabIds(std::vector<int>* tab_ids, Error** error);
// Check if the given tab exists currently.
void DoesTabExist(int tab_id, bool* does_exist, Error** error);
void CloseTab(int tab_id, Error** error);
// Gets the active JavaScript modal dialog's message.
void GetAppModalDialogMessage(std::string* message, Error** error);
// Accepts or dismisses the active JavaScript modal dialog.
void AcceptOrDismissAppModalDialog(bool accept, Error** error);
// Accepts an active prompt JavaScript modal dialog, using the given
// prompt text as the result of the prompt.
void AcceptPromptAppModalDialog(const std::string& prompt_text,
Error** error);
// Gets the version of the runing browser.
void GetBrowserVersion(std::string* version);
// Gets the ChromeDriver automation version supported by the automation
// server.
void GetChromeDriverAutomationVersion(int* version, Error** error);
// Waits for all tabs to stop loading.
void WaitForAllTabsToStopLoading(Error** error);
// Install packed extension.
void InstallExtensionDeprecated(const FilePath& path, Error** error);
// Gets all installed extension IDs.
void GetInstalledExtensions(std::vector<std::string>* extension_ids,
Error** error);
// Install a packed or unpacked extension. If the path ends with '.crx',
// the extension is assumed to be packed.
void InstallExtension(const FilePath& path, std::string* extension_id,
Error** error);
private:
AutomationProxy* automation() const;
Error* GetIndicesForTab(int tab_id, int* browser_index, int* tab_index);
Error* CompareVersion(int client_build_no,
int client_patch_no,
bool* is_newer_or_equal);
Error* CheckVersion(int client_build_no,
int client_patch_no,
const std::string& error_msg);
Error* CheckAlertsSupported();
Error* CheckAdvancedInteractionsSupported();
Error* CheckNewExtensionInterfaceSupported();
scoped_ptr<ProxyLauncher> launcher_;
DISALLOW_COPY_AND_ASSIGN(Automation);
};
} // namespace webdriver
DISABLE_RUNNABLE_METHOD_REFCOUNT(webdriver::Automation);
#endif // CHROME_TEST_WEBDRIVER_WEBDRIVER_AUTOMATION_H_
|