Class: PrestaShopAutomation::PrestaShop

Inherits:
Capybara::Session
  • Object
show all
Includes:
CarriersActions, CartRulesActions, GeneralActions, GeneralHelpers, InstallerActions, OrdersActions, ProductsActions, SettingsActions, TaxesActions, UsersActions, RSpec::Expectations, RSpec::Matchers
Defined in:
lib/prestashop-automation.rb

Instance Method Summary collapse

Methods included from UsersActions

#create_user

Methods included from InstallerActions

#add_module_from_repo, #database_exists, #drop_database, #install, #install_module, #prepare_database, #update_all_modules

Methods included from OrdersActions

#add_product_to_cart, #add_products_to_cart, #order_current_cart_5_steps, #order_current_cart_opc, #validate_order

Methods included from CartRulesActions

#create_cart_rule, #delete_cart_rule

Methods included from CarriersActions

#create_carrier

Methods included from TaxesActions

#create_tax, #create_tax_group, #create_tax_group_from_rate

Methods included from ProductsActions

#create_product

Methods included from SettingsActions

#set_ecotax_option, #set_friendly_urls, #set_gift_wrapping_option, #set_order_process_type, #set_rounding_method, #set_rounding_rule

Methods included from GeneralActions

#get_menu, #goto_admin_tab, #goto_back_office, #goto_front_office, #goto_module_configuration, #login_to_back_office, #login_to_front_office, #logout_of_back_office, #logout_of_front_office

Methods included from GeneralHelpers

#click, #click_button_named, #click_label_for, #expect_not_to, #expect_to, #get_cookies_string, #get_select_options, #onoff, #select_by_value, #select_by_value_jqChosen, #select_random_option, #standard_success_check, #version_gte, #visit, #wait_until

Constructor Details

#initialize(options) ⇒ PrestaShop

Returns a new instance of PrestaShop.



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/prestashop-automation.rb', line 51

def initialize options

	@front_office_url = options[:front_office_url]
	@back_office_url  = options[:back_office_url]
          @installer_url = options[:installer_url]
	@admin_email = options[:admin_email] || '[email protected]'
	@admin_password = options[:admin_password] || '123456789'
	@default_customer_email = options[:default_customer_email] || '[email protected]'
	@default_customer_password = options[:default_customer_password] || '123456789'
	@database_user = options[:database_user] || 'root'
	@database_password = options[:database_password] || ''
	@database_name = options[:database_name]
	@database_prefix = options[:database_prefix] || 'ps_'
	@database_port = options[:database_port] || '3306'
	@database_host = options[:database_host] || 'localhost'
          @filesystem_path = options[:filesystem_path]
	@version = options[:version]

	@dumps = []

	super :selenium_with_long_timeout
end

Instance Method Details

#all(*args) ⇒ Object

Rspec defines this method, but we want the one from Capybara::Session



47
48
49
# File 'lib/prestashop-automation.rb', line 47

def all *args
	Capybara::Session.instance_method(:all).bind(self).call *args
end

#clear_cookiesObject



112
113
114
# File 'lib/prestashop-automation.rb', line 112

def clear_cookies
	reset!
end

#dump_database(target) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/prestashop-automation.rb', line 78

def dump_database target
	if database_exists
		cmd = "mysqldump -uroot "
		if @database_password.to_s.strip != ''
			cmd += "-p#{Shellwords.shellescape @database_password} "
		end
		cmd += "-h#{Shellwords.shellescape @database_host} "
		cmd += "-P#{@database_port} "
		cmd += "#{Shellwords.shellescape @database_name} "
		cmd += "> #{Shellwords.shellescape target}"
		`#{cmd}`
		if !$?.success?
			throw "Could not dump database!"
		end
		return true
	else
		return false
	end
end

#load_database(src) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/prestashop-automation.rb', line 98

def load_database src
	prepare_database
	cmd = "mysql -uroot "
	if @database_password.to_s.strip != ''
		cmd += "-p#{Shellwords.shellescape @database_password} "
	end
	cmd += "-h#{Shellwords.shellescape @database_host} "
	cmd += "-P#{@database_port} "
	cmd += "#{Shellwords.shellescape @database_name} "
	cmd += "< #{Shellwords.shellescape src}"
	`#{cmd}`
	return $?.success?
end

#quitObject



74
75
76
# File 'lib/prestashop-automation.rb', line 74

def quit
    driver.browser.quit
end

#restore(dump = nil) ⇒ Object



132
133
134
135
136
137
138
139
140
# File 'lib/prestashop-automation.rb', line 132

def restore dump=nil
	unless dump
		dump = @dumps.pop
	end

	if dump[:database]
		load_database dump[:database].path
	end
end

#saveObject



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/prestashop-automation.rb', line 116

def save
	out = {
		:database => nil,
		:files => nil
	}

	if database_exists
		out[:database] = Tempfile.new 'prestashop-db'
		dump_database out[:database].path
	end

	@dumps << out

	return out
end