Can intern test JavaScript dependent on HTML markup? - intern

I'd like to be able to test a widget in the same way that Dojo's DOH could.
An example of this is for example dijit tests e.g. https://github.com/dojo/dijit/blob/master/tests/Fieldset.html
DOH runs in the browser and can test if a declarative widget has been created, test properties on the widget etc
Is this possible with intern using runner.js or would I have to use webdriver and use an execute eval e.g. http://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/execute (which I really don't want to do)
Any examples I've seen on this rely on programatically creating the markup, using eval wouldn't achieve what I want to do

I would use PhantomJS for this. It looks like they have documentation for that here: https://github.com/theintern/intern/wiki/Using-Intern-with-PhantomJS

Related

Geb Test Framework -- get raw page content

Is there a way to get the raw page content using Geb ?
For example the following test should work (but PhantomJS seems to bad the JSON response with HTML code):
def "Get page content example -- health check"() {
given:
go "https://status.github.com/api/status.json"
expect:
assert driver.pageSource.startsWith('{"status":"(good)"')
}
Note that, YES I understand that I could just NOT use Geb, and simply just make a URL call in Groovy, but for a number of reasons I want to explicitly use Geb (one of the reasons is dealing with redirects).
What a web browser renders when it loads a URL depends on the browser itself, there is nothing you can do about it. PhantomJS uses the same engine as Chrome, thus the two of them render some HTML around the JSON. IE, Edge and Firefox do the same, by the way. HtmlUnit for a change renders the pure JSON. But why bother with exact matches like startsWith if you can just use a regular expression? It is much more flexible:
expect:
driver.pageSource =~ /"status":"good"/
This should work in all browser engines.
P.S.: You do not need assert in then: or expect: blocks, that is the beauty of Spock/Geb.

Groovy script gets cached after being executed by Sling

I was looking at the Sling documentation and noticed that Groovy scripts can be used to render a component, similar to the way JSP or HTL can be used.
Now, I'm not very fond of the idea and I think that the place of Groovy code should be in OSGi bundles but I decided to try and see what I can do with these scripts.
I created a simple component with a dialog that has a single property, text. Let's call this component simpleGroovy. Here's the rough structure (dialog details omitted for brevity).
/apps/example/core/components/simpleGroovy
|
|- cq:editConfig
|- dialog
|- simpleGroovy.groovy
The contents of simpleGroovy.groovy are something like this:
println "Hello Groovy! Rendering the contents of ${resource.path} since 2017"
As expected, the script executed just fine, GStrings and all.
However, when I change the script after making the first request, I keep getting the same output. If I rename the script and use a selector, I get an output matching the current state of the script. Until the first request when this also gets cached.
I'm curious as to the cause of this. I suppose the Groovy script gets compiled to a Java class at some point and that the class gets cached somewhere.
I'm on AEM 6.2 so I checked the contents /crx-quickstart/launchpad/felix/bundle305/data/classes (bundle 305 is the id of the org.apache.sling.commons.fsclassloader in my environment).
I can see the compiled classes for JSP and HTL scripts from my example app but there seems to be nothing related to my Groovy script in any of those folders.
I also looked up the ID of my Groovy Runtime (groovy-all) bundle but there's no data folder in there. However, restarting the Groovy Runtime bundle allows me to see the changes I made to my script.
Is there an easier way I could cause the Groovy script to be recompiled? What exactly gets cached and where does it sit?
sling uses Groovy provided GroovyScriptEngine, which stores compiled scripts in memory, see scriptCache.
I dont think there is anything available ootb to clear scriptCache. you will have to write your own groovy scriptengine and probably classloader. (not 100% sure about this though)

Link to website in Gtk.MenuBar using Glade

What is the best way to create a menuitem (for the Gtk.MenuBar) that should open the default browser with a new tab and loading an URL?
Is it possible to do that in Glade directly or do I need to create that function in the program code itself? Is there a preferred way in Python 3 to do that?
After a lot of searching for a Glade-only solution, I think that Gtk.Menuitem doesn't have a URL-open option. I now just defined on_menuitem_clicked-function that uses:
webbrowser.open_new_tab()
from the standard library.

Inserting a news-feed widget to a page

I have a page I'd like to embed a news-feed widget into (so that the feed from some remote site will be displayed in my site).
While there are quite a few free news-feed widgets available out there (a partial list is here: http://allwebco-templates.com/support/S_script_newsfeed.htm), They all require insertion of complex code into the html page, while all the parameters are hard-coded into the generated code, which looks something like this:
insertedWidgetText = "<script id=\"scrnewsblock10795953\" type=\"text/javascript\">...script specific parameters go here...</script>"
let feedWidget = toWidgetBody [hamlet|#{preEscapedText insertedWidgetText}|]
This doesn't integrate well with Yesod's approach as it requires specifying to Hamlet that the content is preEscapedText, which in turn disables the ability to use Hamlet's processing to alter parameters of the widget dynamically (So in case I want the widget to use a different source, for example, I need to statically change the quoted text and cannot use Hamlet's variable substitution).
Of course I could do some text manipulation myself, tailor built for the widget I'm using, but that doesn't seem like the "right" solution (especially if I want to have the embedded text in some external file and not in the middle of my code as in the example above).
Can the above mentioned issue have a better solution than the one I thought about?
Is there an implementation of a news-feed widget in Haskell/Yesod that I can use as a plugin?
Note: I'm a very poor javascript programmer, but solutions in that direction are also welcomed.
Thanks,

Node.JS testing DOM with Mocha?

I'm trying to do some simple view testing in my Node.JS app using the Mocha testing framework...
For example, I want to test that the <ol> on the page has n <li> children, given the number of records I setup in my test.
I tried using Apricot to do this, and while I got it to work, when it fails the error messages are fantastically unhelpful... also, it doesn't always work.
What I'd love is a simple way to test the response body for HTML elements, so I can determine if they match the data they should be displaying.
Here's my test in it's current state: https://gist.github.com/2330685
Anyone know how I can do this?
Posting the comment as answer as well.
For DOM manipulation or element finding, I am suggesting the great library cheerio, which can load the html as string and then use jQuery-like selectors. Also it seems to be really lightweight. I replaced the JSDOM with request + cheerio combination.

Resources