Ruby's RSpec Error resolution

Source: Internet
Author: User

#enconding: Utf-8require ' selenium-webdriver ' require ' rspec ' describe "Baidu Main Page" doit "should has Baidu button on the Baidu Main Page "DODR = Selenium::webdriver.for:ieurl = ' www.baidu.com ' Dr.get urldr.find_element (: ID, ' su '). Should be_ Displayedend #itend #describe

The error code, as seen above, uses UTF-8 encoding first, such as the following

#enconding: Utf-8

Running in RSpec will cause errors that cannot be explained in Chinese


Obviously, the current utf-8 still does not support the normal operation of Chinese. Change Utf-8 to GBK to run successfully. This is the first problem encountered.

The second problem is assertion.

Dr.find_element (: ID, ' su '). Should be_displayed

The assertion of the should method seems obsolete. There is a syntax error when running Rspec-f Doc. Syntax required to change assertions


Change the asserted code to the following expression:

Expect (Dr.find_element (: ID, ' su ')). to Be_displayed
</pre><pre>

The new syntax format for assertions is shown in the following: Expect (Dr.find_element (: ID, ' su ')). To be_displayed control before the should syntax: Dr.find_element (: ID, ' su '). should Be_displayed

The normal running code, for example, looks like the following:

#encoding: gbk# use GBK ability normal display, do not error, use UTF-8 will error require ' selenium-webdriver ' require ' rspec ' describe "Baidu Main Page" doit " Should has Baidu button on the Baidu Main Page "DODR = Selenium::webdriver.for:ieurl = ' www.baidu.com ' dr.get url#~ dr.find_ Element (: ID, ' su '). Should Be_displayedexpect (Dr.find_element (: ID, ' su ')). To be_displayed# new syntax end #itend #describe


Changing the encoding and assertion method to the above expression will run successfully.

Run the results for example with what you see:


Ruby's RSpec Error resolution

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.