File tree Expand file tree Collapse file tree 6 files changed +71
-1
lines changed
spec/integration/selenium/webdriver Expand file tree Collapse file tree 6 files changed +71
-1
lines changed Original file line number Diff line number Diff line change 61
61
require 'selenium/webdriver/common/driver_extensions/has_apple_permissions'
62
62
require 'selenium/webdriver/common/driver_extensions/has_permissions'
63
63
require 'selenium/webdriver/common/driver_extensions/has_debugger'
64
+ require 'selenium/webdriver/common/driver_extensions/has_context'
64
65
require 'selenium/webdriver/common/driver_extensions/prints_page'
65
66
require 'selenium/webdriver/common/driver_extensions/uploads_files'
66
67
require 'selenium/webdriver/common/driver_extensions/full_page_screenshot'
Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
3
+ # Licensed to the Software Freedom Conservancy (SFC) under one
4
+ # or more contributor license agreements. See the NOTICE file
5
+ # distributed with this work for additional information
6
+ # regarding copyright ownership. The SFC licenses this file
7
+ # to you under the Apache License, Version 2.0 (the
8
+ # "License"); you may not use this file except in compliance
9
+ # with the License. You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing,
14
+ # software distributed under the License is distributed on an
15
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
+ # KIND, either express or implied. See the License for the
17
+ # specific language governing permissions and limitations
18
+ # under the License.
19
+
20
+ module Selenium
21
+ module WebDriver
22
+ module DriverExtensions
23
+ module HasContext
24
+
25
+ #
26
+ # Sets the context that Selenium commands are running in using
27
+ # a `with` statement. The state of the context on the server is
28
+ # saved before entering the block, and restored upon exiting it.
29
+ #
30
+ # @param [String] name which permission to set
31
+ # @param [String] value what to set the permission to
32
+ #
33
+
34
+ def context = ( value )
35
+ @bridge . context = value
36
+ end
37
+
38
+ def context
39
+ @bridge . context
40
+ end
41
+
42
+ end # HasContext
43
+ end # DriverExtensions
44
+ end # WebDriver
45
+ end # Selenium
Original file line number Diff line number Diff line change @@ -29,6 +29,7 @@ module Firefox
29
29
class Driver < WebDriver ::Driver
30
30
EXTENSIONS = [ DriverExtensions ::HasAddons ,
31
31
DriverExtensions ::FullPageScreenshot ,
32
+ DriverExtensions ::HasContext ,
32
33
DriverExtensions ::HasDevTools ,
33
34
DriverExtensions ::HasLogEvents ,
34
35
DriverExtensions ::HasNetworkInterception ,
Original file line number Diff line number Diff line change @@ -23,6 +23,8 @@ module Firefox
23
23
module Features
24
24
25
25
FIREFOX_COMMANDS = {
26
+ get_context : [ :get , 'session/:session_id/moz/context' ] ,
27
+ set_context : [ :post , 'session/:session_id/moz/context' ] ,
26
28
install_addon : [ :post , 'session/:session_id/moz/addon/install' ] ,
27
29
uninstall_addon : [ :post , 'session/:session_id/moz/addon/uninstall' ] ,
28
30
full_page_screenshot : [ :get , 'session/:session_id/moz/screenshot/full' ]
@@ -46,6 +48,13 @@ def full_screenshot
46
48
execute :full_page_screenshot
47
49
end
48
50
51
+ def context = ( context )
52
+ execute :set_context , { } , { context : context }
53
+ end
54
+
55
+ def context
56
+ execute :get_context
57
+ end
49
58
end # Bridge
50
59
end # Firefox
51
60
end # WebDriver
Original file line number Diff line number Diff line change @@ -49,6 +49,20 @@ module Firefox
49
49
ensure
50
50
File . delete ( path ) if File . exist? ( path )
51
51
end
52
+
53
+ it 'can get and set context' do
54
+ options = Options . new ( prefs : { 'browser.download.dir' : 'foo/bar' } )
55
+ create_driver! ( capabilities : options ) do |driver |
56
+ expect ( driver . context ) . to eq 'content'
57
+
58
+ driver . context = 'chrome'
59
+ expect ( driver . context ) . to eq 'chrome'
60
+
61
+ # This call can not be made when context is set to 'content'
62
+ dir = driver . execute_script ( "return Services.prefs.getStringPref('browser.download.dir')" )
63
+ expect ( dir ) . to eq 'foo/bar'
64
+ end
65
+ end
52
66
end
53
67
end
54
68
end # Firefox
Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ def initialize
29
29
30
30
extract_browser_from_bazel_target_name
31
31
32
- @driver = ( ENV [ 'WD_SPEC_DRIVER' ] || :chrome ) . to_sym
32
+ @driver = ( ENV [ 'WD_SPEC_DRIVER' ] || :firefox ) . to_sym
33
33
@driver_instance = nil
34
34
end
35
35
You can’t perform that action at this time.
0 commit comments