Skip to content

Adding methods for processing downloaded files #133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![](https://img.shields.io/pypi/v/seleniumbase.svg)](https://pypi.python.org/pypi/seleniumbase) [![Build Status](https://travis-ci.org/seleniumbase/SeleniumBase.svg?branch=master)](https://travis-ci.org/seleniumbase/SeleniumBase) [![Join the chat at https://gitter.im/seleniumbase/SeleniumBase](https://badges.gitter.im/seleniumbase/SeleniumBase.svg)](https://gitter.im/seleniumbase/SeleniumBase?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

**Test Automation Framework for Python**
**A Test Automation Framework for Python**

![](https://cdn2.hubspot.net/hubfs/100006/images/sb_demo.gif "SeleniumBase")

Expand Down Expand Up @@ -586,19 +586,15 @@ Delayed Data Manager usage example: If you scheduled an email to go out 12 hours

### ![http://seleniumbase.com](https://cdn2.hubspot.net/hubfs/100006/images/super_logo_tiny.png "SeleniumBase") Wrap-Up

Congratulations! You now know how to **Automate like a Pro!**
Congratulations on making it through this ReadMe tutorial!

Questions or Comments? [![Join the chat at https://gitter.im/seleniumbase/SeleniumBase](https://badges.gitter.im/seleniumbase/SeleniumBase.svg)](https://gitter.im/seleniumbase/SeleniumBase?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

Here are some other exciting open source projects on GitHub by smart people I've worked with:
[https://github.com/hubspot](https://github.com/hubspot)

~ Michael Mintz<br>
[https://github.com/mdmintz](https://github.com/mdmintz)<br>[https://www.linkedin.com/in/mdmintz](https://www.linkedin.com/in/mdmintz)


### ![http://seleniumbase.com](https://cdn2.hubspot.net/hubfs/100006/images/super_logo_tiny.png "SeleniumBase") License

[The MIT License!](https://github.com/seleniumbase/SeleniumBase/blob/master/LICENSE)
[https://github.com/mdmintz](https://github.com/mdmintz)<br>
[https://www.linkedin.com/in/mdmintz](https://www.linkedin.com/in/mdmintz)

![](https://cdn2.hubspot.net/hubfs/100006/images/logo_base_10.png "SeleniumBase")
2 changes: 1 addition & 1 deletion _config.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
theme: jekyll-theme-cayman
title: SeleniumBase
description: Framework for building test automation
description: A simple Python framework for building test automation with WebDriver
8 changes: 8 additions & 0 deletions help_docs/method_summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ self.download_file(file_url, destination_folder=None)

self.save_file_as(file_url, new_file_name, destination_folder=None)

self.get_downloads_folder(file):

self.get_path_of_downloaded_file(file):

self.is_downloaded_file_present(file):

self.assert_downloaded_file(file):

self.convert_xpath_to_css(xpath)

self.convert_to_css_selector(selector, by)
Expand Down
9 changes: 6 additions & 3 deletions seleniumbase/core/download_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ def reset_downloads_folder():
ARCHIVE_DIR)
if not os.path.exists(archived_downloads_folder):
os.makedirs(archived_downloads_folder)
archived_downloads_folder = "%sdownloads_%s" % (
new_archived_downloads_sub_folder = "%s/downloads_%s" % (
archived_downloads_folder, int(time.time()))
shutil.move(downloads_path, archived_downloads_folder)
shutil.move(downloads_path, new_archived_downloads_sub_folder)
os.makedirs(downloads_path)
if not settings.ARCHIVE_EXISTING_DOWNLOADS:
shutil.rmtree(archived_downloads_folder)
try:
shutil.rmtree(new_archived_downloads_sub_folder)
except OSError:
pass
18 changes: 18 additions & 0 deletions seleniumbase/fixtures/base_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class MyTestClass(BaseCase):
from seleniumbase.core.testcase_manager import TestcaseDataPayload
from seleniumbase.core.testcase_manager import TestcaseManager
from seleniumbase.core import browser_launcher
from seleniumbase.core import download_helper
from seleniumbase.core import log_helper
from seleniumbase.fixtures import constants
from seleniumbase.fixtures import page_actions
Expand Down Expand Up @@ -688,6 +689,23 @@ def save_file_as(self, file_url, new_file_name, destination_folder=None):
page_utils._download_file_to(
file_url, destination_folder, new_file_name)

def get_downloads_folder(self):
""" Returns the OS path of the Downloads Folder.
(Works with Chrome and Firefox only, for now.) """
return download_helper.get_downloads_folder()

def get_path_of_downloaded_file(self, file):
""" Returns the OS path of the downloaded file. """
return os.path.join(self.get_downloads_folder(), file)

def is_downloaded_file_present(self, file):
""" Checks if the file exists in the Downloads Folder. """
return os.path.exists(self.get_path_of_downloaded_file(file))

def assert_downloaded_file(self, file):
""" Asserts that the file exists in the Downloads Folder. """
assert os.path.exists(self.get_path_of_downloaded_file(file))

def convert_xpath_to_css(self, xpath):
return xpath_to_css.convert_xpath_to_css(xpath)

Expand Down
2 changes: 1 addition & 1 deletion server_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

setup(
name='seleniumbase',
version='1.4.14',
version='1.4.15',
description='Web Automation & Testing Framework - http://seleniumbase.com',
long_description='Web Automation and Testing Framework - seleniumbase.com',
platforms='Mac * Windows * Linux * Docker',
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
"""
The setup package to install SeleniumBase dependencies and plugins
(Uses the newer Selenium 3.6.0)
(Uses the newer Selenium 3.8.0)
"""

import os
from setuptools import setup, find_packages # noqa

setup(
name='seleniumbase',
version='1.4.14',
version='1.4.15',
description='Web Automation & Testing Framework - http://seleniumbase.com',
long_description='Web Automation and Testing Framework - seleniumbase.com',
platforms='Mac * Windows * Linux * Docker',
Expand Down