How to use PHANTOMJS method in Selene

Best Python code snippet using selene_python

dependencies.py

Source:dependencies.py Github

copy

Full Screen

1''' Utilities for checking dependencies2'''3from importlib import import_module4import logging5import shutil6from subprocess import Popen, PIPE7from packaging.version import Version as V8from ..settings import settings9logger = logging.getLogger(__name__)10def import_optional(mod_name):11 ''' Attempt to import an optional dependency.12 Silently returns None if the requested module is not available.13 Args:14 mod_name (str) : name of the optional module to try to import15 Returns:16 imported module or None, if import fails17 '''18 try:19 return import_module(mod_name)20 except ImportError:21 pass22 except Exception:23 msg = "Failed to import optional module `{}`".format(mod_name)24 logger.exception(msg)25def import_required(mod_name, error_msg):26 ''' Attempt to import a required dependency.27 Raises a RuntimeError if the requested module is not available.28 Args:29 mod_name (str) : name of the required module to try to import30 error_msg (str) : error message to raise when the module is missing31 Returns:32 imported module33 Raises:34 RuntimeError35 '''36 try:37 return import_module(mod_name)38 except ImportError:39 raise RuntimeError(error_msg)40def detect_phantomjs(version='2.1'):41 ''' Detect if PhantomJS is avaiable in PATH, at a minimum version.42 Args:43 version (str, optional) :44 Required minimum version for PhantomJS (mostly for testing)45 Returns:46 str, path to PhantomJS47 '''48 if settings.phantomjs_path() is not None:49 phantomjs_path = settings.phantomjs_path()50 else:51 if hasattr(shutil, "which"):52 phantomjs_path = shutil.which("phantomjs") or "phantomjs"53 else:54 # Python 2 relies on Environment variable in PATH - attempt to use as follows55 phantomjs_path = "phantomjs"56 try:57 proc = Popen([phantomjs_path, "--version"], stdout=PIPE, stderr=PIPE)58 proc.wait()59 out = proc.communicate()60 if len(out[1]) > 0:61 raise RuntimeError('Error encountered in PhantomJS detection: %r' % out[1].decode('utf8'))62 required = V(version)63 installed = V(out[0].decode('utf8'))64 if installed < required:65 raise RuntimeError('PhantomJS version to old. Version>=%s required, installed: %s' % (required, installed))66 except OSError:67 raise RuntimeError('PhantomJS is not present in PATH. Try "conda install phantomjs" or \68 "npm install -g phantomjs-prebuilt"')...

Full Screen

Full Screen

install-phantomjs

Source:install-phantomjs Github

copy

Full Screen

1#!/usr/bin/env python2from __future__ import print_function3import os4import sys5import platform6import subprocess7sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..'))8from scripts.lib.zulip_tools import run9if platform.architecture()[0] == '64bit':10 phantomjs_arch = 'x86_64'11elif platform.architecture()[0] == '32bit':12 phantomjs_arch = 'i686'13PHANTOMJS_PATH = "/srv/phantomjs"14if "--travis" in sys.argv:15 PHANTOMJS_PATH = os.path.join(os.environ['HOME'], "phantomjs")16PHANTOMJS_BASENAME = "phantomjs-1.9.8-linux-%s" % (phantomjs_arch,)17PHANTOMJS_TARBALL_BASENAME = PHANTOMJS_BASENAME + ".tar.bz2"18PHANTOMJS_TARBALL = os.path.join(PHANTOMJS_PATH, PHANTOMJS_TARBALL_BASENAME)19PHANTOMJS_URL = "https://github.com/zulip/zulip-dist-phantomjs/blob/master/%s?raw=true" % (PHANTOMJS_TARBALL_BASENAME,)20if not os.path.exists(PHANTOMJS_TARBALL):21 run(["sudo", "mkdir", "-p", PHANTOMJS_PATH])22 run(["sudo", "curl", '-J', '-L', PHANTOMJS_URL, "-o", PHANTOMJS_TARBALL])23 run(["sudo", "tar", "-xj", "--directory", PHANTOMJS_PATH,24 "--file", PHANTOMJS_TARBALL])25 run(["sudo", "ln", "-sf", os.path.join(PHANTOMJS_PATH, PHANTOMJS_BASENAME,26 "bin", "phantomjs"),27 "/usr/local/bin/phantomjs"])28else:...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Selene automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful