"Fossies" - the Fresh Open Source Software Archive 
Member "selenium-selenium-4.8.1/cpp/iedriver/CommandHandlers/SetAlertCredentialsCommandHandler.cpp" (17 Feb 2023, 3035 Bytes) of package /linux/www/selenium-selenium-4.8.1.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "SetAlertCredentialsCommandHandler.cpp" see the
Fossies "Dox" file reference documentation.
1 // Licensed to the Software Freedom Conservancy (SFC) under one
2 // or more contributor license agreements. See the NOTICE file
3 // distributed with this work for additional information
4 // regarding copyright ownership. The SFC licenses this file
5 // to you under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16
17 #include "SetAlertCredentialsCommandHandler.h"
18 #include "errorcodes.h"
19 #include "../Alert.h"
20 #include "../Browser.h"
21 #include "../IECommandExecutor.h"
22
23 namespace webdriver {
24
25 SetAlertCredentialsCommandHandler::SetAlertCredentialsCommandHandler(void) {
26 }
27
28 SetAlertCredentialsCommandHandler::~SetAlertCredentialsCommandHandler(void) {
29 }
30
31 void SetAlertCredentialsCommandHandler::ExecuteInternal(
32 const IECommandExecutor& executor,
33 const ParametersMap& command_parameters,
34 Response* response) {
35 ParametersMap::const_iterator username_parameter_iterator = command_parameters.find("username");
36 if (username_parameter_iterator == command_parameters.end()) {
37 response->SetErrorResponse(ERROR_INVALID_ARGUMENT, "Missing parameter: username");
38 return;
39 }
40 std::string username = username_parameter_iterator->second.asString();
41
42 ParametersMap::const_iterator password_parameter_iterator = command_parameters.find("password");
43 if (password_parameter_iterator == command_parameters.end()) {
44 response->SetErrorResponse(ERROR_INVALID_ARGUMENT, "Missing parameter: password");
45 return;
46 }
47 std::string password = password_parameter_iterator->second.asString();
48
49 BrowserHandle browser_wrapper;
50 int status_code = executor.GetCurrentBrowser(&browser_wrapper);
51 if (status_code != WD_SUCCESS) {
52 response->SetErrorResponse(status_code, "Unable to get current browser");
53 return;
54 }
55 // This sleep is required to give IE time to draw the dialog.
56 ::Sleep(100);
57 HWND alert_handle = browser_wrapper->GetActiveDialogWindowHandle();
58 if (alert_handle == NULL) {
59 response->SetErrorResponse(ERROR_NO_SUCH_ALERT, "No alert is active");
60 } else {
61 Alert dialog(browser_wrapper, alert_handle);
62 status_code = dialog.SetUserName(username);
63 if (status_code != WD_SUCCESS) {
64 response->SetErrorResponse(status_code,
65 "Could not set user name");
66 return;
67 }
68 status_code = dialog.SetPassword(password);
69 if (status_code != WD_SUCCESS) {
70 response->SetErrorResponse(status_code,
71 "Could not set password");
72 return;
73 }
74 response->SetSuccessResponse(Json::Value::null);
75 }
76 }
77
78 } // namespace webdriver