dongliuliu0385 2011-11-08 14:40
浏览 49
已采纳

Javascript无法在<input type =“text”>中获取Sahi输入的文本

TL;DR : In a Behat+Mink (@javascript w/ Sahi) scenario, Sahi enter some text in an <input>, and the Javascript in the page isn't able to get what was entered by Sahi

UPDATE:

Solution : downloading the last version of Sahi fixed the problem. Whatever the bug was, it has been corrected.

Context

I'm building a little demo website, to show my team what Behat+Mink can do. There's a few pages, where one can input the size of a square and get the perimeter of this square. One page is using plain old POST method, another page is using Javascript to calculate the perimeter

Url of the "JS page" : http://behatdemo.widop.com/js-square

To show my team that testing javascript is possible, I'm using Sahi as Mink driver, however it doesn't seems to work. I wrote a scenario where a user input 6 as the square side length, and get 24 as perimeter ([link to file on github] (https://github.com/clemherreman/behatdemo/blob/master/features/js_square.feature#L7))

@javascript
Scenario: Inputting a valid side size
Given I am on "/js-square"
When I fill in "side" with "6"
And I press "Calculate"
And I wait for the result to appear
And I wait a little
Then I should see "Perimeter (using js): 24 cm"

Note: And I wait a little is a debug steps that waits 10 seconds, to be able to look at what is displayed on the Sahi firefox window

Problem

It seems that the snippet of javascript that calculate the perimeter isn't able to get the 6 inputed by Sahi. Here is the code ([link to file on github] (https://github.com/clemherreman/behatdemo/blob/master/website/views/js-square.twig#L27))

Instead of having "Perimeter (using js): 24 cm", I get a "Perimeter (using js): Error cm".

(function($) {
  $('form').submit(function(e) {
    e.preventDefault();
    // #side is a <input type="text"> tag, where user input a square side length
    var side = parseFloat(jQuery('#side').val()) || NaN;
    var perimeter = side*4.0 || 'Error';
    $('#sidebar').text('Perimeter (using js): '+perimeter+ ' cm');
  });
})(jQuery);

Debug/Ideas

After some investigation, it turns out that jQuery('#side').val()returns an empty string, which is why I get a "Error" displayed, instead of the perimeter. It seems that Javascript isn't able to get what was inputed by Sahi during the Scenario.

I'm pretty stuck on this one, I feel like I'm missing something.

Links :

Versions:

  • Behat: 2.1.2
  • Mink: 1.1.1
  • Sahi: 3.5
  • PHP: 5.3.6
  • 写回答

1条回答 默认 最新

  • douyun6399 2011-11-09 09:44
    关注

    I was not able to reproduce your error, everythig went fine on my Behat/Mink/Sahi setup : http://screencast.com/t/2rTHo7jj

    Scenario passed

    I'm using Sahi 3.5 with Behat 2.1.2 and Mink 1.1.1 on OSX With latest version of Chrome & PHP 5.3.8-ZS5.5.0

    Try running your test under Chrome with :

    default:
      context:
        parameters:
          base_url: YOURBASEURL
          browser: chrome
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测