Beispiel #1
0
    def __load_po_class(self, path):
        self.table_and_test_file_tabs.table.clear_table()

        if not os.path.exists(path):
            show_dialog_path_doesnt_exist(self, path)
        if not is_correct_python_file(path):
            show_dialog(self, u'File name is incorrect: %s' % path,
                        u'Bad file name')
        else:
            folder = os.path.dirname(path)
            files = [os.path.join(folder, p) for p in os.listdir(folder)
                     if is_correct_python_file(p)]
            self.cb_class_path.Clear()
            self.cb_class_path.AppendItems(files)
            self.cb_class_path.Select(files.index(path))
            try:
                self.__cur_po_class = PageObjectClass.parse_string_to_po_class(read_file(path))
                area = self.__cur_po_class.area
                self.image_panel.set_po_fields(self.__cur_po_class.fields)
                self.image_panel.load_image(self.__cur_po_class.img_path, area)

                self.cb_class_path.SetValue(self.__cur_po_class.file_path)

                self.table_and_test_file_tabs.load_po_class(self.__cur_po_class)
            except Exception:
                self.__cur_po_class = None
                show_error_dialog(self, traceback.format_exc(),
                                  u'Failed to open file %s' % path)
    def get_po_class_for_url(self, url, class_name, folder_path, area=None):
        po_folder = os.path.join(folder_path, RootFolder.PO_FOLDER)
        img_folder = os.path.join(folder_path, RootFolder.PO_FOLDER,
                                  PageObjectClass.IMAGE_FOLDER)
        check_if_path_exists(folder_path)

        self.__log(u'Generating PageObjectClass for url %s with area %s' %
                   (url, str(area)))
        fields = self.get_all_po_fields(url, area)
        img_as_png = self.browser.get_screenshot_as_png()

        filename = get_py_file_name_from_class_name(class_name)
        file_path = os.path.join(po_folder, filename)
        img_path = os.path.join(img_folder,
                                os.path.splitext(filename)[0] + '.png')

        return PageObjectClass(class_name, url, fields, area, file_path,
                               img_path, img_as_png)
    def test_parse_string_to_po_class(self):
        if is_windows():
            self.skipTest(
                "Unsupported in Windows because temp directory is hardcoded to '/tmp' in pickled object."
            )
        else:
            expected_string = read_file(self.expected_duckduckgo_class_path)
            self.assertEqual(self.po_class_object._get_file_content().strip(),
                             expected_string.strip())
            po_class = PageObjectClass.parse_string_to_po_class(
                read_file(self.expected_duckduckgo_class_path))

            self.assertEqual(po_class.name, self.po_class_object.name)
            self.assertEqual(po_class.url, self.po_class_object.url)
            self.assertEqual(po_class.fields, self.po_class_object.fields)
            self.assertEqual(po_class.area, self.po_class_object.area)
            self.assertEqual(po_class.file_path,
                             self.po_class_object.file_path)
            self.assertEqual(po_class.img_path, self.po_class_object.img_path)

            self.assertEqual(po_class, self.po_class_object)
Beispiel #4
0
    def test_parse_string_to_po_class(self):
        if is_windows():
            self.skipTest(
                "Unsupported in Windows because temp directory is hardcoded to '/tmp' in pickled object."
            )
        else:
            expected_string = read_file(self.expected_duckduckgo_class_path)
            self.assertEqual(
                self.po_class_object._get_file_content().strip(),
                expected_string.strip()
            )
            po_class = PageObjectClass.parse_string_to_po_class(
                read_file(self.expected_duckduckgo_class_path)
            )

            self.assertEqual(po_class.name, self.po_class_object.name)
            self.assertEqual(po_class.url, self.po_class_object.url)
            self.assertEqual(po_class.fields, self.po_class_object.fields)
            self.assertEqual(po_class.area, self.po_class_object.area)
            self.assertEqual(po_class.file_path,
                             self.po_class_object.file_path)
            self.assertEqual(po_class.img_path, self.po_class_object.img_path)

            self.assertEqual(po_class, self.po_class_object)