forked from geekan/MetaGPT
-
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.
- Loading branch information
1 parent
ef279fd
commit e657f29
Showing
4 changed files
with
126 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import pytest | ||
from metagpt.config import Config | ||
from metagpt.tools import web_browser_engine, WebBrowserEngineType | ||
|
||
|
||
@pytest.mark.asyncio | ||
@pytest.mark.parametrize( | ||
"browser_type, url, urls", | ||
[ | ||
(WebBrowserEngineType.PLAYWRIGHT, "https://fuzhi.ai", ("https://fuzhi.ai",)), | ||
(WebBrowserEngineType.SELENIUM, "https://fuzhi.ai", ("https://fuzhi.ai",)), | ||
], | ||
ids=["playwright", "selenium"], | ||
) | ||
async def test_scrape_web_page(browser_type, url, urls): | ||
browser = web_browser_engine.WebBrowserEngine(browser_type) | ||
result = await browser.run(url) | ||
assert isinstance(result, str) | ||
assert "深度赋智" in result | ||
|
||
if urls: | ||
results = await browser.run(url, *urls) | ||
assert isinstance(results, list) | ||
assert len(results) == len(urls) + 1 | ||
assert all(("深度赋智" in i) for i in results) |
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,35 @@ | ||
import pytest | ||
from metagpt.config import Config | ||
from metagpt.tools import web_browser_engine_playwright | ||
|
||
|
||
@pytest.mark.asyncio | ||
@pytest.mark.parametrize( | ||
"browser_type, use_proxy, kwagrs, url, urls", | ||
[ | ||
("chromium", {"proxy": True}, {}, "https://fuzhi.ai", ("https://fuzhi.ai",)), | ||
("firefox", {}, {"ignore_https_errors": True}, "https://fuzhi.ai", ("https://fuzhi.ai",)), | ||
("webkit", {}, {"ignore_https_errors": True}, "https://fuzhi.ai", ("https://fuzhi.ai",)), | ||
], | ||
ids=["chromium-normal", "firefox-normal", "webkit-normal"], | ||
) | ||
async def test_scrape_web_page(browser_type, use_proxy, kwagrs, url, urls, proxy, capfd): | ||
try: | ||
config = Config() | ||
global_proxy = config.global_proxy | ||
if use_proxy: | ||
config.global_proxy = proxy | ||
browser = web_browser_engine_playwright.PlaywrightWrapper(browser_type, **kwagrs) | ||
result = await browser.run(url) | ||
assert isinstance(result, str) | ||
assert "Deepwisdom" in result | ||
|
||
if urls: | ||
results = await browser.run(url, *urls) | ||
assert isinstance(results, list) | ||
assert len(results) == len(urls) + 1 | ||
assert all(("Deepwisdom" in i) for i in results) | ||
if use_proxy: | ||
assert "Proxy:" in capfd.readouterr().out | ||
finally: | ||
config.global_proxy = global_proxy |
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,35 @@ | ||
import pytest | ||
from metagpt.config import Config | ||
from metagpt.tools import web_browser_engine_selenium | ||
|
||
|
||
@pytest.mark.asyncio | ||
@pytest.mark.parametrize( | ||
"browser_type, use_proxy, url, urls", | ||
[ | ||
("chrome", True, "https://fuzhi.ai", ("https://fuzhi.ai",)), | ||
("firefox", False, "https://fuzhi.ai", ("https://fuzhi.ai",)), | ||
("edge", False, "https://fuzhi.ai", ("https://fuzhi.ai",)), | ||
], | ||
ids=["chrome-normal", "firefox-normal", "edge-normal"], | ||
) | ||
async def test_scrape_web_page(browser_type, use_proxy, url, urls, proxy, capfd): | ||
try: | ||
config = Config() | ||
global_proxy = config.global_proxy | ||
if use_proxy: | ||
Config().global_proxy = proxy | ||
browser = web_browser_engine_selenium.SeleniumWrapper(browser_type) | ||
result = await browser.run(url) | ||
assert isinstance(result, str) | ||
assert "Deepwisdom" in result | ||
|
||
if urls: | ||
results = await browser.run(url, *urls) | ||
assert isinstance(results, list) | ||
assert len(results) == len(urls) + 1 | ||
assert all(("Deepwisdom" in i) for i in results) | ||
if use_proxy: | ||
assert "Proxy:" in capfd.readouterr().out | ||
finally: | ||
config.global_proxy = global_proxy |