How to use _get_test_result method in Lemoncheesecake

Best Python code snippet using lemoncheesecake

logic.py

Source:logic.py Github

copy

Full Screen

...141 print("Test result modal is open")142 return True143 return False144 # Not implemented yet145 def _get_test_result(self,testcase_function, testcase_payload):146 """147 Return the text of modal-test-result148 :return: str type. text on test result modal149 """150 DATA = {'cmd' : 'run_function', 'function_name' : "{}".format(testcase_function), 'payload' : "{}".format(testcase_payload)}151 c = Client()152 app_id = self.parent.browser.current_url.split('/')[-2]153 print('{}/logic'.format(app_id))154 print(self.parent.browser.current_url)155 response = c.post(self.parent.browser.current_url, DATA)156 print(response)157 print(response.context)158 #print(response.content)159 """160 test_result_modal = self.parent.browser.find_element_by_id('modal-test-result')161 test_result_modal.find_element_by_tag_name('button').click()162 """163 def _click_test_function(self, test_function):164 """165 Click name of function to move to function info page.166 :param test_function: name of function to click167 :return:168 """169 function_table = self.parent.browser.find_elements_by_tag_name('tbody')[1]170 for th in function_table.find_elements_by_tag_name('th'):171 if th.text.strip() == test_function:172 print("[{}] is clicked".format(test_function))173 th.click()174 break175 def _get_function_url(self, test_function):176 """177 Return url of function info page.178 :param test_function:179 :return:180 """181 print("moved to url : {}".format(self.parent.browser.current_url))182 return self.parent.browser.current_url183 def _get_function_name(self):184 """185 Return function_name186 :return: value of element with id 'function-name'187 """188 return self.parent.browser.find_element_by_id('function-name').get_attribute('value')189 def _get_function_description(self):190 """191 Return function_description192 :return: value of element with id 'function-description'193 """194 return self.parent.browser.find_element_by_id('function-description').get_attribute('value')195 def _get_function_runtime(self):196 """197 Return function_runtime198 :return: value of element with id 'function-runtime'199 """200 select_box = select.Select(self.parent.browser.find_element_by_id('function-runtime'))201 return select_box.first_selected_option.get_attribute('value')202 def _get_function_handler(self):203 """204 Return function_handler205 :return: value of element with id 'function-handler'206 """207 return self.parent.browser.find_element_by_id('function-handler').get_attribute('value')208 def _edit_function_description(self, new_desc):209 """210 Edit function_description to [new_desc]211 :return:212 """213 desc_field = self.parent.browser.find_element_by_id('function-description')214 desc_field.clear()215 desc_field.send_keys(new_desc)216 time.sleep(DELAY)217 print("Edited function description to [{}]".format(new_desc))218 def _save_function_info(self):219 """220 click save button of function info, and accept button on alert221 :return:222 """223 self.parent.browser.find_element_by_css_selector('span[onclick="save_function_info();"]').click()224 time.sleep(LONG_DELAY)225 self.parent.browser.switch_to.alert.accept()226 time.sleep(DELAY)227 self.parent.browser.refresh()228 time.sleep(LONG_DELAY)229 print("Clicked save function info")230 def _clear_function_file(self):231 """232 Clear function file(test.py)233 :return:234 """235 ace_script = "editor.setValue('',-1);"236 self.parent.browser.execute_script(ace_script)237 print("Cleared function file")238 def _save_function_file(self):239 """240 Click save button on fuction file, and accept button on alert241 :return:242 """243 self.parent.browser.find_element_by_css_selector('a[onclick="save_current_file();"]').click()244 time.sleep(LONG_DELAY)245 self.parent.browser.switch_to.alert.accept()246 time.sleep(DELAY)247 self.parent.browser.refresh()248 time.sleep(LONG_DELAY)249 print("clicked save function file")250 def _get_function_file(self):251 """252 Get code on function file(test.py)/ace editor253 :return: str type. text in function file.254 """255 ace_script = "editor.getValue();"256 function_file = self.parent.browser.execute_script(ace_script)257 print(function_file)258 return function_file259 def _return_to_logic_module(self):260 """261 Click 'LOGIC' on navigation bar to move to logic module.262 :return:263 """264 self.parent.browser.find_element_by_id('link-logic').click()265 print("Returned to logic module")266 time.sleep(LONG_DELAY * 2)267 def do_test(self):268 FUNCTION_NAME = 'test-function'269 FUNCTION_RUNTIME = 'Python3.6'270 FUNCTION_DESC = 'test-description'271 FUNCTION_DESC_NEW = 'test-description-mod2'272 FUNCTION_DIR = os.path.dirname(os.path.dirname(os.path.abspath(settings.__file__)))273 FUNCTION_FILE = 'test.zip'274 FUNCTION_FILE = os.path.join(FUNCTION_DIR, FUNCTION_FILE)275 FUNCTION_HANDLER = 'test.handler'276 FUNCTION_URL = '/logic/{}'.format(FUNCTION_NAME)277 TESTCASE_NAME = 'test-case'278 TESTCASE_FUNCTION = 'test-function'279 TESTCASE_PAYLOAD = '{"answer": 10}'280 time.sleep(DELAY)281 start_time = time.time()282 self.parent.browser.find_element_by_id('link-logic').click()283 time.sleep(LONG_DELAY)284 while True:285 try:286 if self.parent.get_view_tag() == 'logic':287 break288 self.parent.browser.refresh()289 time.sleep(LONG_DELAY * 4)290 print('Wait...')291 except StaleElementReferenceException:292 pass293 duration = time.time() - start_time294 print('duration: {} s'.format(duration))295 self.parent.assert_view_tag('logic')296 time.sleep(DELAY)297 self._click_create_function()298 time.sleep(LONG_DELAY)299 self._set_function(FUNCTION_NAME, FUNCTION_RUNTIME, FUNCTION_DESC, FUNCTION_FILE, FUNCTION_HANDLER)300 time.sleep(DELAY)301 self.parent.assertTrue(self._accept_and_has_function(FUNCTION_NAME))302 time.sleep(DELAY)303 self._click_create_testcase()304 time.sleep(DELAY)305 self._set_testcase(TESTCASE_NAME, TESTCASE_FUNCTION, TESTCASE_PAYLOAD)306 time.sleep(LONG_DELAY * 2)307 self.parent.assertTrue(self._has_testcase(TESTCASE_NAME))308 time.sleep(DELAY)309 # self._open_test_result(TESTCASE_NAME)310 # time.sleep(LONG_DELAY)311 # _get_test_result is not implemented yet!312 self._get_test_result(TESTCASE_FUNCTION, TESTCASE_PAYLOAD)313 #self.parent.assertTrue(self._get_test_result(TESTCASE_FUNCTION, TESTCASE_PAYLOAD)['response'])314 time.sleep(LONG_DELAY)315 """316 self._click_test_function(FUNCTION_NAME)317 time.sleep(LONG_DELAY)318 self.parent.assertTrue(self._get_function_url(FUNCTION_NAME).endswith(FUNCTION_URL))319 time.sleep(DELAY)320 self.parent.assertTrue(self._get_function_name() == FUNCTION_NAME)321 time.sleep(DELAY)322 self.parent.assertTrue(self._get_function_runtime() == FUNCTION_RUNTIME.lower())323 time.sleep(DELAY)324 self.parent.assertTrue(self._get_function_description() == FUNCTION_DESC)325 time.sleep(DELAY)326 self.parent.assertTrue(self._get_function_handler() == FUNCTION_HANDLER)327 time.sleep(DELAY)328 self._edit_function_description(FUNCTION_DESC_NEW)329 time.sleep(DELAY)330 self._save_function_info()331 time.sleep(LONG_DELAY * 2)332 self.parent.assertTrue(self._get_function_description() == FUNCTION_DESC_NEW)333 time.sleep(DELAY)334 self._clear_function_file()335 time.sleep(DELAY)336 self._save_function_file()337 time.sleep(DELAY)338 self.parent.assertTrue(self._get_function_file() == None)339 time.sleep(DELAY)340 self._return_to_logic_module()341 time.sleep(LONG_DELAY * 2)342 self._open_test_result(TESTCASE_FUNCTION)343 time.sleep(DELAY)344 # _get_test_result is not implemented yet!345 self._get_test_result()346 # self.parent.assertTrue(self._get_test_result(TESTCASE_FUNCTION, TESTCASE_PAYLOAD)['error'])347 time.sleep(LONG_DELAY)348 self._remove_testcase(TESTCASE_NAME)349 time.sleep(LONG_DELAY)350 self.parent.assertFalse(self._has_testcase(TESTCASE_NAME))351 time.sleep(LONG_DELAY * 2)352 self._remove_function(FUNCTION_NAME)353 time.sleep(LONG_DELAY * 2)354 self.parent.assertFalse(self._has_function(FUNCTION_NAME))...

