user170732 user170732 - 9 months ago 65
Python Question

Asserting two statements are true at the same time in Selenium Unittest

I have been trying to assert that two textbox elements contain two specific values for a successful test.

Textbox 1: 100
Textbox 2: 0

I have tried the following code:

def test_example(self):


tb1 = self.find_by_id('textbox1')
tb2 = self.find_by_id('textbox2')

self.assertEquals((tb1.get_attribute('value'), 100) and (tb2.get_attribute('value'), 0))

This gives the following error:

Traceback (most recent call last):
File "", line 48, in test_textbox
self.assertEquals((tb1.get_attribute('value'), 100) and (tb2.get_attribute('value'), 0))
TypeError: assertEqual() takes at least 3 arguments (2 given)

Is there a way to do this?

Answer Source

The following may solve your issue:

Concatenating the 2 strings:

self.assertEqual(tb1.get_attribute('value') + tb2.get_attribute('value'), '1000')


self.assertEqual(''.join([tb1.get_attribute('value'), tb2.get_attribute('value')]), '1000')

Using tuples:

self.assertEqual((tb1.get_attribute('value'), tb2.get_attribute('value')), (100, 0))