最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Protractor tests in CoffeeScript producing "SyntaxError: unexpected by"? - Stack Overflow

programmeradmin0浏览0评论

I am trying to write the following Protractor test in CoffeeScript:

describe "tests", ->

  browser.get "/"

  it "should display Login page", ->
    expect(element(by.css("h1")).getText()).toBe "Login"

However, CoffeeScript spits out this error:

SyntaxError: unexpected by

Solutions?

I am trying to write the following Protractor test in CoffeeScript:

describe "tests", ->

  browser.get "/"

  it "should display Login page", ->
    expect(element(by.css("h1")).getText()).toBe "Login"

However, CoffeeScript spits out this error:

SyntaxError: unexpected by

Solutions?

Share Improve this question asked Jun 7, 2014 at 14:52 XåpplI'-I0llwlg'I -XåpplI'-I0llwlg'I - 22.4k28 gold badges107 silver badges154 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 12

Like @meagar said it is reserved, you can alias it in your protractor config in the onPrepare block:

require('coffee-script/register');

exports.config = {
  ....

  // by is reserved in coffee script
  onPrepare: function() {
    global.By = global.by;
  }
}

then

expect(element(By.css("h1")).getText()).toBe "Login"

by is a reserved word in CoffeeScript, used in specifying loop increments:

evens = (x for x in [0..10] by 2)

Use a different variable name.

发布评论

评论列表(0)

  1. 暂无评论