facebook_browser_test.rb 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. # encoding: utf-8
  2. require 'browser_test_helper'
  3. class FacebookBrowserTest < TestCase
  4. def test_add_config
  5. # app config
  6. if !ENV['FACEBOOK_BT_APP_ID']
  7. raise "ERROR: Need FACEBOOK_BT_APP_ID - hint FACEBOOK_BT_APP_ID='1234'"
  8. end
  9. app_id = ENV['FACEBOOK_BT_APP_ID']
  10. if !ENV['FACEBOOK_BT_APP_SECRET']
  11. raise "ERROR: Need FACEBOOK_BT_APP_SECRET - hint FACEBOOK_BT_APP_SECRET='1234'"
  12. end
  13. app_secret = ENV['FACEBOOK_BT_APP_SECRET']
  14. if !ENV['FACEBOOK_BT_USER_LOGIN']
  15. raise "ERROR: Need FACEBOOK_BT_USER_LOGIN - hint FACEBOOK_BT_USER_LOGIN='1234'"
  16. end
  17. user_login = ENV['FACEBOOK_BT_USER_LOGIN']
  18. if !ENV['FACEBOOK_BT_USER_PW']
  19. raise "ERROR: Need FACEBOOK_BT_USER_PW - hint FACEBOOK_BT_USER_PW='1234'"
  20. end
  21. user_pw = ENV['FACEBOOK_BT_USER_PW']
  22. if !ENV['FACEBOOK_BT_PAGE_ID']
  23. raise "ERROR: Need FACEBOOK_BT_PAGE_ID - hint FACEBOOK_BT_PAGE_ID='1234'"
  24. end
  25. page_id = ENV['FACEBOOK_BT_PAGE_ID']
  26. if !ENV['FACEBOOK_BT_CUSTOMER']
  27. raise "ERROR: Need FACEBOOK_BT_CUSTOMER - hint FACEBOOK_BT_CUSTOMER='name:1234:access_token'"
  28. end
  29. customer_name = ENV['FACEBOOK_BT_CUSTOMER'].split(':')[0]
  30. customer_id = ENV['FACEBOOK_BT_CUSTOMER'].split(':')[1]
  31. customer_access_token = ENV['FACEBOOK_BT_CUSTOMER'].split(':')[2]
  32. @browser = browser_instance
  33. login(
  34. username: 'master@example.com',
  35. password: 'test',
  36. url: browser_url,
  37. auto_wizard: true,
  38. )
  39. tasks_close_all()
  40. click(css: 'a[href="#manage"]')
  41. click(css: 'a[href="#channels/facebook"]')
  42. click(css: '#content .js-configApp')
  43. modal_ready()
  44. set(
  45. css: '#content .modal [name=application_id]',
  46. value: app_id,
  47. )
  48. set(
  49. css: '#content .modal [name=application_secret]',
  50. value: 'wrong',
  51. )
  52. click(css: '#content .modal .js-submit')
  53. watch_for(
  54. css: '#content .modal .alert',
  55. value: 'Error',
  56. )
  57. set(
  58. css: '#content .modal [name=application_secret]',
  59. value: app_secret,
  60. )
  61. click(css: '#content .modal .js-submit')
  62. watch_for_disappear(
  63. css: '#content .modal .alert',
  64. value: 'Error',
  65. )
  66. watch_for(
  67. css: '#content .js-new',
  68. value: 'add account',
  69. )
  70. click(css: '#content .js-configApp')
  71. modal_ready()
  72. set(
  73. css: '#content .modal [name=application_secret]',
  74. value: 'wrong',
  75. )
  76. click(css: '#content .modal .js-submit')
  77. watch_for(
  78. css: '#content .modal .alert',
  79. value: 'Error',
  80. )
  81. set(
  82. css: '#content .modal [name=application_secret]',
  83. value: app_secret,
  84. )
  85. click(css: '#content .modal .js-submit')
  86. watch_for_disappear(
  87. css: '#content .modal .alert',
  88. value: 'Error',
  89. )
  90. watch_for(
  91. css: '#content .js-new',
  92. value: 'add account',
  93. )
  94. click(css: '#content .js-new')
  95. watch_for(
  96. css: 'body',
  97. value: '(Facebook Login|Log into Facebook)',
  98. )
  99. set(
  100. css: '#email',
  101. value: user_login,
  102. )
  103. set(
  104. css: '#pass',
  105. value: user_pw,
  106. )
  107. click(css: '#loginbutton')
  108. #sleep 10
  109. #click(css: 'div[role="dialog"] button[type="submit"][name="__CONFIRM__"]')
  110. #sleep 10
  111. #click(css: 'div[role="dialog"] button[type="submit"][name="__CONFIRM__"]')
  112. #sleep 10
  113. #watch_for(
  114. # css: '#content .modal',
  115. # value: '',
  116. #)
  117. watch_for(
  118. css: '#navigation',
  119. value: 'Dashboard',
  120. )
  121. select(css: '#content .modal [name="pages::' + page_id + '::group_id"]', value: 'Users')
  122. click(css: '#content .modal .js-submit')
  123. sleep 5
  124. watch_for(
  125. css: '#content',
  126. value: 'Hansi Merkur',
  127. )
  128. exists(
  129. css: '#content .main .action:nth-child(1)'
  130. )
  131. exists_not(
  132. css: '#content .main .action:nth-child(2)'
  133. )
  134. click(css: '#content .js-new')
  135. sleep 10
  136. #click(css: '#login_button_inline')
  137. #watch_for(
  138. # css: '#content .modal',
  139. # value: 'Search Terms',
  140. #)
  141. click(css: '#content .modal .js-close')
  142. watch_for(
  143. css: '#content',
  144. value: 'Hansi Merkur',
  145. )
  146. exists(
  147. css: '#content .main .action:nth-child(1)'
  148. )
  149. exists_not(
  150. css: '#content .main .action:nth-child(2)'
  151. )
  152. sleep 50
  153. # post new posting
  154. hash = "##{rand(999_999)}"
  155. customer_client = Koala::Facebook::API.new(customer_access_token)
  156. message = "I need some help for your product #{hash}"
  157. post = customer_client.put_wall_post(message, {}, page_id)
  158. # watch till post is in app
  159. click(text: 'Overviews')
  160. # enable full overviews
  161. execute(
  162. js: '$(".content.active .sidebar").css("display", "block")',
  163. )
  164. click(text: 'Unassigned & Open')
  165. sleep 6 # till overview is rendered
  166. watch_for(
  167. css: '.content.active',
  168. value: hash,
  169. timeout: 40,
  170. )
  171. ticket_open_by_title(
  172. title: hash,
  173. )
  174. click(css: '.content.active [data-type="facebookFeedReply"]')
  175. sleep 2
  176. re_hash = "#{hash}re#{rand(99_999)}"
  177. ticket_update(
  178. data: {
  179. body: "You need to do this #{re_hash} #{rand(999_999)}",
  180. },
  181. )
  182. sleep 20
  183. match(
  184. css: '.content.active .ticket-article',
  185. value: re_hash,
  186. )
  187. end
  188. end