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