Ejemplo n.º 1
0
    def __init__(
        self,
        token: str = None,
        projectname: str = None,
        jobname: str = None,
        disable_reports: bool = False,
    ):
        if Generic.__instance is not None:
            raise SdkException("A driver session already exists")

        LoggingHelper.configure_logging()

        self._token = token if token is not None else ConfigHelper.get_developer_token(
        )

        agent_status_response: AgentStatusResponse = AgentClient.get_agent_version(
            self._token)

        if version.parse(agent_status_response.tag) < version.parse(
                Generic.MIN_GENERIC_DRIVER_SUPPORTED_VERSION):
            raise AgentConnectException(
                f"Your current Agent version {agent_status_response.tag} does not support the Generic driver. "
                f"Please upgrade your Agent to the latest version and try again"
            )
        else:
            logging.info(
                f"Current Agent version {agent_status_response.tag} does support Generic driver"
            )

        self.session_id = None

        if disable_reports:
            # Setting the project and job name to empty strings will cause the Agent to not initialize a report
            self._projectname = ""
            self._jobname = ""
        else:
            self._projectname = (projectname if projectname is not None else
                                 ReportHelper.infer_project_name())
            self._jobname = (jobname if jobname is not None else
                             ReportHelper.infer_job_name())

        reportsettings = ReportSettings(self._projectname, self._jobname)

        capabilities = {"platformName": "ANY"}

        self._agent_client: AgentClient = AgentClient(
            token=self._token,
            capabilities=capabilities,
            report_settings=reportsettings,
        )
        self._agent_session: AgentSession = self._agent_client.agent_session

        self.command_executor = GenericCommandExecutor(
            agent_client=self._agent_client)

        Generic.__instance = self
Ejemplo n.º 2
0
    def __init__(
        self,
        capabilities: dict,
        token: str,
        projectname: str,
        jobname: str,
        disable_reports: bool,
    ):

        if BaseDriver.__instance is not None:
            raise SdkException("A driver session already exists")

        LoggingHelper.configure_logging()

        if token is not None:
            logging.info(f"Token used as specified in constructor: {token}")

        self._token = token if token is not None else ConfigHelper.get_developer_token(
        )

        if disable_reports:
            # Setting the project and job name to empty strings will cause the Agent to not initialize a report
            self._projectname = ""
            self._jobname = ""
        else:
            self._projectname = (projectname if projectname is not None else
                                 ReportHelper.infer_project_name())
            self._jobname = (jobname if jobname is not None else
                             ReportHelper.infer_job_name())

        self._agent_client: AgentClient = AgentClient(
            token=self._token,
            capabilities=capabilities,
            reportsettings=ReportSettings(self._projectname, self._jobname),
        )
        self._agent_session: AgentSession = self._agent_client.agent_session
        self.w3c = True if self._agent_session.dialect == "W3C" else False

        # Create a custom command executor to enable:
        # - automatic logging capabilities
        # - customized reporting settings
        self.command_executor = CustomCommandExecutor(
            agent_client=self._agent_client,
            remote_server_addr=self._agent_session.remote_address,
        )

        self.command_executor.disable_reports = disable_reports

        RemoteWebDriver.__init__(
            self,
            command_executor=self.command_executor,
            desired_capabilities=self._agent_session.capabilities,
        )

        BaseDriver.__instance = self
