SitePoint Sponsor |
|
User Tag List
Results 1 to 10 of 10
Thread: Watir, MySQL, Windows
-
Apr 4, 2006, 11:38 #1
- Join Date
- Jul 2005
- Posts
- 86
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Watir, MySQL, Windows
I'm working on a PC with Windows XP and I have started to use WATIR for writing tests for my Web applications. (PHP) I'm a Ruby newbie, and have no experience with this language.
My problem is that I want to use Watir to test HTML forms to check if the submitted value actually is registered in the MySQL database. How can I connect Watir(Ruby) to MySQL and make this comparison?
I use the Ruby One-Click installer for Windows, and the Watir One-Click installer.
I'd be very grateful for a detailed description on how to solve this problem.
Regards.
-
Apr 5, 2006, 05:49 #2
- Join Date
- Aug 2005
- Posts
- 986
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I've never used watir, but if you just want to connect to the database, you have a few options:
- Use low level functions
- Use ActiveRecord
- Use Og
I'll focus on the second one:
Install activerecord with:
$ gem install activerecord
Now open your watir file, and put this in it:
Code:require_gem 'activerecord' ActiveRecord::Base.establish_connection( :adapter => "mysql", :host => "localhost", :username => "root", :password => "******", :database => "dbname" )
Code:class Post < ActiveRecord::Base end
Code:Post.find(1) #=> Find post with id=1 Post.find_by_title("foo") #=> Find post with title="foo"
http://rubyonrails.com/rails/classes...cord/Base.html
-
Apr 5, 2006, 07:14 #3
- Join Date
- Jul 2005
- Posts
- 86
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by Fenrir2
-
Apr 5, 2006, 07:20 #4
gem works on Windows if you've installed RubyGems.
-
Apr 5, 2006, 11:02 #5
- Join Date
- Aug 2005
- Posts
- 986
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
It's the same for windows. $ just means: open console and type the following.
Ruby one Click installer contains Rubygems.
-
Apr 5, 2006, 14:46 #6
- Join Date
- Jul 2005
- Posts
- 86
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanx! That worked.
Could someone give me the syntax for inserting in the database and storing the id in a variable too? That would be great!
-
Apr 6, 2006, 06:30 #7
- Join Date
- Aug 2005
- Posts
- 986
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I assume that you have a posts table and a Post model class.
Code:a_post = Post.create(:title => 'The title', :content => 'The content') a_post.id
-
Apr 6, 2006, 06:38 #8
- Join Date
- Jul 2005
- Posts
- 86
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks!
I had som problems with the MySQL connection, but this page (http://wiki.rubyonrails.org/rails/pa...ndingsOnWin32/) solved the problem.
-
Apr 25, 2006, 23:54 #9
- Join Date
- Jul 2001
- Location
- Aurora, OR
- Posts
- 16
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Ruby / Watir / SQL Server?
Fenir2, Your reply to the Ruby / Watir / MYSQL was fantastic. Do you have an equivalent advice for SQL Server users?
I typically use Excel for front end input, then generate Ruby code from the back end of Excel and execute that, then come back to the Excel script to do the Sql Server query. I'd actually rather to do the query inside the Ruby code.I'd rather have a free bottle in front of me than a prefrontal lobotomy
-
Apr 26, 2006, 04:52 #10
- Join Date
- Aug 2005
- Posts
- 986
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks!
You'll have to do two things:
1. Install http://rubyforge.org/projects/ruby-dbi/
2. Change the adapter to sqlserver, like this:
Code:ActiveRecord::Base.establish_connection( :adapter => "sqlserver", :host => "the_host :username => "root", :password => "******", :database => "dbname" )
Here is more information:
http://wiki.rubyonrails.com/rails/pa...osoftSQLServer
Bookmarks