Module: Firebase::Cloning::Tool

Defined in:
lib/firebase/cloning/tool.rb,
lib/firebase/cloning/tool/version.rb

Constant Summary collapse

VERSION =
"0.1.6"

Class Method Summary collapse

Class Method Details

.clone_firebase_remote_configObject



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/firebase/cloning/tool.rb', line 141

def self.clone_firebase_remote_config
  print 'Email: '
  email = gets.chomp
  print 'Password: '
  password = STDIN.noecho(&:gets).chomp
  puts
  print 'Source(Project Name, Case sensitive): '
  source_project = gets.chomp
  print 'Destination(New Project Name, Case sensitive, Only letters, numbers, spaces, and these characters: -!\'") : '
  destination_project = gets.chomp

  # overrides selenium's driver to use chrome browser
  Capybara.register_driver :chrome_driver do |app|
    Capybara::Selenium::Driver.new(app, {:browser => :chrome})
  end

  # selecting the driver
  Capybara.default_driver = :chrome_driver

  Capybara.visit 'https://console.firebase.google.com/'
  (email, password)

  go_to_project(source_project)
  go_to_remote_config

  remote_config_values = copy_remote_config
  Capybara.visit 'https://console.firebase.google.com/'
  wait_until_selector_present('div.c5e-landing-create-project-button')

  if project_exists(destination_project)
    go_to_project(destination_project)
  else
    create_new_project(destination_project)
  end

  go_to_remote_config

  paste_remote_config(remote_config_values)

  publish_changes

  puts 'Project cloned successfully!!!'
end

.copy_remote_configObject



99
100
101
102
103
104
105
106
107
108
# File 'lib/firebase/cloning/tool.rb', line 99

def self.copy_remote_config
  puts 'Copying remote config to memory...'
  remote_config_values = {}
  Capybara.all('div.content').each {
    |element|
    remote_config_values[element.find('div.name').text()] = element.find('div.chip-value.value.ng-star-inserted div.ng-star-inserted').text()
  }
  puts 'Remote config copied.'
  return remote_config_values
end

.create_new_project(project_name) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/firebase/cloning/tool.rb', line 58

def self.create_new_project(project_name)
  puts 'Creating new project: ' + project_name + '...'
  Capybara.find('div.c5e-landing-create-project-button').click
  wait_until_selector_disapears('circle.ng-star-inserted')
  wait_until_xpath_present('//input[@name="projectName"]')
  Capybara.find(:xpath, '//input[@name="projectName"]').set project_name
  Capybara.find('#mat-checkbox-2-input').first(:xpath,".//..").click
  wait_until_xpath_disapears('//button[@ng-click="controller.createProject()" and @disabled="disabled"]')
  Capybara.find(:xpath, '//button[@ng-click="controller.createProject()"]').click
  wait_until_xpath_present('//button[@name="continueButton"]')
  Capybara.find(:xpath, '//button[@name="continueButton"]').click
  puts 'Project ' + project_name + ' created.'
  wait_until_selector_present('div.fb-featurebar-title')
  puts 'Project ' + project_name + ' loaded.'
end

.do_login(email, password) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/firebase/cloning/tool.rb', line 43

def self.(email, password)
  puts 'Trying sign in for ' + email + '...'
  wait_until_selector_present('#identifierId')
  Capybara.fill_in('identifierId', with: email)
  wait_until_selector_present('#identifierNext')
  Capybara.find('#identifierNext').click
  wait_until_xpath_present('//input[@name="password"]')
  # Capybara.fill_in('Passwd', with: password)
  Capybara.find(:xpath, '//input[@name="password"]').set(password)
  wait_until_selector_present('#passwordNext')
  Capybara.find('#passwordNext').click
  wait_until_selector_present('div.c5e-landing-create-project-button')
  puts 'Sign in completed.'
end

.go_to_project(project_name) ⇒ Object



74
75
76
77
78
79
# File 'lib/firebase/cloning/tool.rb', line 74

def self.go_to_project(project_name)
  puts 'Opening ' + project_name + ' project...'
  Capybara.find('div.c5e-project-card-project-name', :exact_text => project_name).click
  wait_until_selector_present('div.fb-featurebar-title')
  puts 'Project ' + project_name + ' loaded.'
end

.go_to_remote_configObject



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/firebase/cloning/tool.rb', line 81