Ejemplo n.º 3
0
    def __init__(
        self,
        desired_capabilities: dict = None,
        token: str = None,
        project_name: str = None,
        job_name: str = None,
        disable_reports: bool = False,
    ):
        if Remote.__instance is not None:
            raise SdkException("A driver session already exists")

        LoggingHelper.configure_logging()

        self._desired_capabilities = desired_capabilities

        self._token = token if token is not None else ConfigHelper.get_developer_token(
        )

        if disable_reports:
            # Setting the project and job name to empty strings will cause the Agent to not initialize a report
            self._project_name = ""
            self._job_name = ""
        else:
            self._project_name = (project_name if project_name is not None else
                                  ReportHelper.infer_project_name())
            self._job_name = (job_name if job_name is not None else
                              ReportHelper.infer_job_name())

        report_settings = ReportSettings(self._project_name, self._job_name)

        self._agent_client: AgentClient = AgentClient(
            token=self._token,
            capabilities=self._desired_capabilities,
            report_settings=report_settings,
        )
        self._agent_session: AgentSession = self._agent_client.agent_session
        self.w3c = True if self._agent_session.dialect == "W3C" else False

        AppiumWebDriver.__init__(
            self,
            command_executor=self._agent_session.remote_address,
            desired_capabilities=self._desired_capabilities,
        )

        self.command_executor = CustomAppiumCommandExecutor(
            agent_client=self._agent_client,
            remote_server_addr=self._agent_session.remote_address,
        )

        # this ensures that mobile-specific commands are also available for our command executor
        self._addCommands()

        Remote.__instance = self
    def update_known_test_name(self):
        """Infers the current test name and if different from the latest known test name, reports a test"""
        current_test_name = ReportHelper.infer_test_name()

        # Actions inside a unittest tearDown or tearDownClass method should be reported as part of the test
        in_unittest_teardown = ReportHelper.find_unittest_teardown()

        if self._latest_known_test_name != current_test_name and not in_unittest_teardown:
            # the name of the test method has changed and we're not inside a unittest teardown method,
            # so we need to report a test
            if not self.disable_auto_test_reports:
                self.report_test()
            # update the latest known test name for future reports
            self._latest_known_test_name = current_test_name
Ejemplo n.º 5
0
    def test(self, name: str = None, passed: bool = True, message: str = None):
        """Sends a test report to the Agent Client

        Args:
            name (str): The test name
            passed (bool): True if the test should be marked as passed, False otherwise
            message (str): A message that goes with the test
        """
        if not self._command_executor.disable_reports:
            if name is None:
                name = ReportHelper.infer_test_name()

            if not self._command_executor.disable_auto_test_reports:
                if os.getenv("RFW_SUPPRESS_WARNINGS",
                             "false").casefold() != "true":
                    logging.warning(
                        "Automatic reporting is enabled, disable this using disable_reports flag "
                        "when creating a driver instance to avoid duplicates in the report"
                    )

            test_report = CustomTestReport(
                name=name,
                passed=passed,
                message=message,
            )

            self._command_executor.agent_client.report_test(test_report)

        else:
            logging.debug(f"Test '{name}' {'passed' if passed else 'failed'}")
Ejemplo n.º 6
0
def test_test_name_is_inferred_correctly_from_method_name_and_parameter_values(
    parameter,
):
    current_test_info = os.environ.get("PYTEST_CURRENT_TEST")
    assert (
        ReportHelper.infer_name_from_pytest_info_for(current_test_info, ReportNamingElement.Test)
        == f"test_test_name_is_inferred_correctly_from_method_name_and_parameter_values[{parameter}]"
    )
Ejemplo n.º 7
0
 def __init__(self, agent_client: AgentClient, command_executor):
     self._agent_client = agent_client
     self._command_executor = command_executor
     self._disable_reports = False
     self._disable_auto_test_reports = False
     self._disable_command_reports = False
     self._disable_redaction = False
     self._stashed_command = None
     self._latest_known_test_name = ReportHelper.infer_test_name()
 def __init__(self, agent_client: AgentClient, command_executor,
              remote_connection):
     self._agent_client = agent_client
     self._command_executor = command_executor
     self._disable_reports = False
     self._disable_auto_test_reports = False
     self._disable_command_reports = False
     self._disable_redaction = False
     self._stashed_command = None
     self._latest_known_test_name = ReportHelper.infer_test_name()
     self._excluded_test_names = list()
     self._step_helper = StepHelper(
         remote_connection, agent_client.agent_session.dialect == "W3C",
         agent_client.agent_session.session_id)
     self._settings = StepSettings()
Ejemplo n.º 9
0
def test_job_name_is_inferred_correctly():
    assert ReportHelper.infer_job_name() == "reporthelper_test"
Ejemplo n.º 10
0
def test_project_name_is_inferred_correctly():
    assert ReportHelper.infer_project_name() == "tests.ci.unittests.helpers"
Ejemplo n.º 11
0
def test_test_name_is_inferred_correctly_from_method_name():
    assert (
        ReportHelper.infer_test_name()
        == "test_test_name_is_inferred_correctly_from_method_name"
    )
