Exemplo n.º 1
0
 def save_html(self, prefix=None):
     filename = "{}.{}.html".format(prefix, now_to_str())
     full_filename = os.path.join(self.screenshots_directory, filename)
     with open(full_filename, "w", encoding="utf-8") as f:
         f.write(self.browser.page_source)
     self.logger.log("HTML saved on {}".format(full_filename))
     return full_filename
Exemplo n.º 2
0
 def __initialize_filename(self):
     base_directory = os.sep.join(
         os.path.dirname(__file__).split(os.sep)[:-2])
     test_logs_directory = os.path.join(base_directory, "logs")
     if not os.path.exists(test_logs_directory):
         os.makedirs(test_logs_directory)
     return os.path.join(test_logs_directory,
                         "{}_{}.txt".format(self.test_name, now_to_str()))
Exemplo n.º 3
0
    def test_create_issue_in_gitlab_project(self):
        """
        Given a GITLAB_KEY
        And a search for gpaoliveira_playground was made
        When an issue is created with today's date
        And project issues are searched for using created issue name
        Then the same issue is returned
        """
        self.log_step("Given a GITLAB_KEY")
        if not self.environment.GITLAB_KEY:
            self.then_everything_should_be_fine(["No GITLAB_KEY"])

        self.log_step("Given a search for gpaoliveira_playground was made")
        equals = EqualDeep()
        api = ApiGitlab(self.environment.GITLAB_BASE,
                        self.environment.GITLAB_KEY)
        project: GitlabProject = api.search_project("gpaoliveira_playground")
        self.add_output_message(str(project))
        if not equals.run(target=project, name="gpaoliveira_playground"):
            self.then_everything_should_be_fine(equals.error_messages)

        self.log_step("When an issue is created with today's date")
        now = now_to_str()
        issue_name = "Issue {}".format(now)
        self.add_output_message("Creating '{}'".format(issue_name))
        issue = api.create_bug(project, issue_name)
        self.add_output_message(str(issue))
        if not equals.run(target=issue, name=issue_name):
            self.then_everything_should_be_fine(equals.error_messages)

        self.log_step(
            "When project issues are searched for using created issue name")
        self.add_output_message("Retrieving {}".format(issue_name))
        listed_issue = api.list_issues_project(project, issue_name)
        self.add_output_message(str(listed_issue))
        if not equals.run(target=listed_issue, name=issue_name):
            self.then_everything_should_be_fine(equals.error_messages)

        self.log_step("Then the same issue is returned")
        equals = EqualDeep()
        if not equals.two_objects(issue, listed_issue):
            self.then_everything_should_be_fine([
                "issue != retrieved - {}".format(",".join(
                    equals.error_messages))
            ])

        self.then_everything_should_be_fine()
Exemplo n.º 4
0
 def with_random_user(self, password):
     self.user = "******" + now_to_str()
     self.email = self.user + "@email.com"
     try:
         self.FIRSTNAME_INPUT.type("Test")
         self.LASTNAME_INPUT.type("User")
         self.EMAIL_INPUT.type(self.email.replace("\"", ""))
         self.CONFIRM_EMAIL_INPUT.type(self.email.replace("\"", ""))
         self.PASSWORD_INPUT.type(password.replace("\"", ""), hide=True)
         self.CONFIRM_PASSWORD_INPUT.type(password.replace("\"", ""),
                                          hide=True)
         self.SIGNUP_BUTTON.click(10)
         self.add_to_output("SIGNUP_BUTTON clicked with user '{}'".format(
             self.email))
     except Exception as e:
         self.exception_to_error_message(e)
     return self.load_new_page(PageLearn)
Exemplo n.º 5
0
 def save_screenshot(self, prefix=None):
     filename = "{}.{}.png".format(prefix, now_to_str())
     full_filename = os.path.join(self.screenshots_directory, filename)
     self.browser.save_screenshot(filename=full_filename)
     self.logger.log("Screenshot saved on {}".format(full_filename))
     return full_filename
Exemplo n.º 6
0
 def add_to_output(self, message):
     self.output_messages.append("[{}] {}".format(now_to_str(), message))
