facebook_browser_test.rb 5.4 KB

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