惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
酷 壳 – CoolShell
酷 壳 – CoolShell
WordPress大学
WordPress大学
小众软件
小众软件
博客园 - 司徒正美
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Jina AI
Jina AI
Hugging Face - Blog
Hugging Face - Blog
博客园 - Franky
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
量子位
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
雷峰网
雷峰网
云风的 BLOG
云风的 BLOG
M
MIT News - Artificial intelligence
F
Fortinet All Blogs
T
Tailwind CSS Blog
Martin Fowler
Martin Fowler
I
InfoQ
The GitHub Blog
The GitHub Blog
有赞技术团队
有赞技术团队
The Cloudflare Blog
罗磊的独立博客

博客园 - Tachikoma

用Ruby实现 Web Service Server ,并用Ruby发送 HTTP请求 Web Service Android 使用 Ksoap2 出现的低级错误... - Tachikoma Cygwin中通过RJB在Ruby下调用ICTCLAS(JAVA) ICTCLAS4J 的编译脚本 Ruby Sandbox 实现运行客户代码 - Tachikoma Ruby在使用MongoDB时,对Cursor的重新包装 ruby 下使用 ICTCLAS(JAVA) RJB 在windows下的一些安装事项 Ruby手工测试正确,rcov测试失败的解决 在dell dimension 5150 上安装 leopard 手记 Rails测试中清空数据表/载入空fixtures RDoc 解决同名module 与 Class的问题 C 实用的 e-editor 的bundle Best of Ruby Quiz - Animal Quiz Best of Ruby Quiz - GEDCOM Parser Best of Ruby Quiz - MadLib - Tachikoma 使用selenium-on-rails的一些讨论 3]assertXpathCount的使用 使用selenium-on-rails的一些讨论 2]清理缓存 - Tachikoma - 博客园 关于 rails ActiveRecord 属性 以及 foreign_key 不直接用数据库项目 时的一些讨论
使用selenium-on-rails的一些讨论 [0,1]
Tachikoma · 2008-04-27 · via 博客园 - Tachikoma

这两天搞了一下selenium-on-rails, 作了一些讨论

0. 建议单独建立一个环境 selenium,用法见doc
0.1. 可以另开一个数据库用于selenium测试,但一般会用test库,以及测试夹具,但是有些只适合selenium测试的夹具,为了不影响其他测试,需要把这些夹具单独存放并保证不影响其他测试
举个例子[源自doc],建立空的夹具文件放在test/fixtures/blank下,然后http://localhost:3000/selenium/setup?fixtures=blank/* [可能需要转义一下],就会装载blank下的所有夹具,实际效果是讲数据库表清空

1. 关于测试夹具 fixtures 装入无效
有时会存在莫名其妙的无效问题,举个例子

open "/selenium/setup?fixtures=blank/*"
open 
"/selenium/setup?fixtures=all"  # => 这一行会失效

有时候第一行也可能直接失效
查看selenium-on-rails的源代码

 1#selenium-on-rails/lib/selenium-on-rails/fixture_loader.rb
 2
 3  def load_fixtures fixtures_param
 4    available = nil
 5    fixtures = fixtures_param.split(/\s*,\s*/).collect do |f|
 6      fixture_set = File.dirname f
 7      fixture_set = '' if fixture_set == '.'
 8      fixture = File.basename f
 9      if fixture == 'all'
10        available ||= available_fixtures
11        available[fixture_set]
12      else
13        f
14      end
15    end
16    fixtures.flatten!
17    fixtures.reject! {|f| f.blank? }
18
19    if fixtures.any?
20      # Fixtures.reset_cache  ## tachikmoma add
21      Fixtures.create_fixtures fixtures_path, fixtures
22    end
23    fixtures
24  end

第20行是我人为加入的,去掉其注释后问题可解决
原理:
在console里作了一下实验

 Fixtures.create_fixtures(File.join(RAILS_ROOT,"test/fixtures"),"teachers")  
#
=> 这句会成功

Fixtures.create_fixtures(File.join(RAILS_ROOT,
"test/fixtures"),"blank/teachers")
#
=> 这句和上句输出一样,并未把库清空

下面

Fixtures.create_fixtures(File.join(RAILS_ROOT,"test/fixtures"),"teachers")  
#
=> 这句会成功

Fixtures.reset_cache
#
=> 清空fixtures缓存,rails为了保证fixtures加载速度,启用了缓存机制

Fixtures.create_fixtures(File.join(RAILS_ROOT,
"test/fixtures"),"blank/teachers")
#
=> 清空库