def self.go_to_remote_config
  puts 'Going to remote config...'
  Capybara.find('.c5e-entry-displayname', :text => 'Remote Config').first(:xpath,".//..").click

  wait_until_selector_present('div.fb-featurebar-title')

  if Capybara.all('img.fire-zero-state-image').any?
    puts 'Waiting to add new remote config data...'
    wait_until_xpath_present('//*[@id="main"]/ng-transclude/div/div/div/r10g-ng2-parameter-list/div/div/mat-card/fire-zero-state/div/button')
    Capybara.find(:xpath, '//*[@id="main"]/ng-transclude/div/div/div/r10g-ng2-parameter-list/div/div/mat-card/fire-zero-state/div/button').click
  else
    puts 'Waiting for remote config data...'
    wait_until_selector_present('button.mat-raised-button.mat-primary.ng-star-inserted')
    # Capybara.find('button.mat-raised-button.mat-primary.ng-star-inserted').click
  end
  puts 'Remote config loaded.'
end

.paste_remote_config(remote_config_values) ⇒ Object



120
121
122
123
124
125
126
127
128
129
130
# File 'lib/firebase/cloning/tool.rb', line 120

def self.paste_remote_config(remote_config_values)
  puts 'Pasting remote config from memory...'
  remote_config_values.each do | key, value |
    Capybara.find(:xpath, '//*[@id="main"]/ng-transclude/div/div/div/r10g-ng2-parameter-list/div/div/mat-card/fire-inline-editor/div/r10g-ng2-parameter-editor/form/div/div[2]/div[1]/div[1]/input').set key
    Capybara.find(:xpath, '//*[@id="main"]/ng-transclude/div/div/div/r10g-ng2-parameter-list/div/div/mat-card/fire-inline-editor/div/r10g-ng2-parameter-editor/form/div/div[2]/div[2]/div/r10g-ng2-parameter-conditional-value-editor/div/div/r10g-ng2-parameter-conditional-value-input/div/input').set value
    Capybara.find(:xpath, '//*[@id="main"]/ng-transclude/div/div/div/r10g-ng2-parameter-list/div/div/mat-card/fire-inline-editor[1]/div/r10g-ng2-parameter-editor/form/div/div[3]/div[2]/button[2]').click
    Capybara.find(:xpath, '//*[@id="main"]/ng-transclude/div/div/div[2]/r10g-ng2-parameter-list/div/div/mat-card/fire-card-action-bar/div/div/button').click
  end
  Capybara.find(:xpath, '//*[@id="main"]/ng-transclude/div/div/div[2]/r10g-ng2-parameter-list/div/div/mat-card/fire-inline-editor[1]/div/r10g-ng2-parameter-editor/form/div/div[3]/div[2]/button[1]').click
  puts 'Remote config pasted.'
end

.project_exists(project_name) ⇒ Object



110
111
112
113
114
115
116
117
118
# File 'lib/firebase/cloning/tool.rb', line 110

def self.project_exists(project_name)
  Capybara.all('div.c5e-project-card-project-name').each {
    |element|
    if element.text() == project_name
      return true
    end
  }
  return false
end

.publish_changesObject



132
133
134
135
136
137
138
139
# File 'lib/firebase/cloning/tool.rb', line 132

def self.publish_changes
  puts 'Publishing remote config...'
  Capybara.find(:xpath, '//*[@id="main"]/ng-transclude/fb-feature-bar/div/div/div[2]/div/button').click
  wait_until_selector_present('div.fire-dialog-actions button.mat-primary')
  Capybara.find('div.fire-dialog-actions button.mat-primary').click
  wait_until_selector_present('div.md-toast-content')
  puts 'Remote config published.'
end

.wait_until_selector_disapears(selector, wait = 30) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/firebase/cloning/tool.rb', line 19

def self.wait_until_selector_disapears(selector, wait=30)
  wait.times do
    break     if !Capybara.all(selector).any?
    puts 'Waiting for selector to disapears: ' + selector + '...'
    sleep 1
  end
end

.wait_until_selector_present(selector, wait = 30) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/firebase/cloning/tool.rb', line 11

def self.wait_until_selector_present(selector, wait=30)
  wait.times do
    break     if Capybara.all(selector).any?
    puts 'Waiting for selector: ' + selector + '...'
    sleep 1
  end
end

.wait_until_xpath_disapears(xpath, wait = 30) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/firebase/cloning/tool.rb', line 35

def self.wait_until_xpath_disapears(xpath, wait=30)
  wait.times do
    break     if !Capybara.all(:xpath, xpath).any?
    puts 'Waiting for xpath: ' + xpath + '...'
    sleep 1
  end
end

.wait_until_xpath_present(xpath, wait = 30) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/firebase/cloning/tool.rb', line 27

def self.wait_until_xpath_present(xpath, wait=30)
  wait.times do
    break     if Capybara.all(:xpath, xpath).any?
    puts 'Waiting for xpath: ' + xpath + '...'
    sleep 1
  end
end