Full Screen

Full Screen

all_e2e_test.py

Source:all_e2e_test.py Github

copy

Full Screen

...11class AllE2ETest(unittest.TestCase):12 def setUp(self):13 from internal.sky31_pptx import SKY31PPTX14 self.sky31_pptx = SKY31PPTX(pptx_file=None)15 def _get_test_result(self, year: int, month: int) -> str:16 yyyymm = date(year=year, month=month, day=1).strftime("%Y%m")17 with open(f'./test_files/{yyyymm}.txt', 'r', encoding='utf-8') as result_file:18 result = result_file.read()19 result_file.close()20 return result21 def _save_test_result(self, year: int, month: int):22 yyyymm = date(year=year, month=month, day=1).strftime("%Y%m")23 with open(f'./test_files/{yyyymm}.txt', 'w', encoding='utf-8') as result_file:24 result = get_monthly_menus(year, month)25 result_file.write(result)26 result_file.close()27 def test_monthly_results(self):28 # print('testing...2020 10')29 # self.assertEqual(self._get_test_result(2020, 10), get_monthly_menus(2020, 10))30 # print('testing...2020 11')31 # self.assertEqual(self._get_test_result(2020, 11), get_monthly_menus(2020, 11))32 # print('testing...2020 12')33 # self.assertEqual(self._get_test_result(2020, 12), get_monthly_menus(2020, 12))34 # print('testing...2021 1')35 # self.assertEqual(self._get_test_result(2021, 1), get_monthly_menus(2021, 1))36 # print('testing...2021 2')37 # self.assertEqual(self._get_test_result(2021, 2), get_monthly_menus(2021, 2))38 # print('testing...2021 3')39 # self.assertEqual(self._get_test_result(2021, 3), get_monthly_menus(2021, 3))40 # print('testing...2021 4')41 # self.assertEqual(self._get_test_result(2021, 4), get_monthly_menus(2021, 4))42 # print('testing...2021 5')43 # self.assertEqual(self._get_test_result(2021, 5), get_monthly_menus(2021, 5))44 print('testing...2021 6')45 self.assertEqual(self._get_test_result(2021, 6), get_monthly_menus(2021, 6))46 print('testing...2021 7')47 self.assertEqual(self._get_test_result(2021, 7), get_monthly_menus(2021, 7))48 def find_idx(self, text: str, word: str):49 all_positions = []50 next_pos = -151 while True:52 next_pos = text.find(word, next_pos + 1)53 if next_pos < 0:54 break55 all_positions.append(next_pos)56 return all_positions57 def test_reduce_malformed_text(self):58 malformed_menu_text = '오색 비빔밥\n(8,000)\n\n해물 순두부 찌개(7,000)\n\n해물 순두부 찌개(7,000)해물 순두부 찌개(7,000)\n\n(8,000)'59 reduced_text = self.sky31_pptx._reduce_malformed_menu(malformed_menu_text)60 self.assertEqual(reduced_text, '오색 비빔밥\n(8,000)\n\n해물 순두부 찌개\n(7,000)\n\n해물 순두부 찌개\n(7,000)해물 순두부 찌개\n(7,000)\n\n(8,000)')61 def test_reduce_wellformed_text(self):...

