Skip to content
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

Update pyvirtualdisplay #831

Closed
Closed
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
25fe8e9
manual test breaking post-#807
MollieBakal Dec 3, 2020
d112642
replacing with standard json function for single string
MollieBakal Dec 3, 2020
79aa598
modifying test to see if stops running for over two hours:
MollieBakal Dec 3, 2020
b08dfe1
Reverting error, updating function to current name
MollieBakal Dec 4, 2020
2d6cfb2
Deleted redundant files and references to default_browser_params.json…
ankushduacodes Dec 9, 2020
6bab765
Merge branch 'post-rename-fixes' of https://github.com/MollieBakal/Op…
MollieBakal Dec 13, 2020
e694157
Attempted fix treats display as object
MollieBakal Dec 13, 2020
abcd7d1
changing display; pytest unchanged
MollieBakal Dec 13, 2020
5795552
added a test case to ensure xvfb runs
MollieBakal Dec 13, 2020
65d010b
simplifying test
MollieBakal Dec 13, 2020
6afb484
Merge pull request #2 from mozilla/master
MollieBakal Dec 14, 2020
58b0ff8
Bump ini in /openwpm/Extension/webext-instrumentation (#828)
dependabot[bot] Dec 14, 2020
2064b91
Bump ini from 1.3.5 to 1.3.8 in /openwpm/Extension/firefox (#829)
dependabot[bot] Dec 14, 2020
fc7c772
Bump ini from 1.3.5 to 1.3.8 (#827)
dependabot[bot] Dec 14, 2020
1255cdb
manual test breaking post-#807
MollieBakal Dec 3, 2020
9832dae
replacing with standard json function for single string
MollieBakal Dec 3, 2020
a90269f
modifying test to see if stops running for over two hours:
MollieBakal Dec 3, 2020
4d17abf
Deleted redundant files and references to default_browser_params.json…
ankushduacodes Dec 9, 2020
62daf22
Attempted fix treats display as object
MollieBakal Dec 13, 2020
4757896
changing display; pytest unchanged
MollieBakal Dec 13, 2020
774e4d6
added a test case to ensure xvfb runs
MollieBakal Dec 13, 2020
641f168
simplifying test
MollieBakal Dec 13, 2020
bfede3f
fixing requested issues
MollieBakal Dec 15, 2020
bcb16fb
Merge branch 'post-rename-fixes' of https://github.com/MollieBakal/Op…
MollieBakal Dec 15, 2020
b693700
runs; modified test to include exception
MollieBakal Dec 15, 2020
ebe318e
Merge branch 'master' into post-rename-fixes
MollieBakal Dec 15, 2020
f0bba54
fix import
MollieBakal Dec 15, 2020
e622378
Merge branch 'post-rename-fixes' of https://github.com/MollieBakal/Op…
MollieBakal Dec 15, 2020
f20e6c3
Queue not optional; removed
MollieBakal Dec 15, 2020
e15acf8
updated test to check for lockfile
MollieBakal Dec 15, 2020
43aa5d1
Update test/test_xvfb_browser.py
MollieBakal Dec 16, 2020
1ac71d3
sticky key in the last commit, same change
MollieBakal Dec 16, 2020
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ Quick Start

Once installed, it is very easy to run a quick test of OpenWPM. Check out
`demo.py` for an example. This will use the default setting specified in
`openwpm/default_manager_params.json` and
`openwpm/default_browser_params.json`, with the exception of the changes
`openwpm/config.py::ManagerParams` and
`openwpm/config.py::BrowserParams`, with the exception of the changes
specified in `demo.py`.

More information on the instrumentation and configuration parameters is given
Expand Down
9 changes: 7 additions & 2 deletions docs/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ To load the default configuration create instances of `config::ManagerParams` an
from openwpm.config import BrowserParams, ManagerParams

manager_params = ManagerParams(num_browsers=5)
browser_params = [BrowserParams() for _ in range(num_browsers)]
browser_params = [BrowserParams() for _ in range(manager_params.num_browsers)]
```

where `manager_params` is of type `class<ManagerParams>` and `browser_params` is a length 5 list
Expand All @@ -20,11 +20,16 @@ of configurations of `class<BrowserParams>`.
####Validations:
To validate `browser_params` and `manager_params`, we have two methods each for type of params, `config::validate_browser_params` and `config::validate_manager_params`. For example:
```python
from openwpm.config import validate_browser_params, validate_manager_params
from openwpm.config import (
validate_browser_params,
validate_manager_params,
validate_crawl_configs,
)

for bp in browser_params:
validate_browser_params(bp)
validate_manager_params(manager_params)
validate_crawl_configs(manager_params, browser_params)
```
**NOTE**: If any validations fail, we raise `ConfigError`

Expand Down
28 changes: 22 additions & 6 deletions docs/Platform-Architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,33 @@ The user-facing component of the OpenWPM platform is the Task Manager. The Task

## Instantiating a Task Manager

All automation code is contained within the `openwpm` folder; the Task Manager code is contained in `openwpm/TaskManager.py`.
All automation code is contained within the `openwpm` folder; the Task Manager code is contained in `openwpm/task_manager.py`.

Task Managers can be instantiated in the following way:
```python
from opemwpm.task_manager import TaskManager
from openwpm.config import (
BrowserParams,
ManagerParams,
)

`manager = TaskManager.TaskManager(manager_params, browser_params)`
number_of_browser = 5 # Number of browsers to spawn

# Instantiating Browser and Manager Params with default values.
manager_params = ManagerParams(num_browsers = number_of_browsers)
browser_params = [BrowserParams() for bp in range(manager_params.num_browsers)]

# These instances can be used to modify default values of both browser and manager params.
manager_params.data_directory = '~/Documents'
manager_params.database_name = 'custom_name.sqlite'

for i in range(len(browser_params)):
browser_params[i].display_mode = 'headless' # all 5 browsers will spawn in headless mode

# Instantiating TaskManager
manager = TaskManager(manager_params, browser_params)

You can call
```python
manager_params, browser_params = TaskManager.load_default_params(number_of_browsers_to_spawn)
```
to get the default parameters.

To learn more about the `manager_params` and `browser_params` have a look at [Configuration.md](Configuration.md)

Expand Down
2 changes: 1 addition & 1 deletion docs/Using_OpenWPM.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Users can change the settings for task manager and individual browsers so that,
from openwpm.config import BrowserParams, ManagerParams

manager_params = ManagerParams(num_browsers=5)
browser_params = [BrowserParams() for _ in range(num_browsers)]
browser_params = [BrowserParams() for _ in range(manager_params.num_browsers)]
```

#### Loading Custom Browser or Manager configs
Expand Down
2 changes: 1 addition & 1 deletion environment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ dependencies:
- pytest-cov=2.10.1
- pytest=6.1.2
- python=3.8.6
- pyvirtualdisplay=0.2.5
- pyvirtualdisplay=1.3.2
vringar marked this conversation as resolved.
Show resolved Hide resolved
- redis-py=3.5.3
- s3fs=0.4.0
- selenium=3.141.0
Expand Down
4 changes: 3 additions & 1 deletion openwpm/browser_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ def BrowserManager(
logger = logging.getLogger("openwpm")
try:
# Start Xvfb (if necessary), webdriver, and browser
driver, prof_folder = deploy_firefox.deploy_firefox(
driver, prof_folder, display = deploy_firefox.deploy_firefox(
status_queue, browser_params, manager_params, crash_recovery
)
if prof_folder[-1] != "/":
Expand Down Expand Up @@ -497,6 +497,8 @@ def BrowserManager(
if driver.profile and not os.path.isdir(driver.profile.path):
driver.profile = None
driver.quit()
if browser_params.display_mode == "xvfb":
display.stop()
status_queue.put("OK")
return

Expand Down
21 changes: 0 additions & 21 deletions openwpm/default_browser_params.json

This file was deleted.

13 changes: 0 additions & 13 deletions openwpm/default_manager_params.json

This file was deleted.

5 changes: 3 additions & 2 deletions openwpm/deploy_browsers/deploy_firefox.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def deploy_firefox(status_queue, browser_params, manager_params, crash_recovery)
display_mode = browser_params.display_mode
display_pid = None
display_port = None
display = None
if display_mode == "headless":
fo.set_headless(True)
fo.add_argument("--width={}".format(DEFAULT_SCREEN_RES[0]))
Expand All @@ -68,7 +69,7 @@ def deploy_firefox(status_queue, browser_params, manager_params, crash_recovery)
try:
display = Display(visible=0, size=DEFAULT_SCREEN_RES)
display.start()
display_pid, display_port = display.pid, display.cmd_param[-1][1:]
display_pid, display_port = display.pid, display.display
except EasyProcessError:
raise RuntimeError(
"Xvfb could not be started. \
Expand Down Expand Up @@ -157,4 +158,4 @@ def deploy_firefox(status_queue, browser_params, manager_params, crash_recovery)

status_queue.put(("STATUS", "Browser Launched", int(pid)))

return driver, driver.capabilities["moz:profile"]
return driver, driver.capabilities["moz:profile"], display
vringar marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion test/manual_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def start_webdriver(
Set to True to load browser_params
browser_params_file : string
Specify the browser_params.json to load.
If None, default_params will be loaded.
If None, default params form openwpm/config.py::BrowserParams will be loaded.

Returns
-------
Expand Down
4 changes: 3 additions & 1 deletion test/test_mp_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,9 @@ def test_child_process_logging(self, tmpdir):
child_process = Process(target=child_proc_logging_exception())
child_process.daemon = True
child_process.start()
openwpm_logger.close()
time.sleep(2)
child_process.join()
print("Child processes joined...")
vringar marked this conversation as resolved.
Show resolved Hide resolved
openwpm_logger.close()
log_content = self.get_logfile_contents(log_file)
assert "I'm logging an exception" in log_content
26 changes: 26 additions & 0 deletions test/test_xvfb_browser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from functools import partial
from typing import List

from openwpm.command_sequence import CommandSequence
from openwpm.task_manager import TaskManager

from .openwpmtest import OpenWPMTest
from .utilities import BASE_TEST_URL


class TestXVFBDisplay(OpenWPMTest):
"""Test the XVFB display option to see if it runs and shuts down properly after a command is given"""

def get_config(self, data_dir=""):
return self.get_test_config(data_dir, display_mode="xvfb")

def test_display_shutdown(self):
manager_params, browser_params = self.get_config()
TEST_SITE = BASE_TEST_URL + "/test_pages/simple_a.html"
manager = TaskManager(manager_params, browser_params)

sequence = CommandSequence(TEST_SITE)
sequence.get()
sequence.save_screenshot()
manager.execute_command_sequence(sequence)
manager.close()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that this test tests anything that isn't tested by test_simple_commands.py

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per request later, added different command. Had not seen that displaymode=xvfb was tested, sorry.

vringar marked this conversation as resolved.
Show resolved Hide resolved