Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
f52e17f1
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f52e17f1
编写于
1月 15, 2018
作者:
A
Ashley Ellis Pierce
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move browser checking to its own class
上级
3ddb811a
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
57 addition
and
29 deletion
+57
-29
actionpack/lib/action_dispatch/system_test_case.rb
actionpack/lib/action_dispatch/system_test_case.rb
+1
-0
actionpack/lib/action_dispatch/system_testing/browser.rb
actionpack/lib/action_dispatch/system_testing/browser.rb
+49
-0
actionpack/lib/action_dispatch/system_testing/driver.rb
actionpack/lib/action_dispatch/system_testing/driver.rb
+3
-26
actionpack/test/dispatch/system_testing/driver_test.rb
actionpack/test/dispatch/system_testing/driver_test.rb
+4
-3
未找到文件。
actionpack/lib/action_dispatch/system_test_case.rb
浏览文件 @
f52e17f1
...
@@ -6,6 +6,7 @@
...
@@ -6,6 +6,7 @@
require
"capybara/minitest"
require
"capybara/minitest"
require
"action_controller"
require
"action_controller"
require
"action_dispatch/system_testing/driver"
require
"action_dispatch/system_testing/driver"
require
"action_dispatch/system_testing/browser"
require
"action_dispatch/system_testing/server"
require
"action_dispatch/system_testing/server"
require
"action_dispatch/system_testing/test_helpers/screenshot_helper"
require
"action_dispatch/system_testing/test_helpers/screenshot_helper"
require
"action_dispatch/system_testing/test_helpers/setup_and_teardown"
require
"action_dispatch/system_testing/test_helpers/setup_and_teardown"
...
...
actionpack/lib/action_dispatch/system_testing/browser.rb
0 → 100644
浏览文件 @
f52e17f1
# frozen_string_literal: true
module
ActionDispatch
module
SystemTesting
class
Browser
# :nodoc:
attr_reader
:name
def
initialize
(
name
)
@name
=
name
end
def
type
case
name
when
:headless_chrome
:chrome
when
:headless_firefox
:firefox
else
name
end
end
def
options
case
name
when
:headless_chrome
headless_chrome_browser_options
when
:headless_firefox
headless_firefox_browser_options
end
end
private
def
headless_chrome_browser_options
options
=
Selenium
::
WebDriver
::
Chrome
::
Options
.
new
options
.
args
<<
"--headless"
options
.
args
<<
"--disable-gpu"
options
end
def
headless_firefox_browser_options
options
=
Selenium
::
WebDriver
::
Firefox
::
Options
.
new
options
.
args
<<
"-headless"
options
end
end
end
end
actionpack/lib/action_dispatch/system_testing/driver.rb
浏览文件 @
f52e17f1
...
@@ -5,7 +5,7 @@ module SystemTesting
...
@@ -5,7 +5,7 @@ module SystemTesting
class
Driver
# :nodoc:
class
Driver
# :nodoc:
def
initialize
(
name
,
**
options
)
def
initialize
(
name
,
**
options
)
@name
=
name
@name
=
name
@browser
=
options
[
:using
]
@browser
=
Browser
.
new
(
options
[
:using
])
@screen_size
=
options
[
:screen_size
]
@screen_size
=
options
[
:screen_size
]
@options
=
options
[
:options
]
@options
=
options
[
:options
]
end
end
...
@@ -32,34 +32,11 @@ def register
...
@@ -32,34 +32,11 @@ def register
end
end
def
browser_options
def
browser_options
if
@browser
==
:headless_chrome
@options
.
merge
(
options:
@browser
.
options
).
compact
browser_options
=
Selenium
::
WebDriver
::
Chrome
::
Options
.
new
browser_options
.
args
<<
"--headless"
browser_options
.
args
<<
"--disable-gpu"
@options
.
merge
(
options:
browser_options
)
elsif
@browser
==
:headless_firefox
browser_options
=
Selenium
::
WebDriver
::
Firefox
::
Options
.
new
browser_options
.
args
<<
"-headless"
@options
.
merge
(
options:
browser_options
)
else
@options
end
end
def
browser
if
@browser
==
:headless_chrome
:chrome
elsif
@browser
==
:headless_firefox
:firefox
else
@browser
end
end
end
def
register_selenium
(
app
)
def
register_selenium
(
app
)
Capybara
::
Selenium
::
Driver
.
new
(
app
,
{
browser:
browser
}.
merge
(
browser_options
)).
tap
do
|
driver
|
Capybara
::
Selenium
::
Driver
.
new
(
app
,
{
browser:
@browser
.
type
}.
merge
(
browser_options
)).
tap
do
|
driver
|
driver
.
browser
.
manage
.
window
.
size
=
Selenium
::
WebDriver
::
Dimension
.
new
(
*
@screen_size
)
driver
.
browser
.
manage
.
window
.
size
=
Selenium
::
WebDriver
::
Dimension
.
new
(
*
@screen_size
)
end
end
end
end
...
...
actionpack/test/dispatch/system_testing/driver_test.rb
浏览文件 @
f52e17f1
...
@@ -12,7 +12,8 @@ class DriverTest < ActiveSupport::TestCase
...
@@ -12,7 +12,8 @@ class DriverTest < ActiveSupport::TestCase
test
"initializing the driver with a browser"
do
test
"initializing the driver with a browser"
do
driver
=
ActionDispatch
::
SystemTesting
::
Driver
.
new
(
:selenium
,
using: :chrome
,
screen_size:
[
1400
,
1400
],
options:
{
url:
"http://example.com/wd/hub"
})
driver
=
ActionDispatch
::
SystemTesting
::
Driver
.
new
(
:selenium
,
using: :chrome
,
screen_size:
[
1400
,
1400
],
options:
{
url:
"http://example.com/wd/hub"
})
assert_equal
:selenium
,
driver
.
instance_variable_get
(
:@name
)
assert_equal
:selenium
,
driver
.
instance_variable_get
(
:@name
)
assert_equal
:chrome
,
driver
.
instance_variable_get
(
:@browser
)
assert_equal
:chrome
,
driver
.
instance_variable_get
(
:@browser
).
name
assert_nil
driver
.
instance_variable_get
(
:@browser
).
options
assert_equal
[
1400
,
1400
],
driver
.
instance_variable_get
(
:@screen_size
)
assert_equal
[
1400
,
1400
],
driver
.
instance_variable_get
(
:@screen_size
)
assert_equal
({
url:
"http://example.com/wd/hub"
}),
driver
.
instance_variable_get
(
:@options
)
assert_equal
({
url:
"http://example.com/wd/hub"
}),
driver
.
instance_variable_get
(
:@options
)
end
end
...
@@ -20,7 +21,7 @@ class DriverTest < ActiveSupport::TestCase
...
@@ -20,7 +21,7 @@ class DriverTest < ActiveSupport::TestCase
test
"initializing the driver with a headless chrome"
do
test
"initializing the driver with a headless chrome"
do
driver
=
ActionDispatch
::
SystemTesting
::
Driver
.
new
(
:selenium
,
using: :headless_chrome
,
screen_size:
[
1400
,
1400
],
options:
{
url:
"http://example.com/wd/hub"
})
driver
=
ActionDispatch
::
SystemTesting
::
Driver
.
new
(
:selenium
,
using: :headless_chrome
,
screen_size:
[
1400
,
1400
],
options:
{
url:
"http://example.com/wd/hub"
})
assert_equal
:selenium
,
driver
.
instance_variable_get
(
:@name
)
assert_equal
:selenium
,
driver
.
instance_variable_get
(
:@name
)
assert_equal
:headless_chrome
,
driver
.
instance_variable_get
(
:@browser
)
assert_equal
:headless_chrome
,
driver
.
instance_variable_get
(
:@browser
)
.
name
assert_equal
[
1400
,
1400
],
driver
.
instance_variable_get
(
:@screen_size
)
assert_equal
[
1400
,
1400
],
driver
.
instance_variable_get
(
:@screen_size
)
assert_equal
({
url:
"http://example.com/wd/hub"
}),
driver
.
instance_variable_get
(
:@options
)
assert_equal
({
url:
"http://example.com/wd/hub"
}),
driver
.
instance_variable_get
(
:@options
)
end
end
...
@@ -28,7 +29,7 @@ class DriverTest < ActiveSupport::TestCase
...
@@ -28,7 +29,7 @@ class DriverTest < ActiveSupport::TestCase
test
"initializing the driver with a headless firefox"
do
test
"initializing the driver with a headless firefox"
do
driver
=
ActionDispatch
::
SystemTesting
::
Driver
.
new
(
:selenium
,
using: :headless_firefox
,
screen_size:
[
1400
,
1400
],
options:
{
url:
"http://example.com/wd/hub"
})
driver
=
ActionDispatch
::
SystemTesting
::
Driver
.
new
(
:selenium
,
using: :headless_firefox
,
screen_size:
[
1400
,
1400
],
options:
{
url:
"http://example.com/wd/hub"
})
assert_equal
:selenium
,
driver
.
instance_variable_get
(
:@name
)
assert_equal
:selenium
,
driver
.
instance_variable_get
(
:@name
)
assert_equal
:headless_firefox
,
driver
.
instance_variable_get
(
:@browser
)
assert_equal
:headless_firefox
,
driver
.
instance_variable_get
(
:@browser
)
.
name
assert_equal
[
1400
,
1400
],
driver
.
instance_variable_get
(
:@screen_size
)
assert_equal
[
1400
,
1400
],
driver
.
instance_variable_get
(
:@screen_size
)
assert_equal
({
url:
"http://example.com/wd/hub"
}),
driver
.
instance_variable_get
(
:@options
)
assert_equal
({
url:
"http://example.com/wd/hub"
}),
driver
.
instance_variable_get
(
:@options
)
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录