| 39 | self.commands = Commands(self.io, None) |
| 40 | |
| 41 | def test_cmd_web_imports_playwright(self): |
| 42 | # Create a mock print_error function |
| 43 | mock_print_error = MagicMock() |
| 44 | self.commands.io.tool_error = mock_print_error |
| 45 | |
| 46 | # Run the cmd_web command |
| 47 | result = self.commands.cmd_web("https://example.com", return_content=True) |
| 48 | |
| 49 | # Assert that the result contains some content |
| 50 | self.assertIsNotNone(result) |
| 51 | self.assertNotEqual(result, "") |
| 52 | |
| 53 | # Try to import playwright |
| 54 | try: |
| 55 | import playwright # noqa: F401 |
| 56 | |
| 57 | playwright_imported = True |
| 58 | except ImportError: |
| 59 | playwright_imported = False |
| 60 | |
| 61 | # Assert that playwright was successfully imported |
| 62 | self.assertTrue( |
| 63 | playwright_imported, "Playwright should be importable after running cmd_web" |
| 64 | ) |
| 65 | |
| 66 | # Assert that print_error was never called |
| 67 | mock_print_error.assert_not_called() |
| 68 | |
| 69 | def test_scrape_actual_url_with_playwright(self): |
| 70 | # Create a Scraper instance with a mock print_error function |