使用selenium与odoo交互的工具
odooselenium的Python项目详细描述
odooselenium提供了使用Selenium与Odoo交互的工具。
- 基本测试类;
- 帮助者要转到模块或视图,请单击按钮,填写表单…
这个项目的初始范围是odoo的核心特性。第三方插件可以是 由其他项目支持。
示例
让我们编写一个创建然后删除客户的脚本…
fromselenium.webdriverimportFirefoxfromselenium.webdriver.common.byimportByimportodooseleniumwebdriver=Firefox()ui=odooselenium.OdooUI(webdriver,base_url=u'http://localhost:8069',)# Log in.ui.login('myusername','mypassword','mydatabase')# Navigate to "Accounting / Customers".ui.go_to_module('Accounting')ui.go_to_view('Customers')# Toggle list view.assertui.get_url_fragments()['view_type']==u'kanban'list_view_button=webdriver.find_element(By.CSS_SELECTOR,".oe_vm_switch_list")withui.wait_for_ajax_load():list_view_button.click()assertui.get_url_fragments()['view_type']==u'list'# Click "Create" button.create_button=webdriver.find_element(By.XPATH,"//button[""@data-bt-testing-model_name='res.partner' and ""@data-bt-testing-name='oe_list_add']")withui.wait_for_ajax_load():create_button.click()# Fill then submit the form.name_field=webdriver.find_element(By.XPATH,"//input[""@data-bt-testing-model_name='res.partner' and ""@data-bt-testing-name='name']")name_field.send_keys('Sample customer')save_button=webdriver.find_element(By.XPATH,"//button[""@data-bt-testing-model_name='res.partner' and ""@data-bt-testing-name='oe_form_button_save']")withui.wait_for_ajax_load():save_button.click()
下面是一个简单的测试类:
importodooseleniumclassSampleTestCase(odooselenium.TestCase):defconfigure(self,**kwargs):"""Override this method to alter settings... if necessary."""kwargs.setdefault('url','http://localhost:8069')kwargs.setdefault('username','admin')kwargs.setdefault('password','admin')kwargs.setdefault('dbname','test')super(SampleTestCase,self).configure(kwargs)deftest_ui(self):# self.ui is instance of odooselenium.OdooUI.self.ui.go_to_module('Accounting')# self.webdriver is Selenium's webdriver.self.webdriver.find_element_by_css_selector('body')
另请参见OdoseLenium自己的测试 https://github.com/meta-it/odooselenium/tree/master/tests
安装
见INSTALL。