question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

test <input type="hidden"> will block the testcase

See original GitHub issue

This is my view, I want to test.

<h1>Request Group Rate</h1>
<form>
    <input type="hidden" name="referrer">
    Name: <input type="text" id="fieldName" name="name"><br>
    Group size: <input type="text" name="groupSize"><br>
    Email: <input type="email" name="email"><br>
    <input type="submit" value="Submit">
</form>
<script>
 $(document).ready(function() {
     /* document.referrer: Returns the URI of the page that links to this page */
     $('input[name="referrer"]').val(document.referrer);
 });
</script>

I wrote my test like this:

var Browser = require('zombie'),
    assert = require('chai').assert;

var browser;

suite('Cross-Page Tests', function() {
    setup(function() {
         browser = new Browser();
    });


    test('requesting a group rate quote from the hood river tour page ' +
         'should populate the referrer field', function(done) {
             var referrer = 'http://localhost:3000/tours/hood-river';
             browser.visit(referrer, function() {
                 browser.clickLink('.requestGroupRate', function() {
                     browser.assert.input('form input[name="referrer"]', referrer);
                     done();
                 });
             });
         });

then, I run the test, I found the test will block at ** browser.assert.input(‘form input[name=“referrer”]’, referrer); ** (I annotate this line, and the test runs OK).

My package.son:

{
  "name": "meadowlark",
  "version": "1.0.0",
  "description": "A travel website",
  "main": "meadowlark.js",
  "scripts": {
    "test": "grunt"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/zwb-ict/meadowlark.git"
  },
  "keywords": [
    "node"
  ],
  "author": "zwb.ict@gmail.com",
  "license": "MIT",
  "bugs": {
    "url": "https://github.com/zwb-ict/meadowlark/issues"
  },
  "homepage": "https://github.com/zwb-ict/meadowlark",
  "dependencies": {
    "express": "^4.12.3",
    "express-handlebars": "^2.0.0"
  },
  "devDependencies": {
    "chai": "^2.2.0",
    "grunt": "^0.4.5",
    "grunt-contrib-jshint": "^0.11.2",
    "grunt-exec": "^0.4.6",
    "grunt-istanbul": "^0.5.0",
    "grunt-mocha-test": "^0.12.7",
    "istanbul": "^0.3.13",
    "mocha": "^2.2.4",
    "zombie": "^3.0.0"
  }
}

Issue Analytics

  • State:open
  • Created 8 years ago
  • Comments:5

github_iconTop GitHub Comments

3reactions
YoussefKababecommented, Sep 27, 2015

I have the same problem, I still don’t know why the document.referrer stays empty, but I managed to get the referrer from headers using this:

console.log(browser.resources[0].request.headers._headers);

=> [ [ 'referer', 'http://localhost:3000/tours/hood-river' ],
  [ 'accept', 'text/html,*/*' ],
  [ 'content-type',
    'application/x-www-form-urlencoded;charset=UTF-8' ] ]

I think the problem is coming from Zombie itself because when trying this manually in browser, document.referrer is set correctly!

0reactions
arjunlubanacommented, Jan 3, 2022

Has the fix been merged or not? I am having a similar problem with document.referrer returning an empty string.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Introducing: Hidden Test Cases - by John Kelly
One good way to prevent students from cheating the system is to hide inputs and outputs to the test cases. This prevents the...
Read more >
<input type="hidden"> - HTML: HyperText Markup Language
The <input> element's value attribute holds a string that contains the hidden data you want to include when the form is submitted to...
Read more >
Issues with matching values in forms, and hidden fields #1017
Hello, I am currently using rspec for testing our application. This is the HTML that we are testing against:
Read more >
Best way to test input value in dom-testing-library or react ...
One final alternative for testing the value is to find the input by role. This won't work in your example's case unless you...
Read more >
Preventing tampering with hidden inputs
Since they are not rendered visible, hidden inputs are sometimes erroneously perceived as safe. But similar to session cookies, hidden form inputs store...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found