Exemplo n.º 7
0
    def __init__(self,
                 url,
                 method=METHOD_GET,
                 request_headers={},
                 authorization=None,
                 proxies=None,
                 plain_body=None,
                 json_body=None,
                 ignore_response_body=False,
                 expected_response_code=200,
                 expected_headers=None,
                 expected_verifications=DEFAULT_VERIFICATIONS,
                 override_base_filename=None,
                 override_base_folder=None):
        self.method = method
        self.url = url
        self.body = plain_body
        if not self.body and json_body:
            self.body = json.dumps(json_body)
        self.ignore_response_body = ignore_response_body
        self.request_headers = request_headers
        self.authorization = authorization
        self.proxies = proxies
        self.status_code = 0
        self.expected_response_code = expected_response_code
        self.response_headers = {}
        self.expected_headers = expected_headers
        self.expected_verifications = expected_verifications

        # Attributes to control caching (cached_filename) and where the data is stored when saved (filename)
        self.filename = None
        base_name = (self.__safe_string(self.url) + now_to_str()
                     if not override_base_filename else override_base_filename)
        self._base_name = (os.path.join(
            override_base_folder if override_base_folder else self.BASE_FOLDER,
            base_name))
        self.cached_filename = self._base_name + self.CACHE_EXTENSION

        # Declare response time (time between request and all download) and
        # latency time (time between request and response headers) and
        # full time (time between request and response saved in filesystem)
        self.elapsed_time = 0
        self.latency_time = 0
        self.full_time = 0

        # Declare the response data (in plain, as it came) and the dict representation of it
        # If the response content type is a binary one, nothing is saved in those
        # but a file is created with the proposed filename (and the flag self.is_binary is set to True)
        # Real data content len is also stored, for further checks with Header Content-Length
        self._data = None
        self.is_binary = False
        self._dict = None
        self.content_len = 0

        # Misc stuff
        self.error_messages = []
        self._request_begin_time = None
        self._requested = False
        self._retries = 3
        self._sleep_between_retries = 0.1
        self._logger = Logger(name=self.__class__.__name__)
        logging.getLogger("requests").setLevel(logging.ERROR)
        logging.getLogger("urllib").setLevel(logging.ERROR)
        logging.getLogger("urllib3").setLevel(logging.ERROR)
        requests.packages.urllib3.disable_warnings()
Exemplo n.º 8
0
    def test_create_issue_in_github_project(self):
        """
        Given a GITHUB_KEY
        And 'playground' repository is found using v3
        When an issue is created with today's date
        And the list of issues in the project is retrieved
        And that same issue is retrieved
        Then they all have the same issue information
        """
        equals = EqualDeep()
        self.log_step("Given a GITHUB_KEY")
        if not self.environment.GITHUB_KEY:
            self.then_everything_should_be_fine(["No GITHUB_KEY"])

        self.log_step("Given 'playground' repository is found using v3")
        api = ApiGithub(self.environment.GITHUB_BASE,
                        self.environment.GITHUB_KEY)
        repositories_v3: List[GithubRepository] = api.user_repositories_v3()
        self.flush_api_messages(api)
        target_repos_v3: List[GithubRepository] = [
            r for r in repositories_v3 if r.name == "playground"
        ]
        target_repo_v3 = None
        if not target_repos_v3:
            self.then_everything_should_be_fine(
                ["No 'playground' repository found in v3"])
        else:
            target_repo_v3 = target_repos_v3[0]
            self.add_output_message("Target repository using v3:\n" +
                                    str(target_repo_v3))

        self.log_step("When an issue is created with today's date")
        now = now_to_str()
        issue_name = "Issue {}".format(now)
        self.add_output_message("Creating '{}'".format(issue_name))
        issue = api.create_issue_in_repo(target_repo_v3,
                                         name=issue_name,
                                         labels=["bug"],
                                         description=issue_name)
        self.add_output_message(str(issue))
        if not equals.run(target=issue, name=issue_name):
            self.then_everything_should_be_fine(equals.error_messages)

        self.log_step("When the list of issues in the project is retrieved")
        issues = api.list_issues_in_repo(target_repo_v3)
        issues_with_same_title = [i for i in issues if i.name == issue_name]
        listed_issue = None
        if not issues_with_same_title:
            self.add_fail_message(
                "No issue with title '{}' found in repo".format(issue_name))
        else:
            self.add_output_message("Listed '{}'".format(issue_name))
            listed_issue = issues_with_same_title[0]
            self.add_output_message(str(listed_issue))

        self.log_step("When that same issue is retrieved")
        self.add_output_message("Retrieving '{}'".format(issue_name))
        retrieved_issue = api.retrieve_single_issue(issue)
        self.add_output_message(str(retrieved_issue))

        self.log_step("Then they all have the same issue information")
        equals = EqualDeep()
        if not equals.two_objects(issue, retrieved_issue):
            self.then_everything_should_be_fine([
                "issue created != retrieved - {}".format(",".join(
                    equals.error_messages))
            ])
        else:
            self.add_output_message("issue created == retrieved")
        if not equals.two_objects(issue, listed_issue):
            self.then_everything_should_be_fine([
                "issue created != listed - {}".format(",".join(
                    equals.error_messages))
            ])
        else:
            self.add_output_message("issue created == listed")

        self.then_everything_should_be_fine()