New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'by' is a reserved word in Coffeescript #275

Closed
Elexy opened this Issue Nov 19, 2013 · 11 comments

Comments

Projects
None yet
6 participants
@Elexy

Elexy commented Nov 19, 2013

I Write my tests in CoffeeScript and noticed that Protractor.By. has been replaced by just 'by'. This causes the coffeescript compiler to choke.

http://coffeescript.org/documentation/docs/lexer.html#section-66

By = protractor.By

describe "app entry page", ->

  it "should login", ->
    browser.get '/login'
    element(By.input("user.email")).sendKeys "admin@example.com"
    # FAILS: element(by.input("user.email")).sendKeys "admin@example.com"

This is an easy workaround and not too invasive, but I would like to put this on the list.

@juliemr

This comment has been minimized.

Member

juliemr commented Nov 21, 2013

Thanks for pointing this out! Maybe we should add a doc for folks looking to use coffeescript.

@Elexy

This comment has been minimized.

Elexy commented Nov 21, 2013

I can start a doc and PR?

@juliemr

This comment has been minimized.

Member

juliemr commented Nov 21, 2013

That'd be great! Should go in docs/using-coffeescript.md.

@Elexy

This comment has been minimized.

Elexy commented Nov 21, 2013

OK, will get on it tomorrow, i did run into some more Coffeescript issues.

@cyranix

This comment has been minimized.

cyranix commented Nov 22, 2013

Alternative workaround for "by" is to use JS escaping with backticks:

myButton = element `by`.name 'foo'
@cyranix

This comment has been minimized.

cyranix commented Nov 22, 2013

@Elexy Definitely interested in helping with the Coffeescript doc if you like. Page object pattern looks beautiful in Coffeescript!

class LoginPage
  constructor: ->
    @email = element `by`.name 'login-email'
    @password = element `by`.name 'login-password'
    @loginButton = element `by`.xpath '//form[1]/input[@type="submit"]'

  get: ->
    browser.get 'app/#/login'
    browser.getCurrentUrl()

  setEmail: (text) ->
    @email.sendKeys text
    @

  clearEmail: ->
    @email.clear()
    @

  setPassword: (text) ->
    @password.sendKeys text
    @

  clearPassword: ->
    @password.clear()
    @

  login: ->
    @loginButton.click()
    @

describe 'Login and logout capabilities', ->
  it 'should warn on malformed email address', ->
    page = new LoginPage()
    url = page.get()

    page
      .setEmail('test')
      .setPassword('test')
      .login()

    expect(browser.getCurrentUrl()).toEqual(url)
@daniellmb

This comment has been minimized.

daniellmb commented Dec 13, 2013

@cyranix that IS beautiful!

@juliemr

This comment has been minimized.

Member

juliemr commented Jan 10, 2014

See e7d9e08

global By is now an alternative.

Closing this issue - if someone wants to write a getting started for coffeescript, please open a PR!

@juliemr juliemr closed this Jan 10, 2014

@Mulkave

This comment has been minimized.

Mulkave commented Jan 21, 2014

Ran into this issue using Protractor 0.16.1:

 ReferenceError: By is not defined
   Stacktrace:
     ReferenceError: By is not defined

@cyranix workaround worked for me.

@juliemr

This comment has been minimized.

Member

juliemr commented Jan 24, 2014

By is only out in 0.17.0.

@lucassus lucassus referenced this issue Feb 19, 2014

Closed

Upgrade protractor #89

3 of 4 tasks complete
@armw4

This comment has been minimized.

armw4 commented Jan 27, 2015

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment