Here are some key differences between Mechanize and Selenium/Webkit for browser automation and testing:
Mechanize:
- Pure Ruby, no external dependencies
- Very fast as it doesn't launch a browser
- No support for JavaScript
- Easy to programmatically interact with forms, links, etc.
Selenium/Webkit:
- Requires a browser to be launched (Firefox, Chrome, etc.)
- Support JavaScript execution and dynamic content
- Slower than Mechanize due to actual browser operations
- Can test browser-side functionality like CSS rendering
- Easy to programmatically interact and automate browser
In summary:
- Mechanize is faster but lacks JavaScript support
- Selenium
2. What is MongoDB?
• A No-SQL database
• Document oriented
• Open Source
• Written in C++
3. Document Oriented?
• Documents are stored in collections > db.posts.findOne()
{
_id : ObjectId("4e77bb3b8a3e000000004f7a"),
when : Date("2011-09-19T02:10:11.3Z",
author : "alex",
•
title : "No Free Lunch",
No JOINS: embedded text : "This is the text of the post. It could be very long.",
tags : [ "business", "ramblings" ],
votes : 5,
voters : [ "jane", "joe", "spencer", "phyllis", "li" ],
comments : [
•
{ who : "jane", when : Date("2011-09-19T04:00:10.112Z"),
No JOINS: linked comment : "I agree." },
{ who : "meghan", when : Date("2011-09-20T14:36:06.958Z"),
comment : "You must be joking. etc etc ..." }
]
}
4. Document Oriented?
• Documents are stored in collections > db.posts.findOne()
{
_id : ObjectId("4e77bb3b8a3e000000004f7a"),
when : Date("2011-09-19T02:10:11.3Z",
author : "alex",
•
title : "No Free Lunch",
No JOINS: embedded text : "This is the text of the post. It could be very long.",
tags : [ "business", "ramblings" ],
votes : 5,
voters : [ "jane", "joe", "spencer", "phyllis", "li" ],
comments : [
•
{ who : "jane", when : Date("2011-09-19T04:00:10.112Z"),
No JOINS: linked comment : "I agree." },
{ who : "meghan", when : Date("2011-09-20T14:36:06.958Z"),
comment : "You must be joking. etc etc ..." }
]
}
5. Document Oriented?
• Documents are stored in collections
> db.posts.findOne()
•
{
No JOINS: embedded _id : ObjectId("4e77bb3b8a3e000000004f7a"),
when : Date("2011-09-19T02:10:11.3Z",
author : "alex",
title : "No Free Lunch",
text : "This is the text of the post. It could be very long.",
•
tags : [ "business", "ramblings" ],
No JOINS: linked votes : 5,
voters : [ "jane", "joe", "spencer", "phyllis", "li" ],
comments : [
{ who : "jane", when : Date("2011-09-19T04:00:10.112Z"),
comment : "I agree." },
•
{ who : "meghan", when : Date("2011-09-20T14:36:06.958Z"),
links are references to other documents and ]
comment : "You must be joking. etc etc ..." }
are processed by the client. }
10. Cool features
• Schemaless
• Atomic operations The GridFS spec provides a mechanism for
transparently dividing a large file among multiple
• Map/Reduce
documents. This allows us to efficiently store large
objects, and in the case of especially large files,
such as videos, permits range operations (e.g.,
• Fast, in-place updates fetching only the first N bytes of a file).
• GridFS
11. Querying
• // A post with title “Mongo”
db.posts.find({'title': 'Mongo'})
• // All posts about tennis, but without comments
db.posts.find( { tags : 'tennis' }, { comments : 0 } );
• // last 5 comments
db.posts.find({}, {comments:{'$slice': -5}})
• // just the likes of the comments
db.posts.find({}, {'comments.$.likes': 1}
12. Use it for
• It’s schemaless features (e.g. for prototyping)
• It’s horizontal scalability (with auto-sharding)
• To store and stream large files (with gridfs)
• To make ultra-fast, single query updates
14. Scenarios for browser testing
Feature: User Registration and Logging in
A User should be able to create an account.
A User should be able to log in with a new account.
A User should be able to create a profile after logging in for the first time.
Scenario: Registration with a normal account.
Given I sign up as a new user with email@example.com/secret
Then I should be signed in
And I sign out
Scenario: Log in with a new account
Given I sign up as a new user with email@example.com/secret
Then I should be signed in
Then I sign out
And I sign in with email@example.com/secret
Then I should be signed in
And I sign out
Scenario: Create a profile with a new account
Given I sign in as a new user
Then I should see "create your profile"
And I fill in "profile_name" with "My Name"
And I fill in "profile_about" with "I am a long green vegetable that goes well with salads."
And I select an avatar file
And I press "Save"
Then I should see "Profile was successfully updated."
And I sign out
17. Mechanize, Selenium / Webkit
• Mechanize: fast, but no javascript support
• Selenium, javascript support, but sloooow
• Webkit, javascript support, less slooow