forked from mozilla/moztrap-tests
/
create_case_page.py
78 lines (57 loc) · 3.45 KB
/
create_case_page.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from datetime import datetime
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
from pages.base_page import MozTrapBasePage
class MozTrapCreateCasePage(MozTrapBasePage):
_page_title = 'Create Case'
_name_locator = (By.ID, 'id_name')
_product_select_locator = (By.ID, 'id_product')
_version_select_locator = (By.ID, 'id_productversion')
_suite_select_locator = (By.ID, 'id_suite')
_description_locator = (By.ID, 'id_description')
_step1_instruction_locator = (By.ID, 'id_steps-0-instruction')
_step1_result_locator = (By.ID, 'id_steps-0-expected')
_status_select_locator = (By.ID, 'id_status')
_submit_locator = (By.CSS_SELECTOR, '#single-case-add .form-actions button[type="submit"]')
_case_locator = (By.CSS_SELECTOR, '#managecases .itemlist .listitem .title[title="%(case_name)s"]')
def go_to_create_case_page(self):
self.selenium.get(self.base_url + '/manage/case/add/')
self.is_the_current_page
def create_case(self, name='Test Case', product='Test Product', version='Test Version', suite=None, desc='This is a test case', step1_instruction='Test Case step 1 instruction', step1_result='Test Case step 1 expected result', status='active'):
dt_string = datetime.utcnow().isoformat()
case = {}
case['name'] = u'%(name)s %(dt_string)s' % {'name': name, 'dt_string': dt_string}
case['desc'] = u'%(desc)s created on %(dt_string)s' % {'desc': desc, 'dt_string': dt_string}
case['locator'] = (self._case_locator[0], self._case_locator[1] % {'case_name': case['name']})
name_field = self.selenium.find_element(*self._name_locator)
name_field.send_keys(case['name'])
product_select = Select(self.selenium.find_element(*self._product_select_locator))
product_select.select_by_visible_text(product)
version_select = Select(self.selenium.find_element(*self._version_select_locator))
version_select.select_by_visible_text(product)
if suite:
suite_select = Select(self.selenium.find_element(*self._suite_select_locator))
suite_select.select_by_visible_text(suite)
self.selenium.find_element(*self._description_locator).send_keys(case['desc'])
self.selenium.find_element(*self._step1_instruction_locator).send_keys(step1_instruction)
self.selenium.find_element(*self._step1_result_locator).send_keys(step1_result)
status_select = Select(self.selenium.find_element(*self._status_select_locator))
status_select.select_by_visible_text(status)
self.selenium.find_element(*self._submit_locator).click()
return case
@property
def product_value(self):
product_select = self.find_element(*self._product_select_locator)
return product_select.find_element(By.CSS_SELECTOR, 'option:checked').text
@property
def product_version_value(self):
version_select = self.find_element(*self._version_select_locator)
return version_select.find_element(By.CSS_SELECTOR, 'option:checked').text
@property
def suite_value(self):
suite_select = self.find_element(*self._suite_select_locator)
return suite_select.find_element(By.CSS_SELECTOR, 'option:checked').text