Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

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

OK

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
2  
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
1  
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
add comment

1 Answer

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_python_script.py > ./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
add comment

Your Answer

 
discard

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.