Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Side by Side Diff: chrome/test/webdriver/server.cc

Issue 3643002: Implemnts the commands in webdriver to preform searching of elements on a page. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: fix for windows build Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <signal.h> 5 #include <signal.h>
6 #include <stdlib.h> 6 #include <stdlib.h>
7 #ifndef _WIN32 7 #ifndef _WIN32
8 #include <sys/time.h> 8 #include <sys/time.h>
9 #include <sys/types.h> 9 #include <sys/types.h>
10 #include <sys/wait.h> 10 #include <sys/wait.h>
11 #else 11 #else
12 #include <time.h> 12 #include <time.h>
13 #endif 13 #endif
14 #include <iostream> 14 #include <iostream>
15 #include <fstream> 15 #include <fstream>
16 16
17 #include "base/at_exit.h" 17 #include "base/at_exit.h"
18 #include "base/command_line.h" 18 #include "base/command_line.h"
19 #include "base/logging.h" 19 #include "base/logging.h"
20 #include "base/scoped_ptr.h" 20 #include "base/scoped_ptr.h"
21 #include "base/string_util.h" 21 #include "base/string_util.h"
22 #include "base/utf_string_conversions.h" 22 #include "base/utf_string_conversions.h"
23 23
24 #include "chrome/test/webdriver/dispatch.h" 24 #include "chrome/test/webdriver/dispatch.h"
25 #include "chrome/test/webdriver/session_manager.h" 25 #include "chrome/test/webdriver/session_manager.h"
26 #include "chrome/test/webdriver/utility_functions.h" 26 #include "chrome/test/webdriver/utility_functions.h"
27 #include "chrome/test/webdriver/commands/create_session.h" 27 #include "chrome/test/webdriver/commands/create_session.h"
28 #include "chrome/test/webdriver/commands/execute_command.h" 28 #include "chrome/test/webdriver/commands/execute_command.h"
29 #include "chrome/test/webdriver/commands/find_element_commands.h"
30 #include "chrome/test/webdriver/commands/implicit_wait_command.h"
29 #include "chrome/test/webdriver/commands/navigate_commands.h" 31 #include "chrome/test/webdriver/commands/navigate_commands.h"
30 #include "chrome/test/webdriver/commands/session_with_id.h" 32 #include "chrome/test/webdriver/commands/session_with_id.h"
31 #include "chrome/test/webdriver/commands/source_command.h" 33 #include "chrome/test/webdriver/commands/source_command.h"
32 #include "chrome/test/webdriver/commands/speed_command.h" 34 #include "chrome/test/webdriver/commands/speed_command.h"
33 #include "chrome/test/webdriver/commands/title_command.h" 35 #include "chrome/test/webdriver/commands/title_command.h"
34 #include "chrome/test/webdriver/commands/url_command.h" 36 #include "chrome/test/webdriver/commands/url_command.h"
35 37
36 #include "third_party/mongoose/mongoose.h" 38 #include "third_party/mongoose/mongoose.h"
37 39
38 // Make sure we have ho zombies from CGIs. 40 // Make sure we have ho zombies from CGIs.
(...skipping 22 matching lines...) Expand all
61 SetCallback<CreateSession>(ctx, "/session"); 63 SetCallback<CreateSession>(ctx, "/session");
62 SetCallback<BackCommand>(ctx, "/session/*/back"); 64 SetCallback<BackCommand>(ctx, "/session/*/back");
63 SetCallback<ExecuteCommand>(ctx, "/session/*/execute"); 65 SetCallback<ExecuteCommand>(ctx, "/session/*/execute");
64 SetCallback<ForwardCommand>(ctx, "/session/*/forward"); 66 SetCallback<ForwardCommand>(ctx, "/session/*/forward");
65 SetCallback<RefreshCommand>(ctx, "/session/*/refresh"); 67 SetCallback<RefreshCommand>(ctx, "/session/*/refresh");
66 SetCallback<SourceCommand>(ctx, "/session/*/source"); 68 SetCallback<SourceCommand>(ctx, "/session/*/source");
67 SetCallback<TitleCommand>(ctx, "/session/*/title"); 69 SetCallback<TitleCommand>(ctx, "/session/*/title");
68 SetCallback<URLCommand>(ctx, "/session/*/url"); 70 SetCallback<URLCommand>(ctx, "/session/*/url");
69 SetCallback<SpeedCommand>(ctx, "/session/*/speed"); 71 SetCallback<SpeedCommand>(ctx, "/session/*/speed");
70 72
73 // WebElement commands
74 SetCallback<ImplicitWaitCommand>(ctx, "/session/*/timeouts/implicit_wait");
75 SetCallback<FindOneElementCommand>(ctx, "/session/*/element");
76 SetCallback<FindManyElementsCommand>(ctx, "/session/*/elements");
77 SetCallback<FindOneElementCommand>(ctx, "/session/*/element/*/element");
78 SetCallback<FindManyElementsCommand>(ctx, "/session/*/elements/*/elements");
79
71 // Since the /session/* is a wild card that would match the above URIs, this 80 // Since the /session/* is a wild card that would match the above URIs, this
72 // line MUST be the last registered URI with the server. 81 // line MUST be the last registered URI with the server.
73 SetCallback<SessionWithID>(ctx, "/session/*"); 82 SetCallback<SessionWithID>(ctx, "/session/*");
74 } 83 }
75 } // namespace webdriver 84 } // namespace webdriver
76 85
77 // Sets up and runs the Mongoose HTTP server for the JSON over HTTP 86 // Sets up and runs the Mongoose HTTP server for the JSON over HTTP
78 // protcol of webdriver. The spec is located at: 87 // protcol of webdriver. The spec is located at:
79 // http://code.google.com/p/selenium/wiki/JsonWireProtocol. 88 // http://code.google.com/p/selenium/wiki/JsonWireProtocol.
80 int main(int argc, char *argv[]) { 89 int main(int argc, char *argv[]) {
81 struct mg_context *ctx; 90 struct mg_context *ctx;
82 base::AtExitManager exit; 91 base::AtExitManager exit;
83 std::string port = "8080"; 92 std::string port = "9515";
84 #ifdef OS_POSIX 93 #ifdef OS_POSIX
85 CommandLine cmd_line = CommandLine(argc, argv); 94 CommandLine cmd_line = CommandLine(argc, argv);
86 #elif OS_WIN 95 #elif OS_WIN
87 std::string c; 96 std::string c;
88 97
89 for (int i = 0; i < argc; ++i) { 98 for (int i = 0; i < argc; ++i) {
90 c += std::string(argv[i]); 99 c += std::string(argv[i]);
91 } 100 }
92 CommandLine& cmd_line = CommandLine::FromString(ASCIIToWide(c)); 101 CommandLine& cmd_line = CommandLine::FromString(ASCIIToWide(c));
93 #endif 102 #endif
94 103
95 // Init the commandline singleton from the env. 104 // Init the commandline singleton from the env.
96 CommandLine::Init(0, NULL); 105 CommandLine::Init(0, NULL);
97 106
98 #if OS_POSIX 107 #if OS_POSIX
99 signal(SIGPIPE, SIG_IGN); 108 signal(SIGPIPE, SIG_IGN);
100 signal(SIGCHLD, &signal_handler); 109 signal(SIGCHLD, &signal_handler);
101 #endif 110 #endif
102 srand((unsigned int)time(NULL)); 111 srand((unsigned int)time(NULL));
103 112
104 if (cmd_line.HasSwitch(std::string("port"))) { 113 if (cmd_line.HasSwitch(std::string("port"))) {
105 port = cmd_line.GetSwitchValueASCII(std::string("port")); 114 port = cmd_line.GetSwitchValueASCII(std::string("port"));
106 } 115 }
107 116
108 VLOG(1) << "Using port: " << port; 117 VLOG(1) << "Using port: " << port;
109 webdriver::SessionManager* session = webdriver::SessionManager::GetInstance(); 118 webdriver::SessionManager* session = webdriver::SessionManager::GetInstance();
110 session->SetIPAddress(port); 119 session->SetIPAddress(port);
111 120
112 // Initialize SHTTPD context. 121 // Initialize SHTTPD context.
113 // Listen on port 8080 or port specified on command line. 122 // Listen on port 9515 or port specified on command line.
114 // TODO(jmikhail) Maybe add port 8081 as a secure connection. 123 // TODO(jmikhail) Maybe add port 9516 as a secure connection.
115 ctx = mg_start(); 124 ctx = mg_start();
116 mg_set_option(ctx, "ports", port.c_str()); 125 mg_set_option(ctx, "ports", port.c_str());
117 126
118 webdriver::InitCallbacks(ctx); 127 webdriver::InitCallbacks(ctx);
119 128
120 std::cout << "Starting server" << std::endl; 129 std::cout << "Starting server on port: " << port << std::endl;
121 // The default behavior is to run this service forever. 130 // The default behavior is to run this service forever.
122 while (true) 131 while (true)
123 PlatformThread::Sleep(3600); 132 PlatformThread::Sleep(3600);
124 133
125 // We should not reach here since the service should never quit. 134 // We should not reach here since the service should never quit.
126 // TODO(jmikhail): register a listener for SIGTERM and break the 135 // TODO(jmikhail): register a listener for SIGTERM and break the
127 // message loop gracefully. 136 // message loop gracefully.
128 mg_stop(ctx); 137 mg_stop(ctx);
129 return (EXIT_SUCCESS); 138 return (EXIT_SUCCESS);
130 } 139 }
131 140
OLDNEW
« no previous file with comments | « chrome/test/webdriver/commands/implicit_wait_command.cc ('k') | chrome/test/webdriver/webdriver_remote_tests.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698