Full Screen

Full Screen

test_significance_test_utils.py

Source:test_significance_test_utils.py Github

copy

Full Screen

...3import numpy as np4import copy5NUM_TRAILS = 10006class SignificanceTestTest(unittest.TestCase):7 def _get_test_result(self, metric, same_label = True):8 y_true = ['a', 'b']9 y_a = ['a', 'b']10 if same_label:11 y_b = copy.deepcopy(y_a)12 else:13 y_b = ['b', 'a']14 result = significance_test_utils.Result(y_true, [y_a, y_b])15 y_true, y_pred_a, y_pred_b = significance_test_utils._get_transformed_results(result)16 metrics = significance_test_utils.randomization_test(y_true, y_pred_a=y_pred_a, y_pred_b=y_pred_b, metric=metric, num_trails=NUM_TRAILS)17 diffs = metrics[:, 0] - metrics[:, 1]18 return diffs19 def test_same_labels(self):20 for metric_name, metric in significance_test_utils.metrics:21 diffs = self._get_test_result(metric, same_label=True)22 # There should be no difference if the models have exactly the same predicted labels23 self.assertTrue(np.all(diffs == 0))24 def test_different_labels(self):25 for metric_name, metric in significance_test_utils.metrics:26 diffs = self._get_test_result(metric, same_label=False)27 # There should be a difference in the randomization tests when the predicted labels are not the same...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Lemoncheesecake automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful