遇到冻结错误-无法修改冻结的字符串

时间:2020-11-07 07:22:11

标签: ruby rspec capybara

在运行下面提到的cod时遇到冻结错误。还找到帮助程序文件。下面是主文件:

需要“ spec_helper.rb” 要求'rspec_capybara_assignment_helper.rb'

describe 'Open the automationpractices site' , :type => :request do
    it 'Test: Page Content', :page do
        visit "http://automationpractice.com/index.php"
        expect(page).to have_xpath(".//img[contains(@src,'automationpractice.com/img/logo')]")
        expect(page).to have_xpath(".//input[@id='search_query_top']")
        expect(page).to have_link("Contact us")
        expect(page).to have_link("Sign in")
        within('div#block_top_menu') do
            expect(page).to have_link("Women")
            expect(page).to have_link("Dresses")
            expect(page).to have_link("T-shirts")
        end
        within('div#center_column') do
            expect(page).to have_link("Popular")
            expect(page).to have_link("Best Sellers")
        end
        expect(page).to have_content("Automation Practice Website")
    end 
end

Spec_Helper文件:-spec_helper.rb

require 'rspec'
require 'capybara/rspec'
require 'capybara/dsl'
require "selenium-webdriver"
require "capybara"
require 'capybara/rspec/matchers'

RSpec.configure do |config|
  config.include Capybara::DSL , :type => :request # to include capybara DSL methods 
  config.include Capybara::RSpecMatchers,:type => :request # to include Rspec matchers available.
end

Capybara.configure do |config|
  config.run_server = false
  config.default_driver = :selenium # which driver to use (selenium / chrome /internet explorer)
  config.default_selector = :css #(by default css selector) # if user want to use xpath, he has to write find(:xpath, <xpath>).click
  config.app_host = "http://automationpractice.com/index.php" # host app
  config.default_max_wait_time = 5 # wait for 4 seconds.
  config.app_host = @url
  config.ignore_hidden_elements = true # will ignore hidden elements on page.
  config.match =:prefer_exact # check for exact match.
end

Rspec Capybara Assignmnet帮助文件:

rspec_capybara_assignment_helper.rb def click_on(值) find(value).click 结束

def link_click(value) 
    click_link(value)
end

def button_click(value) 
    click_button(value)
end

def login_application 
    link_click('Sign in')
    fill_in('email', :with => 'test.test@testing.com')
    fill_in('passwd', :with => 'testtest')
    button_click('SubmitLogin')
end

def sign_out 
    link_click('Sign out')
end

def search_product(value) 
    fill_in('search_query_top', :with => value)
    button_click('Search')
    sleep(2)
end

def add_product(value) 
    page.find(:css,'.product-image-container').hover
    sleep(2)
    first("a", :text => "More").click
    sleep(4)
    fill_in('quantity_wanted', :with => '2', visible: false)
    select('M', :from => 'group_1')
    find('button.exclusive').click
    sleep(2)
    first("span", :text => "Continue shopping", wait: 3).click
    sleep(2)
end

def check_locator(value) 
    expect(page).to have_selector(value)
end

错误如下:

打开自动化实践站点 测试:页面内容(失败-1)

失败:

  1. 打开自动化实践站点测试:页面内容 失败/错误:请访问“ http://automationpractice.com/index.php”

    FrozenError: 无法修改冻结的字符串

    ./ spec / tests / rspec_capybara_assignment.rb:6:in在中的'block(2个级别)'

在0.7789秒内完成(文件加载时间为3.61秒) 1例,1例失败

失败的示例:

rspec ./spec/tests/rspec_capybara_assignment.rb:5#打开自动化实践站点Test:页面内容

1 个答案:

答案 0 :(得分:0)

这似乎与selenium-webdriver有关,与水豚本身无关。

https://github.com/SeleniumHQ/selenium/issues/7365上有一个与此相关的问题

要解决此问题,请在您的gemfile中指定至少要至少3.142.4:gem 'selenium-webdriver', '~> 3.142.4'

然后运行bundle update selenium-webdriver

这应该可以解决此特定问题。

相关问题