Question

I am trying to convert our tests from selenium to rspec and capybara but I am encountering some problems. In selenium We use a function called verifyText which basically checks if two values are similar. however with rspecs and capybara, I am having problems when the text is in french with accents.

Failure/Error: verifyText "//div[@id='adview']/div[2]/div/div", "crédit"
   expected: "crédit"
        got: "crédit" (using ==)

I think its an encoding issue. But, I have specified encoding to ISO-8859-15 but still it doesn't work for me. Here is how test file looks like:

# -*- encoding : iso-8859-15 -*-

describe "php-placeholder", type: :feature do
    it "placeholderFr_Placeholder" do
        verifyText "//div[@id='adview_aside']/div[2]/div/div", "crédit"

Here is how verifyText looks like.

def verifyText(id, value)
  (page.first(:xpath, id).text.force_encoding 'iso-8859-15').should == value
end
Was it helpful?

Solution

Hi I have found the solution my self. I was using the wrong encoding function. I use the following function and it solved my problem.

def verifyText(id, value)
  page.first(:xpath, id).text.encode('iso-8859-15').should == value
end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top