Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/rust/src/safari.rs
2885 views
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
6
// "License"); you may not use this file except in compliance
7
// with the License. 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,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied. See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
use crate::config::ManagerConfig;
19
use crate::config::OS::MACOS;
20
use crate::files::BrowserPath;
21
use crate::{create_http_client, Logger, SeleniumManager, STABLE};
22
use anyhow::anyhow;
23
use anyhow::Error;
24
use reqwest::Client;
25
use std::collections::HashMap;
26
use std::path::PathBuf;
27
use std::string::ToString;
28
use std::sync::mpsc;
29
use std::sync::mpsc::{Receiver, Sender};
30
31
pub const SAFARI_NAME: &str = "safari";
32
pub const SAFARIDRIVER_NAME: &str = "safaridriver";
33
const SAFARI_PATH: &str = "/Applications/Safari.app";
34
const SAFARI_FULL_PATH: &str = "/Applications/Safari.app/Contents/MacOS/Safari";
35
36
pub struct SafariManager {
37
pub browser_name: &'static str,
38
pub driver_name: &'static str,
39
pub config: ManagerConfig,
40
pub http_client: Client,
41
pub log: Logger,
42
pub tx: Sender<String>,
43
pub rx: Receiver<String>,
44
pub download_browser: bool,
45
}
46
47
impl SafariManager {
48
pub fn new() -> Result<Box<Self>, Error> {
49
let browser_name = SAFARI_NAME;
50
let driver_name = SAFARIDRIVER_NAME;
51
let config = ManagerConfig::default(browser_name, driver_name);
52
let default_timeout = config.timeout.to_owned();
53
let default_proxy = &config.proxy;
54
let (tx, rx): (Sender<String>, Receiver<String>) = mpsc::channel();
55
Ok(Box::new(SafariManager {
56
browser_name,
57
driver_name,
58
http_client: create_http_client(default_timeout, default_proxy)?,
59
config,
60
log: Logger::new(),
61
tx,
62
rx,
63
download_browser: false,
64
}))
65
}
66
}
67
68
impl SeleniumManager for SafariManager {
69
fn get_browser_name(&self) -> &str {
70
self.browser_name
71
}
72
73
fn get_browser_names_in_path(&self) -> Vec<&str> {
74
vec![self.get_browser_name()]
75
}
76
77
fn get_http_client(&self) -> &Client {
78
&self.http_client
79
}
80
81
fn set_http_client(&mut self, http_client: Client) {
82
self.http_client = http_client;
83
}
84
85
fn get_browser_path_map(&self) -> HashMap<BrowserPath, &str> {
86
HashMap::from([(BrowserPath::new(MACOS, STABLE), SAFARI_PATH)])
87
}
88
89
fn discover_browser_version(&mut self) -> Result<Option<String>, Error> {
90
self.discover_safari_version(SAFARI_FULL_PATH.to_string())
91
}
92
93
fn get_driver_name(&self) -> &str {
94
self.driver_name
95
}
96
97
fn request_driver_version(&mut self) -> Result<String, Error> {
98
Ok("(local)".to_string())
99
}
100
101
fn request_browser_version(&mut self) -> Result<Option<String>, Error> {
102
Ok(None)
103
}
104
105
fn get_driver_url(&mut self) -> Result<String, Error> {
106
Err(anyhow!(format!(
107
"{} not available for download",
108
self.get_driver_name()
109
)))
110
}
111
112
fn get_driver_path_in_cache(&self) -> Result<PathBuf, Error> {
113
Ok(PathBuf::from("/usr/bin/safaridriver"))
114
}
115
116
fn get_config(&self) -> &ManagerConfig {
117
&self.config
118
}
119
120
fn get_config_mut(&mut self) -> &mut ManagerConfig {
121
&mut self.config
122
}
123
124
fn set_config(&mut self, config: ManagerConfig) {
125
self.config = config;
126
}
127
128
fn get_logger(&self) -> &Logger {
129
&self.log
130
}
131
132
fn set_logger(&mut self, log: Logger) {
133
self.log = log;
134
}
135
136
fn get_sender(&self) -> &Sender<String> {
137
&self.tx
138
}
139
140
fn get_receiver(&self) -> &Receiver<String> {
141
&self.rx
142
}
143
144
fn get_platform_label(&self) -> &str {
145
""
146
}
147
148
fn request_latest_browser_version_from_online(
149
&mut self,
150
_browser_version: &str,
151
) -> Result<String, Error> {
152
self.unavailable_download()
153
}
154
155
fn request_fixed_browser_version_from_online(
156
&mut self,
157
_browser_version: &str,
158
) -> Result<String, Error> {
159
self.unavailable_download()
160
}
161
162
fn get_min_browser_version_for_download(&self) -> Result<i32, Error> {
163
self.unavailable_download()
164
}
165
166
fn get_browser_binary_path(&mut self, _browser_version: &str) -> Result<PathBuf, Error> {
167
self.unavailable_download()
168
}
169
170
fn get_browser_url_for_download(&mut self, _browser_version: &str) -> Result<String, Error> {
171
self.unavailable_download()
172
}
173
174
fn get_browser_label_for_download(
175
&self,
176
_browser_version: &str,
177
) -> Result<Option<&str>, Error> {
178
self.unavailable_download()
179
}
180
181
fn is_download_browser(&self) -> bool {
182
self.download_browser
183
}
184
185
fn set_download_browser(&mut self, download_browser: bool) {
186
self.download_browser = download_browser;
187
}
188
189
fn is_snap(&self, _browser_path: &str) -> bool {
190
false
191
}
192
193
fn get_snap_path(&self) -> Option<PathBuf> {
194
None
195
}
196
}
197
198