         done()
 
 
-
-  clickSaveAndTestButton: (browser) ->
-
-    saveAndTestButton    = '.template-title-form .buttons .save-test'
-    editorSelector       = '.stack-template .output .output-view'
-    loaderIconNotVisible = "#{saveAndTestButton} .kdloader.hidden"
-
-    browser
-      .waitForElementVisible     saveAndTestButton, 20000
-      .scrollToElement           saveAndTestButton
-      .click                     saveAndTestButton
-      .waitForElementVisible     editorSelector, 35000
-      .waitForElementVisible     '.template-title-form .buttons .save-test .kdloader', 20000
-      .waitForElementNotVisible  loaderIconNotVisible, 500000
-      .pause                     3000
-
-
-  saveTemplate: (browser, deleteStack = yes, checkTags = yes, doExtra = yes) ->
-
-    stackModal           = '.stack-modal'
-    modalCloseButton     = "#{stackModal} .gray"
-    stackTabSelector     = '.team-stack-templates .kdtabhandle.stack-template.active'
-    finalizeStepsButton  = "#{sidebarSelector} a[href='/Home/Welcome']:not(.SidebarSection-headerTitle)"
-
-    if doExtra
-      @seeTemplatePreview(browser)
-      @updateStackReadme(browser)
-      @defineCustomVariables(browser)
-
-    @clickSaveAndTestButton(browser)
-
-    browser.element 'css selector', stackModal, (result) ->
-      if result.status is 0
-        browser
-          .assert.containsText    stackModal, 'Your stack script has been successfully saved'
-          .waitForElementVisible  modalCloseButton, 20000
-          .click                  modalCloseButton
-
-    browser
-      .waitForElementVisible     stackTabSelector, 20000
-      .waitForElementVisible     stackModalCloseButton, 20000
-      .click                     stackModalCloseButton
-      .pause                     3000
-      .waitForElementVisible     sidebarStackSection, 20000
-      .waitForElementNotPresent  finalizeStepsButton, 20000
-      .waitForElementVisible     envMachineStateModal, 20000
-
-    if checkTags
-      @checkStackTemplateTags(browser, deleteStack)
-
-
-  checkStackTemplateTags: (browser, deleteStack) ->
-
-    inUseTag       = "#{stackCatalogModal} [testpath=StackInUseTag]"
-    defaultTag     = "#{stackCatalogModal} [testpath=StackDefaultTag]"
-    accessTag      = "#{stackCatalogModal} [testpath=StackAccessLevelTag]"
-    deleteMenuItem = '.kdbuttonmenu .context-list-wrapper .delete'
-
-    @openStackCatalog(browser, no)
-
-    browser
-      .waitForElementVisible  stackTemplateList, 20000
-      .waitForElementVisible  inUseTag, 20000
-      .waitForElementVisible  defaultTag, 20000
-      .waitForElementVisible  accessTag, 20000
-      .assert.containsText    accessTag, 'GROUP'
-
-    if deleteStack
-      browser
-        .waitForElementVisible    stackSettingsMenuIcon, 20000
-        .click                    stackSettingsMenuIcon
-        .pause                    2000
-        .waitForElementVisible    deleteMenuItem, 20000
-        .click                    deleteMenuItem
-        .assert.containsText      '.kdnotification.main', 'This template currently in use by the Team'
-        .waitForElementNotVisible '.kdnotification.main', 30000
-
-    browser
-      .waitForElementVisible  stackModalCloseButton, 20000
-      .click                  stackModalCloseButton
-
-
-  editStack: (browser, openEditorAndClone = no) ->
-
-    editMenuItem             = '.kdbuttonmenu .context-list-wrapper .edit'
-    openEditorButton         = '.kdmodal-inner .kdmodal-buttons .red'
-    openEditorAndCloneButton = '.kdmodal-inner .kdmodal-buttons .green'
-    stackTemplatePage        = '.define-stack-view .stack-template'
-    stackEditorSelector      = "#{stackTemplatePage} .editor-pane"
-    numberNotification       = "#{sidebarStackSection} .SidebarListItem-unreadCount"
-    myStacksPage             = '.environments-modal.My-Stacks'
-    stackItems               = "#{myStacksPage} .environment-item"
-    makeTeamDefaultButton    = '.stacks .template-title-form .set-default'
-    makeTeamDefaultLoader    = "#{makeTeamDefaultButton} .kdloader.hidden"
-    newStackTemplate         = '.stacktemplates .stack-template-list .stacktemplate-item:last-child .title'
-    newStackInSidebar        = '.SidebarStackSection .SidebarMachinesListItem .SidebarMachinesListItem--MainLink'
-    updateNotification       = "#{stackItems} .update-notification"
-    updateStackButton        = "#{updateNotification} .reinit-stack"
-    reinitModal              = '.kdmodal[testpath=reinitStack]'
-    proceedButton            = "#{reinitModal} .red"
-    sidebarStackWidget       = '.SidebarStackWidgets'
-
-
-    browser.pause  3000
-    @openStackCatalog(browser, no)
-
-    browser
-      .waitForElementVisible  stackTemplateList, 20000
-      .waitForElementVisible  stackSettingsMenuIcon, 20000
-      .click                  stackSettingsMenuIcon
-      .pause                  2000
-      .waitForElementVisible  editMenuItem, 20000
-      .click                  editMenuItem
-      .pause                  2000
-
-    if openEditorAndClone
-      browser
-        .waitForElementVisible  openEditorAndCloneButton, 20000
-        .click                  openEditorAndCloneButton
-    else
-      browser
-        .waitForElementVisible  openEditorButton, 20000
-        .click                  openEditorButton
-
-    browser
-      .waitForElementVisible  stackTemplatePage, 20000
-      .waitForElementVisible  stackEditorSelector, 20000
-
-    @setTextToEditor browser, 'template', staticContents.multiMachineStackTemplate
-
-    if openEditorAndClone
-      @createCredential(browser, no, no, yes)
-
-    @clickSaveAndTestButton(browser)
-
-    if openEditorAndClone
-      browser
-        .waitForElementVisible  makeTeamDefaultButton, 20000
-        .click                  makeTeamDefaultButton
-        .pause                  3000
-        .waitForElementVisible  '.stacktemplates', 20000
-
-    browser
-      .waitForElementVisible  stackModalCloseButton, 20000
-      .click                  stackModalCloseButton
-
-    if openEditorAndClone
-      browser
-        .waitForElementVisible  sidebarStackWidget, 20000
-        .waitForTextToContain   sidebarStackWidget, 'Team admin has changed the default stack'
-        .click                  "#{sidebarStackWidget} a"
-        .waitForElementVisible  stackItems, 20000
-        .click                  "#{stackItems} .red"
-
-    else
-      browser
-        .waitForElementVisible  newStackInSidebar, 20000
-        .waitForElementVisible  numberNotification, 20000
-        .click                  numberNotification
-        .waitForElementVisible  stackItems, 20000
-        .waitForElementVisible  updateNotification, 20000
-        .assert.containsText    updateNotification, 'has updated this stack'
-        .waitForElementVisible  updateStackButton, 20000
-        .click                  updateStackButton
-
-    browser
-      .waitForElementVisible  reinitModal, 20000
-      .click                  proceedButton
-      .waitForTextToContain   sidebarSelector, 'mexample'
-
-
-  deleteStack: (browser) ->
-
-    deleteMenuItem = '.kdbuttonmenu .context-list-wrapper .delete'
-    stackTemplate  = '.stacktemplates .stack-template-list [testpath=privateStackListItem]'
-    stackMenuIcon  = "#{stackTemplate} .stack-settings-menu"
-    deleteModal    = '.kdmodal[testpath=RemoveStackModal]'
-    deleteButton   = "#{deleteModal} .red"
-
-
-    browser.element 'css selector', stackCatalogModal, (result) ->
-      if result.status is 0
-        browser
-          .waitForElementVisible  stackCatalogModal, 20000
-          .waitForElementVisible  closeButton, 20000
-          .click                  closeButton
-
-    @openStackCatalog(browser)
-
-    browser
-      .waitForElementVisible    myStackTemplatesButton, 20000
-      .click                    myStackTemplatesButton
-      .waitForElementVisible    stackTemplate, 20000
-      .pause                    3000
-      .waitForElementVisible    stackMenuIcon, 20000
-      .click                    stackMenuIcon
-      .waitForElementVisible    deleteMenuItem, 20000
-      .click                    deleteMenuItem
-      .pause                    3000
-      .waitForElementVisible    deleteModal, 20000
-      .assert.containsText      "#{deleteModal} .kdmodal-title", 'Remove stack template ?'
-      .waitForElementVisible    deleteButton, 20000
-      .click                    deleteButton
-      .waitForElementNotPresent deleteModal, 20000
-      .waitForElementVisible    closeButton, 20000
-      .click                    closeButton
-
-
-  buildStack: (browser) ->
-
-    buildStackButton     = "#{envMachineStateModal} .content-container .state-button"
-    progressbarContainer = "#{envMachineStateModal} .progressbar-container"
-    credentialsModal     = '.kdmodal[testpath=BuildRequirementsModal]'
-    addedCredential      = "#{credentialsModal} .credential-item"
-    titleInput           = "#{credentialsModal} input[name=title]"
-    usernameInput        = "#{credentialsModal} input[name=username]"
-    passwordInput        = "#{credentialsModal} input[name=password]"
-    credentialSaveButton = "#{credentialsModal} button.green"
-    useCredentialButton  = "#{addedCredential} .kdbutton:not(.secondary)"
-    readmeMarkdown       = "#{envMachineStateModal} .content-readme"
-    readmeHeader         = "#{readmeMarkdown} #test-stack-readme"
-    readmeLink           = "#{readmeMarkdown} a"
-
-    browser
-      .waitForElementVisible     buildStackButton, 20000
-      .waitForElementVisible     readmeMarkdown, 20000
-      .waitForElementVisible     readmeHeader, 20000
-      .waitForElementVisible     readmeLink, 20000
-      .click                     buildStackButton
-      .pause                     3500 # wait for credentials modal
-
-    browser.element 'css selector', credentialsModal, (result) ->
-      if result.status is 0
-
-        browser.element 'css selector', addedCredential, (result) ->
-          if result.status isnt 0
-            browser
-              .waitForElementVisible   titleInput, 20000
-              .waitForElementVisible   usernameInput, 20000
-              .waitForElementVisible   passwordInput, 20000
-              .setValue                titleInput, 'Build requirement data for testing'
-              .setValue                usernameInput, 'FOO'
-              .setValue                passwordInput, 'BAR'
-              .click                   credentialSaveButton
-              .waitForElementVisible   addedCredential, 20000
-
-          browser
-            .waitForElementVisible     useCredentialButton, 20000
-            .click                     useCredentialButton
-
-      browser
-        .waitForElementVisible     progressbarContainer, 20000
-        .waitForElementNotPresent  progressbarContainer, 500000
-        .pause                     3000 # wait for machine
-        .waitForElementVisible     stackMachine, 20000
-
-    browser.isStackBuilt = yes
-
-
   defineCustomVariables: (browser) ->
 
     wrongCustomVariable    = "foo: '"

    @setTextToEditor browser, 'template', staticContents.stackTemplate


  reinitStack: (browser) ->

    myStacksLink  = '.AppModal-navItem.my-stacks'
    stackItem     = '.kdlistitemview.environment-item'
    reinitButton  = "#{stackItem} .button-container .red"
    reinitModal   = '.kdmodal[testpath=reinitStack]'
    proceedButton = "#{reinitModal} .red"
    notification  = '.kdnotification.main'

    @openStackCatalog(browser, no)

    browser
      .waitForElementVisible    myStacksLink, 20000
      .click                    myStacksLink
      .waitForElementVisible    stackItem, 20000
      .click                    reinitButton
      .waitForElementVisible    reinitModal, 20000
      .click                    proceedButton
      .waitForElementNotPresent stackCatalogModal, 30000
      .waitForElementVisible    envMachineStateModal, 20000


  destroyEverything: (browser) ->

    if browser.isStackBuilt
      @reinitStack(browser)
      browser.pause 10000 # wait before credential destroy
      @createStack(browser, yes)
      @createCredential(browser, no, yes)


  seeTemplatePreview: (browser) ->

    templatePreviewButton     = '.stack-template .template-preview-button'
    stackTemplatePreviewModal = '.stack-template-preview'
    tabsSelector              = "#{stackTemplatePreviewModal} .kdmodal-content .kdtabhandle-tabs"
    yamlTabSelector           = "#{tabsSelector} .yaml"
    jsonTabSelector           = "#{tabsSelector} .json"
    stackTabSelector          = '.team-stack-templates .kdtabhandle.stack-template'

    browser
      .waitForElementVisible  stackTabSelector, 20000
      .click                  stackTabSelector
      .waitForElementVisible  templatePreviewButton, 20000
      .click                  templatePreviewButton
      .waitForElementVisible  stackTemplatePreviewModal, 20000
      .waitForElementVisible  yamlTabSelector, 20000
      .waitForElementVisible  jsonTabSelector, 20000
      .waitForElementVisible  stackModalCloseButton, 20000
      .click                  stackModalCloseButton


  updateStackReadme: (browser) ->

    @switchTabOnStackCatalog(browser, 'readme')
    @setTextToEditor(browser, 'readme', staticContents.readme)

    previewButton = '.editor-pane .preview-button'
    previewModal  = '[testpath=ReadmePreviewModal]'
    readmeLink    = 'https://koding.com/docs/creating-an-aws-stack'

    browser
      .waitForElementVisible  previewButton, 20000
      .click                  previewButton
      .waitForElementVisible  previewModal, 20000
      .assert.containsText    "#{previewModal} h3", 'Test stack readme'
      .waitForElementVisible  "#{previewModal} a[href='#{readmeLink}']", 20000
      .waitForElementVisible  stackModalCloseButton, 20000
      .click                  stackModalCloseButton


  getAwsKey: -> return awsKey


  checkIconsStacks: (browser, removeNewStack = yes) ->

    saveAndTestButton           = '.buttons button:nth-of-type(5)'
    stackTemplateSelector       = '.kdtabhandlecontainer.hide-close-icons .stack-template'
    stacksLogsSelector          = '.step-define-stack .kdscrollview'
    iconsSelector               = '.kdlistitemview-default.stacktemplate-item .stacktemplate-info'
    notReadyIconSelector        = "#{iconsSelector} .not-ready"
    privateIconSelector         = "#{iconsSelector} .private"
    stackTemplateSettingsButton = '.kdbutton.stack-settings-menu'
    deleteButton                = '.kdlistview-contextmenu.expanded .delete'
    confirmDeleteButton         = '.kdview.kdmodal-buttons .solid.red .button-title'

    browser
      .click                      saveAndTestButton
      .pause                      2000 #for stack creation logs to appear
      .waitForElementVisible      stacksLogsSelector, 20000
      .assert.containsText        stacksLogsSelector, 'An error occured: Required credentials are not provided yet'
      .click                      myStackTemplatesButton
      .waitForElementVisible      notReadyIconSelector, 30000
      .assert.containsText        notReadyIconSelector, 'NOT READY'
      .assert.containsText        privateIconSelector, 'PRIVATE'

    if removeNewStack
      browser
        .waitForElementVisible      stackTemplateSettingsButton, 20000
        .click                      stackTemplateSettingsButton
        .waitForElementVisible      deleteButton, 20000
        .click                      deleteButton
        .waitForElementVisible      confirmDeleteButton, 20000
        .click                      confirmDeleteButton
        .pause                      2000
        .waitForElementVisible      stackTemplateSelector, 20000
        .assert.containsText        stackTemplateSelector, 'Stack Template'
        .assert.containsText        saveAndTestButton, 'SAVE & TEST'

  # possible values of tabName variable is 'stack', 'variables' or 'readme'
  switchTabOnStackCatalog: (browser, tabName) ->


        callback invitationUrl



  logoutTeam: (browser, callback) ->
