Best Python code snippet using toolium_python
test_suite.py
Source:test_suite.py  
...578        with open(self.dumpcap_file_path, 'rb') as f:579            r = dpkt.pcapng.Reader(f)580            for pkt in iter(r):581                yield decode_packet(pkt[1]).data582    def _wait_until_condition(self, timeout_s, step_s, condition: lambda pkts: True):583        if timeout_s is None:584            timeout_s = self.DEFAULT_MSG_TIMEOUT585        deadline = time.time() + timeout_s586        while True:587            if condition(self.read_pcap()):588                return589            if time.time() >= deadline:590                raise TimeoutError('Condition was not true in specified time interval')591            time.sleep(step_s)592    def _count_packets(self, condition: lambda pkts: True):593        result = 0594        for pkt in self.read_pcap():595            if condition(pkt):596                result += 1597        return result598    @staticmethod599    def is_icmp_unreachable(pkt):600        return isinstance(pkt, dpkt.ip.IP) \601                and isinstance(pkt.data, dpkt.icmp.ICMP) \602                and isinstance(pkt.data.data, dpkt.icmp.ICMP.Unreach)603    @staticmethod604    def is_dtls_client_hello(pkt):605        header = b'\x16'  # Content Type: Handshake606        header += b'\xfe\xfd'  # Version: DTLS 1.2607        header += b'\x00\x00'  # Epoch: 0608        if isinstance(pkt, dpkt.ip.IP) and isinstance(pkt.data, dpkt.udp.UDP):609            return pkt.udp.data[:len(header)] == header610        else:611            return False612    def count_icmp_unreachable_packets(self):613        return self._count_packets(PcapEnabledTest.is_icmp_unreachable)614    def count_dtls_client_hello_packets(self):615        return self._count_packets(PcapEnabledTest.is_dtls_client_hello)616    def wait_until_icmp_unreachable_count(self, value, timeout_s=None, step_s=0.1):617        def count_of_icmps_is_expected(pkts):618            return self.count_icmp_unreachable_packets() >= value619        try:620            self._wait_until_condition(timeout_s=timeout_s, step_s=step_s, condition=count_of_icmps_is_expected)621        except TimeoutError:622            raise TimeoutError('ICMP Unreachable packet not generated')623    def wait_until_dtls_client_hello_count(self, value, timeout_s=None, step_s=0.1):624        def count_of_dtls_client_hello_is_expected(pkts):625            return self.count_dtls_client_hello_packets() >= value626        try:627            self._wait_until_condition(timeout_s=timeout_s, step_s=step_s, condition=count_of_dtls_client_hello_is_expected)628        except TimeoutError:629            raise TimeoutError('DTLS Client Hello packets were not captured in time')630def get_test_name(test):631    if isinstance(test, Lwm2mTest):632        return test.test_name()633    return test.id()634def get_full_test_name(test):635    if isinstance(test, Lwm2mTest):636        return test.suite_name() + '.' + test.test_name()637    return test.id()638def get_suite_name(suite):639    suite_names = []640    for test in suite:641        if isinstance(test, Lwm2mTest):...page_element.py
Source:page_element.py  
...183        """Find element and return True if it is visible184        :returns: True if element is visible185        """186        return self.is_present() and self.web_element.is_displayed()187    def _wait_until_condition(self, condition, timeout=None):188        """Search element and wait until it meets the condition189        :param condition: name of condition that must meet the element (visible, not_visible, clickable)190        :param timeout: max time to wait191        :returns: page element instance192        """193        try:194            condition_msg = ''195            if condition == 'visible':196                condition_msg = 'not found or is not visible'197                self.utils.wait_until_element_visible(self, timeout)198            elif condition == 'not_visible':199                condition_msg = 'is still visible'200                self.utils.wait_until_element_not_visible(self, timeout)201            elif condition == 'clickable':202                condition_msg = 'not found or is not clickable'203                self.utils.wait_until_element_clickable(self, timeout)204        except TimeoutException as exception:205            parent_msg = f" and parent locator {self.parent_locator_str()}" if self.parent else ''206            timeout = timeout if timeout else self.utils.get_explicitly_wait()207            msg = "Page element of type '%s' with locator %s%s %s after %s seconds"208            msg = msg % (type(self).__name__, self.locator, parent_msg, condition_msg, timeout)209            self.logger.error(msg)210            exception.msg += "\n  {}".format(msg)211            raise exception212        return self213    def wait_until_visible(self, timeout=None):214        """Search element and wait until it is visible215        :param timeout: max time to wait216        :returns: page element instance217        """218        return self._wait_until_condition('visible', timeout)219    def wait_until_not_visible(self, timeout=None):220        """Search element and wait until it is not visible221        :param timeout: max time to wait222        :returns: page element instance223        """224        return self._wait_until_condition('not_visible', timeout)225    def wait_until_clickable(self, timeout=None):226        """Search element and wait until it is clickable227        :param timeout: max time to wait228        :returns: page element instance229        """230        return self._wait_until_condition('clickable', timeout)231    def assert_screenshot(self, filename, threshold=0, exclude_elements=[], force=False):232        """Assert that a screenshot of the element is the same as a screenshot on disk, within a given threshold.233        :param filename: the filename for the screenshot, which will be appended with ``.png``234        :param threshold: percentage threshold for triggering a test failure (value between 0 and 1)235        :param exclude_elements: list of WebElements, PageElements or element locators as a tuple (locator_type,236                                 locator_value) that must be excluded from the assertion237        :param force: if True, the screenshot is compared even if visual testing is disabled by configuration238        """239        VisualTest(self.driver_wrapper, force).assert_screenshot(self.web_element, filename, self.__class__.__name__,240                                                                 threshold, exclude_elements)241    def get_attribute(self, name):242        """Get the given attribute or property of the element243        :param name: name of the attribute/property to retrieve244        :returns: attribute value...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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
