All Questions
361
questions
10
votes
5
answers
15k
views
Python Selenium wait for several elements to load
I have a list, which is dynamically loaded by AJAX.
At first, while loading, it's code is like this:
<ul><li class="last"><a class="loading" href="#"><ins> </ins&...
253
votes
9
answers
371k
views
How can I time a code segment for testing performance with Pythons timeit?
I've a python script which works just as it should, but I need to write the execution time. I've googled that I should use timeit but I can't seem to get it to work.
My Python script looks like this:
...
150
votes
10
answers
199k
views
How to pass arguments in pytest by command line
I have a code and I need to pass the arguments like name from terminal.
Here is my code and how to pass the arguments. I am getting a "File not found" kind error that I don't understand.
I have tried ...
851
votes
14
answers
723k
views
How do I properly assert that an exception gets raised in pytest?
Code:
# coding=utf-8
import pytest
def whatever():
return 9/0
def test_whatever():
try:
whatever()
except ZeroDivisionError as exc:
pytest.fail(exc, pytrace=True)
Output:...
82
votes
20
answers
147k
views
How to upload file ( picture ) with selenium, python
How to upload a picture on a web application with the selenium testing tool? I am using python.
I tried many things, but nothing worked.
266
votes
22
answers
209k
views
Trying to mock datetime.date.today(), but not working
Can anyone tell me why this isn't working?
>>> import mock
>>> @mock.patch('datetime.date.today')
... def today(cls):
... return date(2010, 1, 1)
...
>>> from datetime ...
78
votes
5
answers
135k
views
Check if any alert exists using selenium with python
I'm trying to write a test with selenium in python language for a web page that manages users. In this page someone can add role for users and if a role exists while adding it, an alert raises. I don'...
15
votes
4
answers
5k
views
Select -> option abstraction
In Python, Java and several other selenium bindings, there is a very convenient abstraction over select->option HTML constructions, a Select class.
For example, imagine there is the following ...
12
votes
3
answers
16k
views
Expected conditions in protractor
While writing selenium tests in Python, I got used to using Explicit Waits a lot for waiting for a page to load, or for waiting for an element to become visible, or clickable etc:
from selenium....
486
votes
18
answers
434k
views
How do I run all Python unit tests in a directory?
I have a directory that contains my Python unit tests. Each unit test module is of the form test_*.py. I am attempting to make a file called all_test.py that will, you guessed it, run all files in the ...
156
votes
8
answers
281k
views
How to send mail with To, CC and BCC?
I need to populate a few hundred email boxes with various messages for testing purposes and I was going to use smtplib for that. I need to send messages not only To specific mailboxes, but CC and BCC ...
90
votes
10
answers
67k
views
How to test a function with input call?
I have a console program written in Python. It asks the user questions using the command:
some_input = input('Answer the question:', ...)
How would I test a function containing a call to input using ...
559
votes
7
answers
266k
views
Writing unit tests in Python: How do I start? [closed]
I completed my first proper project in Python and now my task is to write tests for it.
Since this is the first time I did a project, this is the first time I would be writing tests for it.
The ...
102
votes
12
answers
54k
views
How to test or mock "if __name__ == '__main__'" contents
Say I have a module with the following:
def main():
pass
if __name__ == "__main__":
main()
I want to write a unit test for the bottom half (I'd like to achieve 100% coverage). I discovered ...
196
votes
16
answers
87k
views
Python unit test with base and sub class
I currently have a few unit tests which share a common set of tests. Here's an example:
import unittest
class BaseTest(unittest.TestCase):
def testCommon(self):
print 'Calling BaseTest:...