Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm writing a suite of web tests in Python using Selenium. Ultimately, I want to generate a file with the results, which will then be sent out in an email. I'm using a main Python script to kick off all of the test scrips, and then the email script afterwards. When a test successfully runs (through the shell), I get a message in the terminal like this:

Ran 1 test in 15.566s


This ^ ^ ^ is what I want written to a file, but after trying multiple methods I can't get it to write the results. I can't figure out where Selenium does this within the Python script.

Anyone have experience with this/have an idea how to do it?

Thank you!!

share|improve this question
What have you tried that hasn't worked? The first thing that comes to my mind is pipe your output to a file. – Suchit Parikh Dec 3 '13 at 23:10
Selenium doesn't understand the concept of a "test" -- it's just an API for controlling browsers. Your Python script is relying on some other framework to run the tests. Are you running python with the -m switch? – user246 Dec 3 '13 at 23:39

It seems you may not be accustomed to piping. No worries, it was new to everyone at some point. By using the shell to call your tests, you're mostly there already.

A key thing here is that anything that get's written to your terminal can be "piped" into a file that you name. If you are seeing those results in your terminal, then you can route them to a file.

For example

echo "hello world"

will cause the terminal to print "hello world"

Same example, now piped to a file

echo "hello world" > ./helloworld.txt

will cause "hello world" to be placed inside a file named helloworld.txt (in your working directory, which is what the "./" represents)

Now to get your python script to do this, just do something like:

python > ./my_test_results.txt

The following examples should work in Windows CMD and Linux Bash shells (not sure which shell you are using). Also, if you don't know your working directory type "cd" in CMD or "pwd" in Bash to have it printed in the terminal. Then go to that folder and find the file.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.