#An automated selenium test designed to test the interface of a web calculator
# Available @ http://teaching.csse.uwa.edu.au/units/CITS5501/Assinments/calculator.html
# By Aden Huen

#Tests web interface by input space partitioning

import unittest
from selenium import webdriver
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import TimeoutException

class test_webcalc(unittest.TestCase): 

    def test_input(self):
        #Tests the amount of digits allowed in calculator register
        input_size = 0
        alert_popped = False
        
        while (alert_popped == False):
            try:
                expected_conditions.alert_is_present()
                alert = driver.switch_to_alert()
                alert.accept()
                alert_popped = True
                
            except Exception:
                btn1.click()
                input_size += 1
                
        self.assertEqual(input_size, 17)
        btndel.click()
        
    def test_buttons_c(self):
        btndel.click()
        #Test all buttons besides del and =
        btn1.click()
        btndot.click()
        btn2.click()
        btnplus.click()
        btn3.click()
        btnminus.click()
        btn4.click()
        btntimes.click()
        btn5.click()
        btndivide.click()
        btn6.click()
        btnmod.click()
        btn7.click()
        btn8.click()
        btn9.click()
        btn0.click()
        self.assertEqual(result.text, '1.2+3-4*5/6%7890')
        #Test Del
        btndel.click()
        self.assertEqual(result.text, '')
        #Test =
        btndot.click()
        btnequal.click()
        self.assertEqual(result.text, '0')
        btndel.click()
        
    #Test putting zeros after each characteristic as zero is a special case number
    def test_zero_after_digit_c(self):
        btndel.click()
        btn4.click()
        btn0.click()
        self.assertEqual(result.text, '40')
        btndel.click()
    def test_zero_at_start_c(self):
        btndel.click()
        btn0.click()
        btndot.click()
        btn1.click()
        self.assertEqual(result.text, '0.1')
        btndel.click()
    def test_zero_after_decimal_c(self):
        btndel.click()
        btn1.click()