facebook_browser_test.rb 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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: '.content.active a[href="#channels/facebook"]')
  42. click(css: '.content.active .js-configApp')
  43. modal_ready()
  44. set(
  45. css: '.content.active .modal [name=application_id]',
  46. value: app_id,
  47. )
  48. set(
  49. css: '.content.active .modal [name=application_secret]',
  50. value: 'wrong',
  51. )
  52. click(css: '.content.active .modal .js-submit')
  53. watch_for(
  54. css: '.content.active .modal .alert',
  55. value: 'Error',
  56. )
  57. set(
  58. css: '.content.active .modal [name=application_secret]',
  59. value: app_secret,
  60. )
  61. click(css: '.content.active .modal .js-submit')
  62. watch_for_disappear(
  63. css: '.content.active .modal .alert',
  64. value: 'Error',
  65. )
  66. watch_for(
  67. css: '.content.active .js-new',
  68. value: 'add account',
  69. )
  70. click(css: '.content.active .js-configApp')
  71. modal_ready()
  72. set(
  73. css: '.content.active .modal [name=application_secret]',
  74. value: 'wrong',
  75. )
  76. click(css: '.content.active .modal .js-submit')
  77. watch_for(
  78. css: '.content.active .modal .alert',
  79. value: 'Error',
  80. )
  81. set(
  82. css: '.content.active .modal [name=application_secret]',
  83. value: app_secret,
  84. )
  85. click(css: '.content.active .modal .js-submit')
  86. watch_for_disappear(
  87. css: '.content.active .modal .alert',
  88. value: 'Error',
  89. )
  90. watch_for(
  91. css: '.content.active .js-new',
  92. value: 'add account',
  93. )
  94. click(css: '.content.active .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.active .modal',
  115. # value: '',
  116. #)
  117. watch_for(
  118. css: '#navigation',
  119. value: 'Dashboard',
  120. )
  121. select(css: '.content.active .modal [name="pages::' + page_id + '::group_id"]', value: 'Users')
  122. sleep 1
  123. click(css: '.content.active .modal .js-submit')
  124. sleep 5
  125. watch_for(
  126. css: '.content.active',
  127. value: 'Hansi Merkur',
  128. )
  129. exists(
  130. css: '.content.active .main .action:nth-child(1)'
  131. )
  132. exists_not(
  133. css: '.content.active .main .action:nth-child(2)'
  134. )
  135. click(css: '.content.active .js-new')
  136. sleep 10
  137. #click(css: '#login_button_inline')
  138. #watch_for(
  139. # css: '.content.active .modal',
  140. # value: 'Search Terms',
  141. #)
  142. click(css: '.content.active .modal .js-close')
  143. watch_for(
  144. css: '.content.active',
  145. value: 'Hansi Merkur',
  146. )
  147. exists(
  148. css: '.content.active .main .action:nth-child(1)'
  149. )
  150. exists_not(
  151. css: '.content.active .main .action:nth-child(2)'
  152. )
  153. # watch till post is in app
  154. click(text: 'Overviews')
  155. # enable full overviews
  156. execute(
  157. js: '$(".content.active .sidebar").css("display", "block")',
  158. )
  159. click(text: 'Unassigned & Open')
  160. sleep 50
  161. # post new posting
  162. hash = "##{rand(999_999)}"
  163. customer_client = Koala::Facebook::API.new(customer_access_token)
  164. message = "I need some help for your product #{hash}"
  165. post = customer_client.put_wall_post(message, {}, page_id)
  166. watch_for(
  167. css: '.content.active',
  168. value: hash,
  169. timeout: 320,
  170. )
  171. sleep 6
  172. ticket_open_by_title(
  173. title: hash,
  174. )
  175. click(css: '.content.active [data-type="facebookFeedReply"]')
  176. sleep 2
  177. re_hash = "#{hash}re#{rand(99_999)}"
  178. ticket_update(
  179. data: {
  180. body: "You need to do this #{re_hash} #{rand(999_999)}",
  181. },
  182. )
  183. sleep 20
  184. match(
  185. css: '.content.active .ticket-article',
  186. value: re_hash,
  187. )
  188. end
  189. end