forked from brandicted/scrapy-webdriver
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed a bug WRT webdriver initialization and added tests
- Loading branch information
Showing
5 changed files
with
79 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from scrapy.crawler import Crawler | ||
from scrapy.settings import Settings | ||
from selenium import webdriver | ||
|
||
from scrapy_webdriver.manager import WebdriverManager | ||
|
||
BASE_SETTINGS = dict( | ||
DOWNLOAD_HANDLERS={ | ||
'http': 'scrapy_webdriver.download.WebdriverDownloadHandler', | ||
'https': 'scrapy_webdriver.download.WebdriverDownloadHandler', | ||
}, | ||
SPIDER_MIDDLEWARES={ | ||
'scrapy_webdriver.middlewares.WebdriverSpiderMiddleware': 543, | ||
}) | ||
|
||
|
||
class TestManager: | ||
@classmethod | ||
def setup_class(cls): | ||
cls._settings = BASE_SETTINGS | ||
|
||
def settings(self, **options): | ||
settings = self._settings.copy() | ||
settings.update(**options) | ||
return settings | ||
|
||
def test_browser_config(self): | ||
class TestBrowser(object): | ||
pass | ||
|
||
settings = self.settings(WEBDRIVER_BROWSER='Firefox') | ||
crawler = Crawler(Settings(values=settings)) | ||
crawler.configure() | ||
browser = WebdriverManager(crawler) | ||
assert issubclass(browser._browser, webdriver.Firefox) | ||
|
||
settings = self.settings(WEBDRIVER_BROWSER=TestBrowser) | ||
crawler = Crawler(Settings(values=settings)) | ||
crawler.configure() | ||
browser = WebdriverManager(crawler) | ||
assert issubclass(browser._browser, TestBrowser) | ||
|
||
settings = self.settings(WEBDRIVER_BROWSER=TestBrowser()) | ||
crawler = Crawler(Settings(values=settings)) | ||
crawler.configure() | ||
browser = WebdriverManager(crawler) | ||
assert isinstance(browser._webdriver, TestBrowser) |