#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