I am new new in Watir, Rspec testing and i am just getting familiar with it. I found one test on internet, combination of Rspec and watir but id does nothing. it throws error require 'spec' does not exist. I have rspec 2.12 installed. Did I miss something here, do i need to install something? Rspec scripts are working as well as watir but this combination not.
require 'watir'
require 'spec'
describe "Google" do
before :all do
#browser = Watir::Browser.new
#browser.goto "http://google.com"
end
it "has word 'Google' on main page" do
#browser.text.should include("Google")
end
it "has word 'Bing' as it's title" do
#browser.title.should == "Bing"
end
after :all do
#browser.close
end
end
"I found one test on internet" does not help. Please provide link to the page.
Also, you did not say how you run the script. As far as I remember, to run RSpec 1.x scripts you had to do spec file_name.rb, and with RSpec 2.x you have to do rspec file_name.rb. That could be the problem.
Related
I've just learned the basics on how to make modulefiles for loading software on my cluster. Other environment modules (created by admins) print a message upon loading:
$ module load Name
Welcome to Name/version.1.2.3
How do I add this to the modulefile? I like the quick confirmation that I've indeed loaded the module I intended. I've tried a few things from the man page (ex module-info name) but no luck (or I'm doing it wrong).
Thanks
If you "only" want the message to print when running module load (but not when running module unload or other commands), then you can use a statement like this:
if [ module-info mode load ] {
puts stderr "your text here"
}
Reference: https://sourceforge.net/p/modules/mailman/message/34597600/
You can add puts stderr statements to modulefile, for printing messages to terminal.
puts stderr "** INFO: 'Welcome, Module loaded'"
I have the following setup to test a directive:
beforeEach(inject(function($compile, $rootScope, $injector) {
$httpBackend = $injector.get('$httpBackend');
var html = '<password-strength-bar password-to-check="password"></password-strength-bar>';
scope = $rootScope.$new();
elm = angular.element(html);
$compile(elm)(scope);
$httpBackend.expectGET('l10n/en.js').respond({});
$httpBackend.expectGET('tpl/page_signin.html').respond({});
}));
This works fine on a Mac. However, when I run the same code on Linux, it fails with the following error. It is a headless Linux box, but I'm using PhantomJS as my "browsers" in karma.conf.js.
Error: Unsatisfied requests: GET tpl/page_signin.html
I verified that both operating systems are using the same version of Node.
On a similar note, I've installed Chrome and Xfvb (via Jenkins) to run my e2e tests driven by Protractor. The following works fine when running on my Mac locally, but fails on Linux.
it('should render signup when user clicks on "Create one" link', function () {
var signupLink = element(by.linkText('Create one'));
expect(signupLink.isDisplayed()).toBe(true);
signupLink.click();
expect(element.all(by.css('.wrapper')).first().getText()).
toMatch(/Hi there, we're so glad you're here./);
In Jenkins (on Linux), the error is:
Failures:
1) account signup should render signup when user clicks on "Create one" link
Message:
[31m Expected '' to match /Hi there, we're so glad you're here./.[0m
Stack:
Error: Failed expectation
at Object.<anonymous> (/var/lib/jenkins/jobs/myapp/workspace/tests/e2e/account.js:27:17)
at runMicrotasksCallback (node.js:337:7)
Any idea why tests would run fine on Mac, but not on Linux?
This turned out to be caused by using by.linkText('Create one') for my Protractor test. Once I added an id to the link and used by.id('create-account'), it worked.
I also found that using $('.alert') or by.css('alert') doesn't work nearly as well as by.id. Particularly when you click on a button and wait for something to appear on the next screen. For example:
var alert = element(by.id('success'));
browser.driver.wait(protractor.until.elementIsVisible(alert));
I was playing around with selenium via rspec but was dissatisfied and I saw recommendations for poltergeist. When I try to run it with my tests, it seems like the poltergeist driver doesn't show up where it should. I was a little confused where rack test fits in with poltergeist but I tried many different things. I then found this simple example and tried to get that to work but still no luck. I am using jruby on windows.
I am using the example found here: https://gist.github.com/pzol/1607842
I moved all my code into one file, there is no spec helper for this case
I did install phantomjs and ran a little hello world example for phantomjs and it is in my path
require 'rspec'
require 'capybara/rspec'
require 'capybara/poltergeist'
Capybara.javascript_driver = :poltergeist
Capybara.register_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new(app, debug: true)
end
describe 'poltergeist', :type => :request, :js => true do
it 'should find github poltergeist in google' do
visit 'http://www.google.com/'
fill_in "q", :with => "github poltergeist"
click_button "btnK"
page.should have_content 'jonleighton/poltergeist'
end
end
jruby -S rspec poltergeist-test2.rb
F
Failures:
1) poltergeist should find github poltergeist in google
Failure/Error: visit 'http://www.google.com/'
NoMethodError:
undefined method visit' for #<RSpec::Core::ExampleGroup::Nested_1:0x4324
4fd9>
# ./poltergeist-test2.rb:18:in(root)'
Finished in 0.01 seconds
1 example, 1 failure
Failed examples:
rspec ./poltergeist-test2.rb:17 # poltergeist should find github poltergeist in
google
hmmm, well I was looking at capybara docs some more and I changed this line:
describe 'poltergeist', :type => :request, :js => true do
to this line, where I made :type to be :feature and now it seems to be ok ..
describe 'poltergeist', :type => :feature, :js => true do
Seems in my google searches the other day I saw something on that but wasn't sure and at the moment I am not clear what the difference is but I am making progress it appears
I've been playing around with Cucumber for about three weeks now, and everything works well, except this little thing here.
Whenever I run my tests with e.g. cucumber checkout.feature --tags #monthly, I get the following on my console after the test have run successfully:
invalid option: --tags
Test::Unit automatic runner.
Usage: /Users/myusername/.rvm/gems/ruby-2.0.0-p0/bin/cucumber [options] [-- untouched arguments]
-r, --runner=RUNNER Use the given RUNNER.
(c[onsole], e[macs], x[ml])
--collector=COLLECTOR Use the given COLLECTOR.
(de[scendant], di[r], l[oad], o[bject]_space)
-n, --name=NAME Runs tests matching NAME.
(patterns may be used).
--ignore-name=NAME Ignores tests matching NAME.
(patterns may be used).
-t, --testcase=TESTCASE Runs tests in TestCases matching TESTCASE.
(patterns may be used).
--ignore-testcase=TESTCASE Ignores tests in TestCases matching TESTCASE.
(patterns may be used).
--location=LOCATION Runs tests that defined in LOCATION.
LOCATION is one of PATH:LINE, PATH or LINE
--attribute=EXPRESSION Runs tests that matches EXPRESSION.
EXPRESSION is evaluated as Ruby's expression.
Test attribute name can be used with no receiver in EXPRESSION.
EXPRESSION examples:
!slow
tag == 'important' and !slow
--[no-]priority-mode Runs some tests based on their priority.
--default-priority=PRIORITY Uses PRIORITY as default priority
(h[igh], i[mportant], l[ow], m[ust], ne[ver], no[rmal])
-I, --load-path=DIR[:DIR...] Appends directory list to $LOAD_PATH.
--color-scheme=SCHEME Use SCHEME as color scheme.
(d[efault])
--config=FILE Use YAML fomat FILE content as configuration file.
--order=ORDER Run tests in a test case in ORDER order.
(a[lphabetic], d[efined], r[andom])
--max-diff-target-string-size=SIZE
Shows diff if both expected result string size and actual result string size are less than or equal SIZE in bytes.
(1000)
-v, --verbose=[LEVEL] Set the output level (default is verbose).
(important-only, n[ormal], p[rogress], s[ilent], v[erbose])
--[no-]use-color=[auto] Uses color output
(default is auto)
--progress-row-max=MAX Uses MAX as max terminal width for progress mark
(default is auto)
--no-show-detail-immediately Shows not passed test details immediately.
(default is yes)
--output-file-descriptor=FD Outputs to file descriptor FD
-- Stop processing options so that the
remaining options will be passed to the
test.
-h, --help Display this help.
Deprecated options:
--console Console runner (use --runner).
I probably didn't need to put all of that here, but I wanted to give you an impression of how much text appears on my screen after each test, which can be a bit distracting.
Here is my setup:
Gemfile
source 'https://rubygems.org'
gem "rspec"
gem "cucumber"
gem "capybara"
gem "capybara-webkit"
gem "selenium"
gem "selenium-client"
gem "selenium-webdriver"
env.rb
require_relative '../../../config.rb'
require 'capybara/cucumber'
require 'capybara/rspec'
Capybara.app_host = AT_ROOT
Capybara.default_driver = :selenium
Capybara.javascript_driver = :webkit
Capybara.default_wait_time = DEFAULT_WAIT_TIME
Capybara.ignore_hidden_elements = IGNORE_HIDDEN_ELEMENTS
# Define window size of the browser here
Capybara.current_session.driver.browser.manage.window.resize_to(DEFAULT_WINDOW_HEIGHT, DEFAULT_WINDOW_WIDTH)
I couldn't find any connection to the Test::Unit automatic runner in the console output, but apparently it's got something to do with it.
Do you have any idea what that could be? I found some threads related to this issue, but they didn't help me unfortunately.
Thank you
Try
cucumber features -t #monthly
I am not able to click on a java script alert using watir 2.0.4. This is the alert that i am trying to click on. And the line of the code that i am using to click on the javascript alert is
browser.javascript_dialog.button('OK').click
All i get is the error message
undefined method `javascript_dialog' for #<Watir::IE:0x46efcb8> (NoMethodError)
Do i need to install some specific gems for it to work? I thought watir is all i need and i have it already installed. Is it not supported with Watir 2.0.4 ? Please find my gems below.
I also tried supressing the java scrit alert by adding the following lines before clicking on the javascript alert. It did n't work either. Waiting for your valuable input. Thanks!
browser.execute_script "window.confirm = function() { return true; }"
browser.execute_script "window.alert = function() { return true; }"
browser.execute_script "window.prompt = function() { return true; }"
* LOCAL GEMS *
builder (3.0.0)
commonwatir (2.0.4)
ffi (1.0.10 x86-mingw32)
hoe (2.12.3)
minitest (1.6.0)
nokogiri (1.5.0 x86-mingw32)
rake (0.8.7)
rautomation (0.6.3)
rdoc (2.5.8)
s4t-utils (1.0.4)
user-choices (1.1.6.1)
watir (2.0.4)
win32-api (1.4.8 x86-mingw32)
win32-process (0.6.5)
windows-api (0.4.0)
windows-pr (1.2.1)
xml-simple (1.1.1)
The Watir RDoc list of methods does not have .javascript_dialog listed.
It does however have .java_dialog_window
I would try using
browser.javascript_dialog_window.button('OK').click
I'm not sure if the method got renamed for some reason and the popup page in the wiki did not get updated, or if that page has had the wrong method name all along. Let me know if this works and if so I can bug TPTB to figure out what needs to get changed.