Ejemplo n.º 12
0
    def __init__(
        self,
        desired_capabilities: dict = None,
        token: str = None,
        project_name: str = None,
        job_name: str = None,
        disable_reports: bool = False,
    ):
        if Remote.__instance is not None:
            raise SdkException("A driver session already exists")

        LoggingHelper.configure_logging()

        self._desired_capabilities = desired_capabilities

        self._token = token if token is not None else ConfigHelper.get_developer_token(
        )

        if disable_reports:
            # Setting the project and job name to empty strings will cause the Agent to not initialize a report
            self._project_name = ""
            self._job_name = ""
        else:
            self._project_name = (project_name if project_name is not None else
                                  ReportHelper.infer_project_name())

            if job_name:
                self._job_name = job_name
            else:
                self._job_name = ReportHelper.infer_job_name()
                # Can update job name at runtime if not specified.
                os.environ[
                    EnvironmentVariable.TP_UPDATE_JOB_NAME.value] = "True"

        report_settings = ReportSettings(self._project_name, self._job_name)

        self._agent_client: AgentClient = AgentClient(
            token=self._token,
            capabilities=self._desired_capabilities,
            report_settings=report_settings,
        )
        self._agent_session: AgentSession = self._agent_client.agent_session
        self.w3c = True if self._agent_session.dialect == "W3C" else False

        AppiumWebDriver.__init__(
            self,
            command_executor=self._agent_session.remote_address,
            desired_capabilities=self._desired_capabilities,
        )

        self.command_executor = CustomAppiumCommandExecutor(
            agent_client=self._agent_client,
            remote_server_addr=self._agent_session.remote_address,
        )

        # this ensures that mobile-specific commands are also available for our command executor
        self._addCommands()

        # Disable automatic command and test reports if Behave reporting is enabled.
        if os.getenv("TP_DISABLE_AUTO_REPORTING") == "True":
            self.command_executor.disable_command_reports = True
            self.command_executor.disable_auto_test_reports = True

        Remote.__instance = self
Ejemplo n.º 13
0
    def __init__(
        self,
        capabilities: dict,
        token: str,
        project_name: str,
        job_name: str,
        disable_reports: bool,
        report_type: ReportType,
    ):

        if BaseDriver.__instance is not None:
            raise SdkException("A driver session already exists")

        LoggingHelper.configure_logging()

        if token is not None:
            logging.info(f"Token used as specified in constructor: {token}")

        self._token = token if token is not None else ConfigHelper.get_developer_token(
        )

        if disable_reports:
            # Setting the project and job name to empty strings will cause the Agent to not initialize a report
            self._project_name = ""
            self._job_name = ""
        else:
            self._project_name = project_name if project_name is not None else ReportHelper.infer_project_name(
            )

            if job_name:
                self._job_name = job_name
            else:
                self._job_name = ReportHelper.infer_job_name()
                # Can update job name at runtime if not specified.
                os.environ[
                    EnvironmentVariable.TP_UPDATE_JOB_NAME.value] = "True"

        self._agent_client: AgentClient = AgentClient(
            token=self._token,
            capabilities=capabilities,
            report_settings=ReportSettings(self._project_name, self._job_name,
                                           report_type),
        )
        self._agent_session: AgentSession = self._agent_client.agent_session
        self.w3c = True if self._agent_session.dialect == "W3C" else False

        # Create a custom command executor to enable:
        # - automatic logging capabilities
        # - customized reporting settings
        self.command_executor = CustomCommandExecutor(
            agent_client=self._agent_client,
            remote_server_addr=self._agent_session.remote_address,
        )

        self.command_executor.disable_reports = disable_reports

        # Disable automatic command and test reports if Behave reporting is enabled.
        if os.getenv("TP_DISABLE_AUTO_REPORTING") == "True":
            self.command_executor.disable_command_reports = True
            self.command_executor.disable_auto_test_reports = True

        RemoteWebDriver.__init__(
            self,
            command_executor=self.command_executor,
            desired_capabilities=self._agent_session.capabilities,
        )

        BaseDriver.__instance = self
Ejemplo n.º 14
0
def test_test_name_is_inferred_correctly():
    assert ReportHelper.infer_test_name(
    ) == "test_test_name_is_inferred_correctly"