Checking if words with an accent was displayed

82 Views Asked by At

In automated tests, I need to know how I can check if words with an accent was displayed. I performed automated tests as below:

file.feature

# encoding: utf-8

Feature: Cálculo de triângulo

Scenario: Calculando um triângulo equilátero
    Given que estou na tela do TrianguloApp
    When eu preencher o campo Lado 1 com "3"
        And eu preencher o campo Lado 2 com "3"
        And eu preencher o campo Lado 3 com "3"
        And eu clicar em Calcular
    Then a mensagem "O triângulo é Equilátero" será exibida 

file_steps.rb

Given(/^que estou na tela do TrianguloApp$/) do
    element_exists("* text:'TrianguloApp'")
end

When(/^eu preencher o campo Lado 1 com "(.*?)"$/) do |lado1|
      enter_text "* id:'txtLado1'", "#{lado1}"
end

When(/^eu preencher o campo Lado 2 com "(.*?)"$/) do |lado2|
      enter_text "* id:'txtLado2'", "#{lado2}"
end

When(/^eu preencher o campo Lado 3 com "(.*?)"$/) do |lado3|
      enter_text "* id:'txtLado3'", "#{lado3}"
end

When(/^eu clicar em Calcular$/) do
      touch("* id:'btnCalcular'")
end

Then(/^a mensagem "(.*?)" será exibida$/) do |mensagem|
     element_exists("* O triângulo é Equilátero")
end

The result is as in the image below.

result of the automated test

The error occurred because of trying to verify that the phrase O triângulo é Equilátero was displayed on the screen.

2

There are 2 best solutions below

0
Robson Luiz On BEST ANSWER

I was able to validate the text O triângulo é Equilátero

I changed the command element_exists to macro %Q|I should see "#{text}"|

See how it got:

Entao(/^a mensagem "(.*?)" será exibida$/) do |mensagem| macro %Q|I should see "#{mensagem}"| end

Source: http://testmunk.readthedocs.io/en/latest/steps.html

0
Derek Nagy On

Well your statement is missing the text:

element_exists("* text:'O triângulo é Equilátero'")

That might be all you need to get this working, however if you problem is the accents then you could find the element first though a different identifier then check the text.

the_text = query("* id:some_id", "text")

expect(the_text).to eql 'O triângulo é Equilátero'

The expect is from rspec https://github.com/rspec/rspec-expectations