File upload with Behat, Mink & PhantomJS - selenium

I am trying to upload a file using Behat. Therefore I wrote this simple HTML page:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<form method="post" enctype="multipart/form-data">
<input type="file" name="file" id="file" /><br />
<input type="submit" />
</form>
</body>
</html>
and a simple Behat feature:
Feature: test
Scenario: Some Test
Given I am on "/upload.php"
And I attach the file "/path/to/tile" to "file"
When the I attach the file ... to ... phrase is executed, the selenium 2 driver generates a curl request and sends it to PhantomJS: http://localhost:4444/wd/hub/session/5b9a8630-ed8e-11e4-956f-956a9ce75127/element/:wdc:1430215640681/value with params: {"value":["\/path\/to\/file"]}
The request does not terminate unless aborting it and PhantomJS does not react on the request in any way.
I already searched through the net and found several threads saying that it does work and several saying that does not work including an issue on github (https://github.com/detro/ghostdriver/issues/282) which was closed and reopend multiple times.
Versions:
PhantomJS: 2.0.0
Behat: 3.0.15
Mink: 1.6.1
Mink-Selenium2-Driver: 1.2.0
Does anyone know a working solution for this problem?

Could this behaviour exist due to inability to upload files that is a known bug with PhantomJS v 2.0.0?
Basically, a change made in Qt 4.8 and incorporated subsequently in Qt 5.0 prevented clicking on file input elements that were not caused by user gestures.
The solution is discussed further in the issue thread.
To quote, you have to comment one if condition in
/src/qt/qtwebkit/Source/WebCore/html/FileInputType.cpp
//if (!ScriptController::processingUserGesture())
// return;
then compile the binary.

Related

PrimeFaces fileUpload not working with dropZone

I'm unable to upload a file that is dragged onto an inputTextarea component registered as a dropZone. Here's my code, based on the PrimeFaces demo example - am I missing something? The file uploads when it is dragged onto the fileUpload component itself.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head></h:head>
<h:body>
<h:form enctype="multipart/form-data">
<p:inputTextarea id="customDropZone" />
<p:fileUpload
dropZone="customDropZone"
widgetVar="docUploader"
listener="#{test.uploadDocument}"
sizeLimit="100000"
allowTypes="/(\.|\/)txt$/"
/>
</h:form>
</h:body>
</html>
The setup is Glassfish 6.2 / Primefaces 10 / Mojarra 3.0.1.
The dropZone attribute was added to PrimeFaces 11 (so, it's not available in 10). Note that currently the showcase shows PrimeFaces 11.0.0-RC1. So, upgrade if you want to use this feature.
See also:
https://github.com/primefaces/primefaces/issues/7279
https://github.com/primefaces/primefaces/blob/master/docs/11_0_0/gettingstarted/whatsnew.md
https://github.com/primefaces/primefaces/pull/7283

ELM : Compile ELM page to JS

after creating an ELM page and running it successfully using (elm-reactor),
I have compiled it to generate the js file and open it using browser.
using the following command : elm-make pageName.elm --output target.js.
anyway the target.js page is generated successfully but when opening it using the browser it does not show the desired outcome instead it displays the source code as per the below screen shot
Run elm-make pageName.elm without --output target.js and open produced index.html
Alternatively, create your own *.html file and embed target.js via <script> tag, as you would normally do it for any other JavaScript files:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>My app</title>
<script src="target.js"></script>
<script>
// Run the application manually.
Elm.Target.fullscreen();
<script>
</head>
<body>
</body>
</html>
Assuming that the name of the entry module is Target and you want it to take over the whole page.

Link to a html file within a repository from trac wiki

I am attempting to link from my wiki to web documentation within the source repository. This functionality I think is provided by using "export" links, e.g.
[export:path/to/file/index.html]
(after setting [browser] render_unsafe_content = yes)
However, when I do this I get the following browser error:
This page contains the following errors:
error on line 17 at column 10: Opening and ending tag mismatch: link line 0 and head
Below is a rendering of the page up to the first error.
(followed by a small snippet of the html page I'm trying to display).
I'm using trac v 1.1.
(see also this related question: How to link to html file in Trac)
UPDATE:
It seems using export does work with other html files, specifically, there's no problem with an xhtml document starting:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
but I am seeing issues with a (valid) html5 document starting:
<!DOCTYPE html>
<html lang="en">
<head>
which I think trac is attempting to parse as xml and then failing.
To create a hyperlink to a file within your repository you can simply use the following wiki syntax:
[browser:<path> <label>]
Where path is the path to the file within your repository and label is the text to be displayed for the link.

Selenium IDE - best way to not repeat actions that are common for all test cases

For all my Selenium IDE TCs I have a common step of logging in using username, password and logging out at the end for each TC.
The best way I can think of is
creating the user id, password, base url as variables in a common file. That way I don't have to repeat the steps common for all test cases and if the user ID or base url change - I dont have to modify each and every TC.
Was also looking at robot framework to solve this but could not figure it.
Thanks
creating the user id, password, base url as variables in a common file
You are totally right! Also you can create separate files for actions that will be repeated ("methods") and organize them into different folders. Then compose different test suites with these files (use relative paths like ../../../../). In test suite folder you can store file with variables that concern only this test suite and test suite file itself.
For example, create Authentication folder with Login.html, Logout.html test cases. Test suite will be look something like that:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta content="text/html; charset=UTF-8" http-equiv="content-type" />
<title>Test Suite</title>
</head>
<body>
<table id="suiteTable" cellpadding="1" cellspacing="1" border="1" class="selenium"><tbody>
<tr><td><b>Test Suite</b></td></tr>
<tr><td>StoredVariables</td></tr>
<tr><td>Login</td></tr>
...
<tr><td>SomeActions</td></tr>
...
<tr><td>Logout</td></tr>
</tbody></table>
</body>
</html>
Variables will live during all test suite.
It seems you might be better off with Selenium RC or Selenium 2 (WebDriver) which will allow you to have an initialise to setup id, password and setup files? A few examples are shown in this post which I came across earlier: Selenium Test - preserve session across multiple test runs
Sorry if these are things you already knew :)

Why is Selenium only running the first test from my test suite?

I'm using Selenium stand alone server v2.3.0 on Windows XP (sp2). I'm noticing that when I try and run my html suite against Firefox, only the first test gets executed and then the Selenium Runner just sits there without doing anything. The command I use is
java -debug -jar c:/selenium/selenium-server-standalone-2.3.0.jar -port 4444 -userExtensions c:/selenium/user-extensions.js -htmlSuite *chrome http://www.stage.mycliusa.com c:/selenium/test/suite.html c:/selenium/report2.html
The HTML suite file contents are below. Interestingly, when I run the same command switching "*chrome" with "*iehta," everything runs fine. Any ideas why the Firefox tests are stopping after the first test? - Dave
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta content="text/html; charset=UTF-8" http-equiv="content-type" />
<title>mycli USA Tests - Critical Path/Live/EX</title>
</head>
<body>
<table id="suiteTable" cellpadding="1" cellspacing="1" border="1" class="selenium"><tbody>
<tr><td><b>mycli USA Tests - Critical Path/Live/EX</b></td></tr>
<tr><td>mycliConfigNewEXJourneyAWD</td></tr>
<tr><td>mycliContactRetailerOldEX</td></tr>
<tr><td>mycliRAQOldEX35Base</td></tr>
<tr><td>mycliPreApprovedEX35</td></tr>
<tr><td>mycliContactRetailerNewEX35AWD</td></tr>
<tr><td>mycliJMLHandraiserEX</td></tr>
<tr><td>mycliRABEBrochureEX</td></tr>
<tr><td>mycliContactRetailerNewEXJourneyAWD</td></tr>
<tr><td>mycliConfigNewEX35Base</td></tr>
<tr><td>mycliConfigNewEX35AWD</td></tr>
<tr><td>mycliRABMailEX</td></tr>
<tr><td>mycliContactRetailerNewEX35Base</td></tr>
<tr><td>mycliRABBothEX</td></tr>
<tr><td>mycliSATDEX</td></tr>
<tr><td>mycliConfigOldEX35</td></tr>
<tr><td>mycliContactRetailerNewEX35Journey</td></tr>
<tr><td>mycliConfigNewEXJourney</td></tr>
</tbody></table>
</body>
</html>
The problem turns out to be Selenium (using the -htmlSuite option) isn't able to properly process files without an ".html" extension. When I renamed the files and ran the tests again, they sailed right through. This bug is documented here -- http://code.google.com/p/selenium/issues/detail?id=1208.
First function starting with "test"+fucntionName will work and so call all functions within it like
this.f1();
this.f2()
Inside that function !