Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/rust/src/safaritp.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 SAFARITP_NAMES: &[&str] = &[
32
"safaritp",
33
"safari technology preview",
34
r"safari\ technology\ preview",
35
"safaritechnologypreview",
36
];
37
pub const SAFARITPDRIVER_NAME: &str = "safaridriver";
38
const SAFARITP_PATH: &str = "/Applications/Safari Technology Preview.app";
39
const SAFARITP_FULL_PATH: &str =
40
"/Applications/Safari Technology Preview.app/Contents/MacOS/Safari Technology Preview";
41
42
pub struct SafariTPManager {
43
pub browser_name: &'static str,
44
pub driver_name: &'static str,
45
pub config: ManagerConfig,
46
pub http_client: Client,
47
pub log: Logger,
48
pub tx: Sender<String>,
49
pub rx: Receiver<String>,
50
pub download_browser: bool,
51
}
52
53
impl SafariTPManager {
54
pub fn new() -> Result<Box<Self>, Error> {
55
let browser_name = SAFARITP_NAMES[0];
56
let driver_name = SAFARITPDRIVER_NAME;
57
let config = ManagerConfig::default(browser_name, driver_name);
58
let default_timeout = config.timeout.to_owned();
59
let default_proxy = &config.proxy;
60
let (tx, rx): (Sender<String>, Receiver<String>) = mpsc::channel();
61
Ok(Box::new(SafariTPManager {
62
browser_name,
63
driver_name,
64
http_client: create_http_client(default_timeout, default_proxy)?,
65
config,
66
log: Logger::new(),
67
tx,
68
rx,
69
download_browser: false,
70
}))
71
}
72
}
73
74
impl SeleniumManager for SafariTPManager {
75
fn get_browser_name(&self) -> &str {
76
self.browser_name
77
}
78
79
fn get_browser_names_in_path(&self) -> Vec<&str> {
80
vec![self.get_browser_name()]
81
}
82
83
fn get_http_client(&self) -> &Client {
84
&self.http_client
85
}
86
87
fn set_http_client(&mut self, http_client: Client) {
88
self.http_client = http_client;
89
}
90
91
fn get_browser_path_map(&self) -> HashMap<BrowserPath, &str> {
92
HashMap::from([(BrowserPath::new(MACOS, STABLE), SAFARITP_PATH)])
93
}
94
95
fn discover_browser_version(&mut self) -> Result<Option<String>, Error> {
96
self.discover_safari_version(SAFARITP_FULL_PATH.to_string())
97
}
98
99
fn get_driver_name(&self) -> &str {
100
self.driver_name
101
}
102
103
fn request_driver_version(&mut self) -> Result<String, Error> {
104
Ok("(local)".to_string())
105
}
106
107
fn request_browser_version(&mut self) -> Result<Option<String>, Error> {
108
Ok(None)
109
}
110
111
fn get_driver_url(&mut self) -> Result<String, Error> {
112
Err(anyhow!(format!(
113
"{} not available for download",
114
self.get_driver_name()
115
)))
116
}
117
118
fn get_driver_path_in_cache(&self) -> Result<PathBuf, Error> {
119
Ok(PathBuf::from(
120
"/Applications/Safari Technology Preview.app/Contents/MacOS/safaridriver",
121
))
122
}
123
124
fn get_config(&self) -> &ManagerConfig {
125
&self.config
126
}
127
128
fn get_config_mut(&mut self) -> &mut ManagerConfig {
129
&mut self.config
130
}
131
132
fn set_config(&mut self, config: ManagerConfig) {
133
self.config = config;
134
}
135
136
fn get_logger(&self) -> &Logger {
137
&self.log
138
}
139
140
fn set_logger(&mut self, log: Logger) {
141
self.log = log;
142
}
143
144
fn get_sender(&self) -> &Sender<String> {
145
&self.tx
146
}
147
148
fn get_receiver(&self) -> &Receiver<String> {
149
&self.rx
150
}
151
152
fn get_platform_label(&self) -> &str {
153
""
154
}
155
156
fn request_latest_browser_version_from_online(
157
&mut self,
158
_browser_version: &str,
159
) -> Result<String, Error> {
160
self.unavailable_download()
161
}
162
163
fn request_fixed_browser_version_from_online(
164
&mut self,
165
_browser_version: &str,
166
) -> Result<String, Error> {
167
self.unavailable_download()
168
}
169
170
fn get_min_browser_version_for_download(&self) -> Result<i32, Error> {
171
self.unavailable_download()
172
}
173
174
fn get_browser_binary_path(&mut self, _browser_version: &str) -> Result<PathBuf, Error> {
175
self.unavailable_download()
176
}
177
178
fn get_browser_url_for_download(&mut self, _browser_version: &str) -> Result<String, Error> {
179
self.unavailable_download()
180
}
181
182
fn get_browser_label_for_download(
183
&self,
184
_browser_version: &str,
185
) -> Result<Option<&str>, Error> {
186
self.unavailable_download()
187
}
188
189
fn is_download_browser(&self) -> bool {
190
self.download_browser
191
}
192
193
fn set_download_browser(&mut self, download_browser: bool) {
194
self.download_browser = download_browser;
195
}
196
197
fn is_snap(&self, _browser_path: &str) -> bool {
198
false
199
}
200
201
fn get_snap_path(&self) -> Option<PathBuf> {
202
None
203
}
204
}
205
206