Jquery 测试网页背景色的方法

Jquery 测试网页背景色的方法,jquery,ruby-on-rails,testing,cucumber,Jquery,Ruby On Rails,Testing,Cucumber,我想设置一个背景色,并使用cucumber验证是否将正确的颜色设置为网页的背景色 我有以下情况: Then I follow "Use theme" Then the page background should be blue 步骤定义为: 然后/^页面背景应为蓝色$/do page.evaluate_脚本(“%Q[jQuery('body').css('background-color');]”)。应该 "rgb(1,31,69)"结束 但是htis抛出了一个javascript错

我想设置一个背景色,并使用cucumber验证是否将正确的颜色设置为网页的背景色

我有以下情况:

Then I follow "Use theme"    
Then the page background should be blue
步骤定义为:

然后/^页面背景应为蓝色$/do
page.evaluate_脚本(“%Q[jQuery('body').css('background-color');]”)。应该 "rgb(1,31,69)"结束

但是htis抛出了一个javascript错误 有人能告诉我哪里出了问题吗?(附言:我不太擅长jQuery)

错误:

那么页面背景应该是蓝色的 语法错误(Selenium::WebDriver::error::JavascriptError)

问题在于
%Q[]”
部分。看起来您无意中试图在Ruby字符串中定义Ruby字符串。您可以将字符串包装在“”或%Q[]中,但不能同时包装这两种格式

以下任何一项都有效:

# Using %Q[]
puts page.evaluate_script(%Q[jQuery('body').css('background-color');])

# Using ""
puts page.evaluate_script("jQuery('body').css('background-color');")    

# Using $ instead of jQuery
puts page.evaluate_script('$("body").css("background-color")')
问题在于
%Q[]”
部分。看起来您无意中试图在Ruby字符串中定义Ruby字符串。您可以将字符串包装在“”或%Q[]中,但不能同时包装这两种格式

以下任何一项都有效:

# Using %Q[]
puts page.evaluate_script(%Q[jQuery('body').css('background-color');])

# Using ""
puts page.evaluate_script("jQuery('body').css('background-color');")    

# Using $ instead of jQuery
puts page.evaluate_script('$("body").css("background-color")')

谢谢贾斯汀,这很有帮助!!谢谢贾斯汀,这很有帮助!!