Skip to content
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
Closed

'by' is a reserved word in Coffeescript #275

Elexy opened this issue Nov 19, 2013 · 11 comments

Comments

@Elexy
Copy link

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
Copy link
Member

juliemr commented Nov 21, 2013

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

@Elexy
Copy link
Author

Elexy commented Nov 21, 2013

I can start a doc and PR?

@juliemr
Copy link
Member

juliemr commented Nov 21, 2013

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

@Elexy
Copy link
Author

Elexy commented Nov 21, 2013

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

@cyranix
Copy link

cyranix commented Nov 22, 2013

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

myButton = element `by`.name 'foo'

@cyranix
Copy link

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
Copy link

@cyranix that IS beautiful!

@juliemr
Copy link
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 as completed Jan 10, 2014
@Mulkave
Copy link

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
Copy link
Member

juliemr commented Jan 24, 2014

By is only out in 0.17.0.

@armw4
Copy link

armw4 commented Jan 27, 2015

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants