我如何测试是否使用 Capybara/Poltergeist 从下拉菜单中选择了一个项目?
how can i test if an item selected from Dropdown menu with Capybara/Poltergeist?
这是页面来源:
<form class="ui form" action="/install" method="post">
<h4 class="ui dividing header">Database Settings</h4>
<p>Gogs requires MySQL, PostgreSQL, SQLite3 or TiDB.</p>
<div class="inline required field ">
<label>Database Type</label>
<div class="ui selection database type dropdown">
<input type="hidden" id="db_type" name="db_type" value="MySQL">
<div class="text">MySQL</div>
<i class="dropdown icon"></i>
<div class="menu">
<div class="item" data-value="MySQL">MySQL</div>
<div class="item" data-value="PostgreSQL">PostgreSQL</div>
<div class="item" data-value="SQLite3">SQLite3</div>
</div>
</div>
</div>
<div id="sql_settings" class="">
<div class="inline required field ">
<label for="db_host">Host</label>
<input id="db_host" name="db_host" value="127.0.0.1:3306">
</div>
<div class="inline required field ">
<label for="db_user">User</label>
<input id="db_user" name="db_user" value="root">
</div>
<div class="inline required field ">
<label for="db_passwd">Password</label>
<input id="db_passwd" name="db_passwd" type="password" value="">
</div>
<div class="inline required field ">
<label for="db_name">Database Name</label>
<input id="db_name" name="db_name" value="gogs">
<span class="help">Please use INNODB engine with utf8_general_ci charset for MySQL.</span>
</div>
</div>
<div id="pgsql_settings" class="hide">
<div class="inline required field">
<label>SSL Mode</label>
<div class="ui selection database type dropdown">
<input type="hidden" name="ssl_mode" value="disable">
<div class="default text">disable</div>
<i class="dropdown icon"></i>
<div class="menu">
<div class="item" data-value="disable">Disable</div>
<div class="item" data-value="require">Require</div>
<div class="item" data-value="verify-full">Verify Full</div>
</div>
</div>
</div>
</div>
<div id="sqlite_settings" class="hide">
<div class="inline required field ">
<label for="db_path">Path</label>
<input id="db_path" name="db_path" value="data/gogs.db">
<span class="help">The file path of SQLite3 or TiDB database. <br>Please use absolute path when you start as service.</span>
</div>
</div>
这是我的规范文件;
require 'spec_helper'
describe "Configure Gogs" do
include Capybara::DSL
context 'Gogs Settings' do
before { visit "http://0.0.0.0:3000" }
it 'fill settings' do
select 'SQLite3', from: 'db_type'
fill_in :db_path, with: '/data/gogs.db'
within("#sql_settings") do
fill_in :db_host, with: '127.0.0.1:3306'
fill_in :db_user, with: 'Tom'
fill_in :db_passwd, with: '123456'
fill_in :db_name, with: 'vitakid'
fill_in :db_name, with: 'vitakid'
end
fill_in :app_name, with: 'CODE'
fill_in :repo_root_path, with: '/data/git/gogs'
fill_in :run_user, with: 'git'
fill_in :domain, with: 'localhost'
fill_in :ssh_port, with: '22'
fill_in :http_port, with: '3000'
fill_in :app_url, with: 'http://localhost:3000/'
fill_in :log_root_path, with: '/app/gogs/log'
click_button 'Install Gogs'
save_and_open_page
end
结束
结尾
结束这是我得到的错误;
1)配置Gogs Gogs Settings填充设置
Failure/Error: select 'SQLite3', 来自: 'db_type'
Capybara::ElementNotFound:
Unable to find select box "db_type"
# ./spec/gogs_spec.rb:10:in `block (3 levels) in <top (required)>'
在 2.74 秒内完成(文件加载时间为 0.76115 秒)
1 个例子,1 个失败
失败的例子:
rspec ./spec/gogs_spec.rb:9 # 配置 Gogs Gogs 设置填充设置
我似乎无法找到它给出的错误。请帮忙
select 'SQLite3', from: 'db_type'
不起作用,因为 db_type select 元素隐藏在页面上,并已被某些 div 替换。您需要执行用户必须执行的操作,即单击下拉图标,然后单击菜单中的项目,例如
db_type_select = find('div.database.type.dropdown')
within(db_type_select) do
find('i.dropdown').click
find('.item', text: 'SQLite3').click
end
这是页面来源:
<form class="ui form" action="/install" method="post">
<h4 class="ui dividing header">Database Settings</h4>
<p>Gogs requires MySQL, PostgreSQL, SQLite3 or TiDB.</p>
<div class="inline required field ">
<label>Database Type</label>
<div class="ui selection database type dropdown">
<input type="hidden" id="db_type" name="db_type" value="MySQL">
<div class="text">MySQL</div>
<i class="dropdown icon"></i>
<div class="menu">
<div class="item" data-value="MySQL">MySQL</div>
<div class="item" data-value="PostgreSQL">PostgreSQL</div>
<div class="item" data-value="SQLite3">SQLite3</div>
</div>
</div>
</div>
<div id="sql_settings" class="">
<div class="inline required field ">
<label for="db_host">Host</label>
<input id="db_host" name="db_host" value="127.0.0.1:3306">
</div>
<div class="inline required field ">
<label for="db_user">User</label>
<input id="db_user" name="db_user" value="root">
</div>
<div class="inline required field ">
<label for="db_passwd">Password</label>
<input id="db_passwd" name="db_passwd" type="password" value="">
</div>
<div class="inline required field ">
<label for="db_name">Database Name</label>
<input id="db_name" name="db_name" value="gogs">
<span class="help">Please use INNODB engine with utf8_general_ci charset for MySQL.</span>
</div>
</div>
<div id="pgsql_settings" class="hide">
<div class="inline required field">
<label>SSL Mode</label>
<div class="ui selection database type dropdown">
<input type="hidden" name="ssl_mode" value="disable">
<div class="default text">disable</div>
<i class="dropdown icon"></i>
<div class="menu">
<div class="item" data-value="disable">Disable</div>
<div class="item" data-value="require">Require</div>
<div class="item" data-value="verify-full">Verify Full</div>
</div>
</div>
</div>
</div>
<div id="sqlite_settings" class="hide">
<div class="inline required field ">
<label for="db_path">Path</label>
<input id="db_path" name="db_path" value="data/gogs.db">
<span class="help">The file path of SQLite3 or TiDB database. <br>Please use absolute path when you start as service.</span>
</div>
</div>
这是我的规范文件;
require 'spec_helper'
describe "Configure Gogs" do
include Capybara::DSL
context 'Gogs Settings' do
before { visit "http://0.0.0.0:3000" }
it 'fill settings' do
select 'SQLite3', from: 'db_type'
fill_in :db_path, with: '/data/gogs.db'
within("#sql_settings") do
fill_in :db_host, with: '127.0.0.1:3306'
fill_in :db_user, with: 'Tom'
fill_in :db_passwd, with: '123456'
fill_in :db_name, with: 'vitakid'
fill_in :db_name, with: 'vitakid'
end
fill_in :app_name, with: 'CODE'
fill_in :repo_root_path, with: '/data/git/gogs'
fill_in :run_user, with: 'git'
fill_in :domain, with: 'localhost'
fill_in :ssh_port, with: '22'
fill_in :http_port, with: '3000'
fill_in :app_url, with: 'http://localhost:3000/'
fill_in :log_root_path, with: '/app/gogs/log'
click_button 'Install Gogs'
save_and_open_page
end
结束 结尾 结束这是我得到的错误;
1)配置Gogs Gogs Settings填充设置 Failure/Error: select 'SQLite3', 来自: 'db_type'
Capybara::ElementNotFound:
Unable to find select box "db_type"
# ./spec/gogs_spec.rb:10:in `block (3 levels) in <top (required)>'
在 2.74 秒内完成(文件加载时间为 0.76115 秒) 1 个例子,1 个失败
失败的例子:
rspec ./spec/gogs_spec.rb:9 # 配置 Gogs Gogs 设置填充设置
我似乎无法找到它给出的错误。请帮忙
select 'SQLite3', from: 'db_type'
不起作用,因为 db_type select 元素隐藏在页面上,并已被某些 div 替换。您需要执行用户必须执行的操作,即单击下拉图标,然后单击菜单中的项目,例如
db_type_select = find('div.database.type.dropdown')
within(db_type_select) do
find('i.dropdown').click
find('.item', text: 'SQLite3').click
end