InfoHeap
Tech
Navigation
  • Home
  • Tutorials
    • CSS tutorials & examples
    • CSS properties
    • Javascript cookbook
    • Linux/Unix Command Line
    • Mac
    • PHP
      • PHP functions online
      • PHP regex
    • WordPress
  • Online Tools
    • Text utilities
    • Online Lint Tools
search

Selenium tutorials

  • How to test a site using pytest
  • Python selenium webdriver - quick start
  • Pytest - using selenium with PhantomJS
  • Python selenium - execute javascript code
  • Python selenium - print browser log
  • Selenium Phantomjs - check browser errors using pytest
 
  • Home
  • > Tutorials
  • > CI
  • > Selenium

Python pytest – using selenium with PhantomJS

By admin on Dec 18, 2015

Here is quick tutorial to use python selenium with PhantomJS as driver. We will fetch a page and assert that page title has certain keyword. Here is sample code for it. Note that you must have PhantomJS, python selenium and pytest binding installed for this tutorial. We’ll use Mac for this tutorial but it should work on Linux also.

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

def test_title():
  driver = webdriver.PhantomJS("/usr/local/bin/phantomjs")
  driver.get("https://dev.infoheap.com/")
  title = driver.title
  print "title=%s" % (title)
  assert "InfoHeap" in title, "Tile should have InfoHeap"
  driver.close()

To run above code (-s switch will cause stdout to be printed on screen)

$ py.test -s withphantom.py withphantom.py

If everything is fine, you will get an output like this.

================================================================ test session starts ================================================================
platform darwin -- Python 2.7.10, pytest-2.8.5, py-1.4.31, pluggy-0.3.1
rootdir: /Users/user1/tmp/qa, inifile: 
collected 1 items 

withphantom.py title=dev InfoHeap - Tech tutorials, tips, tools and more
.

============================================================= 1 passed in 9.06 seconds ==============================================================

Suggested posts:

  1. Gmail – how to send email from different address
  2. Python filter list/iterable examples
  3. How to use phantomjs to create site/url snapshot thumbnail
  4. PHP – Regex OR (alternation) examples using pipe
  5. How to install phantomjs on Mac
  6. How to install node (node.js) on Mac
  7. Meta robot noindex, follow for wordpress tags and category pages
  8. Python type – find type of a variable
Share this article: share on facebook share on linkedin tweet this submit to reddit
Posted in Tutorials | Tagged CI, PhantomJS, pytest, Python, Python Selenium, Selenium, Test Automation, Tutorials
  • Browse content
  • Article Topics
  • Article archives
  • Contact Us
Popular Topics: Android Development | AngularJS | Apache | AWS and EC2 | Bash shell scripting | Chrome developer tools | Company results | CSS | CSS cookbook | CSS properties | CSS Pseudo Classes | CSS selectors | CSS3 | CSS3 flexbox | Devops | Git | HTML | HTML5 | Java | Javascript | Javascript cookbook | Javascript DOM | jQuery | Kubernetes | Linux | Linux/Unix Command Line | Mac | Mac Command Line | Mysql | Networking | Node.js | Online Tools | PHP | PHP cookbook | PHP Regex | Python | Python array | Python cookbook | SEO | Site Performance | SSH | Ubuntu Linux | Web Development | Webmaster | Wordpress | Wordpress customization | Wordpress How To | Wordpress Mysql Queries | InfoHeap Money

Copyright © 2025 InfoHeap.

Powered by WordPress