user170732 user170732 - 16 days ago 6
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):

self.set_textbox1('100')
self.set_textbox2('0')

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 "test_textboxes.py", 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

The following may solve your issue:

Concatenating the 2 strings:

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

Or:

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))