facebook_browser_test.rb 5.3 KB

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