Skip to content
This repository has been archived by the owner on Jan 13, 2022. It is now read-only.

Quit driver session after each test #57

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
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
16 changes: 13 additions & 3 deletions huxley/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import contextlib
from contextlib import contextmanager
import os
import json
import sys
Expand All @@ -39,6 +39,14 @@
}


@contextmanager
def quitting(driver):
try:
yield driver
finally:
driver.quit()


@plac.annotations(
url=plac.Annotation('URL to hit'),
filename=plac.Annotation('Test file location'),
Expand All @@ -56,6 +64,8 @@
autorerecord=plac.Annotation('Playback test and automatically rerecord if it fails', 'flag', 'a'),
save_diff=plac.Annotation('Save information about failures as last.png and diff.png', 'flag', 'e')
)


def main(
testname,
url,
Expand Down Expand Up @@ -97,13 +107,13 @@ def main(
diffcolor = tuple(int(x) for x in diffcolor.split(','))
jsonfile = os.path.join(filename, 'record.json')

with contextlib.closing(d):
with quitting(d):
if record:
if local:
local_d = webdriver.Remote(local, CAPABILITIES[browser])
else:
local_d = d
with contextlib.closing(local_d):
with quitting(local_d):
with open(jsonfile, 'w') as f:
f.write(
jsonpickle.encode(
Expand Down