Logging frameworks for CasperJS - casperjs

Is there a way to use winston or bunyan with CasperJS ? I couldn't get either to load correctly.
I tried the proxy method described in Can't require Underscore with CasperJS, but that also didn't work.

Related

How to find out if a page is running in Phantom JS (or Poltergeist)?

How to test within Javascript whether it is running Phantom JS (via Poltergeist) or on a regular browser?
Use case: Suppress logging during testing.
Using Poltergeist, Capybara, Ruby.

What's the difference between Selenium XPath and FF XPath?

I'm writing some tests for our web application. When I use this XPath inside the Firefox XPath-Checker plugin it just works fine:
//div[contains(#class, "my-class") and #data-custom-attr="id")]
But If use this in selenium code like so:
(new WebDriverWait(driver, MAX_TIMEOUT_FOR_ELEMENT_LOADING_IN_SECONDS)).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//div[contains(#class, \"my-class\") and #data-custom-attr=\"id\")]"));
a timeout exception is throwen.
Why does the xpath query works directly in the browser but not in the selenium test? Is there documentation on what I have to consider?
As side note: if I use the exact path /html/body/div/... etc. it does work. And a css selector pendant to my example above doesn't work either.
It should work, what's the max wait time you given in code.

How do I test a Curl based FaceBook API implementation?

I wrote my own FaceBook library that uses actual Curl requests, not libcurl.
Is there a way to test it? I'm asking this because most solutions involve using something like fakeweb which as far as I can tell will not work here.
The existing code can be found on my github page.
One approach would be to use a different host/port in test mode (eg localhost:12345)
Then in your test run a sinatra or webrick servlet on that port that you configure to respond to the requests your code should be making
You could mock Request.dispatcher with an expected behavior, pretty much like Fakeweb would do.
There are a few examples on this file, specially https://github.com/chrisk/fakeweb/blob/master/lib/fake_web/ext/net_http.rb#L44.
When running your tests/specs, monkey-patch the run method of your Request class to hook into the Marston VCR library. See the existing library_hooks subdir for examples and ideas on how to do this -- the fakeweb implementation is a good place to start.
VCR works well with live services like Facebook's because it captures interactions "as is", and VCRs can be easily re-recorded when the services change.
I'm running into problems with your library, however. You need to require the cgi and json libraries; it also looks like it requires a Rails environment (it's failing to find with_indifferent_access on Hash).

WATIR/ FireWATIR URL consistency?

We are at the start of a project to test a new web application written in jQuery and are planning to do it using WATIR and FireWATIR.
During the proof of concepts test I've discovered differences in how WATIR and FireWATIR represent URLs, for example a script which passes in FireWATIR generates this error in WATIR.
assert_equal(expandImage.src,"../WebToolKit/images/closed.jpg")
testBrowserGadget2(WebClientHomePage) [002_pub_browser.rb:108]:
<"http://172.24.4.125:8081/WebToolKit/images/closed.jpg"> expected but was
<"../WebToolKit/images/closed.jpg">.
Is there any setting in either WATIR or FireWATIR I can enable so that the URL value is consistent between when running against IE and Firefox?
I use the uri module ...
e.g.
require 'uri'
URI.parse("http://google.com/image/path.jpg").path
=> "/image/path.jpg"
i.e.
assert_equal(URI.parse(expandImage.src).path,"../WebToolKit/images/closed.jpg")
you could use assert_match http://en.wikibooks.org/wiki/Ruby_Programming/Unit_testing

File uploads using the selenium-client gem

I am using the selenium-client gem with Webrat and Cucumber to test a rails project. I have Cucumber set up pretty much as described here: https://github.com/cucumber/cucumber/wiki/Setting-up-Selenium
My problem is that Selenium is prevented from performing file uploads. Ideally I'd like to be able to replicate webrat's 'attach_file' method. I tried dodging the issue by using selenium-client's 'type' method to type the path to the required file, but this seems to fail.
Does anyone have a sugestion for a workaround using selenium-client (i.e. not the regular Selenium gem)?
The normal selenium can't do this because browser security prevents javascript from writing to input=file elements. This is a security feature so that your password file doesnt get uploaded to hackers if you go to a site thats been hacked.
http://jira.openqa.org/browse/SEL-63 has the details
I finally figured this out.
You need to be using firefox with the chrome backend, and you need to specifiy an absolute filepath.
I ended up creating a helper module to specify the filepath, and a "fixtures" folder containing test content. Here is a gist of the solution I came up with: http://gist.github.com/214185
Therefore it is totally possible to replicate Webrat's attach_file method!

Resources