代码之家  ›  专栏  ›  技术社区  ›  Vaibhav

每当遇到Capybara函数时,在运行Cucumber测试时获取“错误的参数类型Fixnum(预期字符串)(TypeError)”

  •  0
  • Vaibhav  · 技术社区  · 6 年前

    我正在尝试在特性测试中使用水豚,但我不断遇到上述错误。然而,我的测试在涉及非水豚函数时有效。

    以下是我的环境中的设置。rb:

        Capybara.server_host = 45454
        #Capybara.server_host = host
        Capybara.app_host = 'http://localhost:45454'
        Capybara.default_driver = :poltergeist
    

    还为Phantomjs设置了PATH变量

    下面是我面临问题的步骤定义文件。

       Given(/^I navigate to home page$/) do 
         visit '/'
       end
    
      And /^I take screenshot$/ do
        page.save_screenshot
      end
    

    以下是功能文件

     Scenario: To validate the page shows up
       Given I navigate to home page
         And I take screenshot
    

    以下是输出:

     Scenario: To validate the page shows up←[90m # features/home.feature:8←[0m
     ←[31mGiven I navigate to home page←[90m         # features/step_definitions/
     home_steps.rb:8←[0m←[0m
     ←[31m      wrong argument type Fixnum (expected String) (TypeError)←[0m
     ←[31m      ./features/step_definitions/home_steps.rb:9:in `/^I navigate to 
     home
     page$/'←[0m
     ←[31m      features/home.feature:9:in `Given I navigate to home page'←[0m
     ←[36mAnd I take screenshot←[90m                 # features/step_definitions/
      home_steps.rb:12←[0m←[0m
     ←[31m      wrong argument type Fixnum (expected String) (TypeError)←[0m
    
     ←[31mFailing Scenarios:←[0m
      ←[31mcucumber features/home.feature:8←[0m←[90m # Scenario: To validate the 
     page
     shows up←[0m
    
     1 scenario (←[31m1 failed←[0m)
     2 steps (←[31m1 failed←[0m, ←[36m1 skipped←[0m)
      0m0.649s
    
    1 回复  |  直到 6 年前
        1
  •  1
  •   Thomas Walpole    6 年前

    Capybara.server_host 需要是Capybara可以将AUT绑定到的接口的主机名/ip,而不是数字。

    您可能正在尝试设置端口

    Capybara.server_port = 45454
    

    然后根据你的 app_host (这可能没有必要)您还需要设置

    Capybara.server_host = 'localhost'