Skip to content

Commit e8ea54e

Browse files
authored
Merge pull request #133 from seleniumbase/files_update
Adding methods for processing downloaded files
2 parents 86fc61a + 5895214 commit e8ea54e

File tree

7 files changed

+40
-15
lines changed

7 files changed

+40
-15
lines changed

README.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![](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)
44

5-
**Test Automation Framework for Python**
5+
**A Test Automation Framework for Python**
66

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

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

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

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

591591
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)
592592

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

596596
~ Michael Mintz<br>
597-
[https://github.com/mdmintz](https://github.com/mdmintz)<br>[https://www.linkedin.com/in/mdmintz](https://www.linkedin.com/in/mdmintz)
598-
599-
600-
### ![http://seleniumbase.com](https://cdn2.hubspot.net/hubfs/100006/images/super_logo_tiny.png "SeleniumBase") License
601-
602-
[The MIT License!](https://github.com/seleniumbase/SeleniumBase/blob/master/LICENSE)
597+
[https://github.com/mdmintz](https://github.com/mdmintz)<br>
598+
[https://www.linkedin.com/in/mdmintz](https://www.linkedin.com/in/mdmintz)
603599

604600
![](https://cdn2.hubspot.net/hubfs/100006/images/logo_base_10.png "SeleniumBase")

_config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
theme: jekyll-theme-cayman
22
title: SeleniumBase
3-
description: Framework for building test automation
3+
description: A simple Python framework for building test automation with WebDriver

help_docs/method_summary.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,14 @@ self.download_file(file_url, destination_folder=None)
8989

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

92+
self.get_downloads_folder(file):
93+
94+
self.get_path_of_downloaded_file(file):
95+
96+
self.is_downloaded_file_present(file):
97+
98+
self.assert_downloaded_file(file):
99+
92100
self.convert_xpath_to_css(xpath)
93101

94102
self.convert_to_css_selector(selector, by)

seleniumbase/core/download_helper.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@ def reset_downloads_folder():
2727
ARCHIVE_DIR)
2828
if not os.path.exists(archived_downloads_folder):
2929
os.makedirs(archived_downloads_folder)
30-
archived_downloads_folder = "%sdownloads_%s" % (
30+
new_archived_downloads_sub_folder = "%s/downloads_%s" % (
3131
archived_downloads_folder, int(time.time()))
32-
shutil.move(downloads_path, archived_downloads_folder)
32+
shutil.move(downloads_path, new_archived_downloads_sub_folder)
3333
os.makedirs(downloads_path)
3434
if not settings.ARCHIVE_EXISTING_DOWNLOADS:
35-
shutil.rmtree(archived_downloads_folder)
35+
try:
36+
shutil.rmtree(new_archived_downloads_sub_folder)
37+
except OSError:
38+
pass

seleniumbase/fixtures/base_case.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class MyTestClass(BaseCase):
3838
from seleniumbase.core.testcase_manager import TestcaseDataPayload
3939
from seleniumbase.core.testcase_manager import TestcaseManager
4040
from seleniumbase.core import browser_launcher
41+
from seleniumbase.core import download_helper
4142
from seleniumbase.core import log_helper
4243
from seleniumbase.fixtures import constants
4344
from seleniumbase.fixtures import page_actions
@@ -688,6 +689,23 @@ def save_file_as(self, file_url, new_file_name, destination_folder=None):
688689
page_utils._download_file_to(
689690
file_url, destination_folder, new_file_name)
690691

692+
def get_downloads_folder(self):
693+
""" Returns the OS path of the Downloads Folder.
694+
(Works with Chrome and Firefox only, for now.) """
695+
return download_helper.get_downloads_folder()
696+
697+
def get_path_of_downloaded_file(self, file):
698+
""" Returns the OS path of the downloaded file. """
699+
return os.path.join(self.get_downloads_folder(), file)
700+
701+
def is_downloaded_file_present(self, file):
702+
""" Checks if the file exists in the Downloads Folder. """
703+
return os.path.exists(self.get_path_of_downloaded_file(file))
704+
705+
def assert_downloaded_file(self, file):
706+
""" Asserts that the file exists in the Downloads Folder. """
707+
assert os.path.exists(self.get_path_of_downloaded_file(file))
708+
691709
def convert_xpath_to_css(self, xpath):
692710
return xpath_to_css.convert_xpath_to_css(xpath)
693711

server_setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
setup(
1010
name='seleniumbase',
11-
version='1.4.14',
11+
version='1.4.15',
1212
description='Web Automation & Testing Framework - http://seleniumbase.com',
1313
long_description='Web Automation and Testing Framework - seleniumbase.com',
1414
platforms='Mac * Windows * Linux * Docker',

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
"""
22
The setup package to install SeleniumBase dependencies and plugins
3-
(Uses the newer Selenium 3.6.0)
3+
(Uses the newer Selenium 3.8.0)
44
"""
55

66
import os
77
from setuptools import setup, find_packages # noqa
88

99
setup(
1010
name='seleniumbase',
11-
version='1.4.14',
11+
version='1.4.15',
1212
description='Web Automation & Testing Framework - http://seleniumbase.com',
1313
long_description='Web Automation and Testing Framework - seleniumbase.com',
1414
platforms='Mac * Windows * Linux * Docker',

0 commit comments

Comments
 (0)