class SeleniumDrivenUserActionsExpectations(unittest.TestCase):
    def setUp(self):
        self.testFileName = "file://" + os.path.dirname(__file__) + "/testWebsite/seleniumTestPage.html"
        self.host = "localhost"
        self.port = 4444
        self.browserStartCommand = "*firefox"
        self.url = "http://*****:*****@id="Main"]'
        self.action = SeleniumDrivenUserActions(self.seleniumExecutionContext)
        self.action.goesTo(self.testFileName)
        self.expectation = SeleniumDrivenUserExpectations(self.seleniumExecutionContext)
        self.originaljquerymethod = JavascriptHelper.GetjQueryWaitForAjaxCondition
        self.originalPrototypeMethod = JavascriptHelper.GetPrototypeWaitForAjaxCondition
        self.originalwaitforcondition = selenium.wait_for_condition

    def tearDown(self):
        JavascriptHelper.GetjQueryWaitForAjaxCondition = self.originaljquerymethod
        JavascriptHelper.GetPrototypeWaitForAjaxCondition = self.originalPrototypeMethod
        selenium.wait_for_condition = self.originalwaitforcondition

    def __del__(self):
        self.seleniumExecutionContext.destroy()

    def SeleniumDrivenUserActionsGoesToShouldBringTheUserToTheRightPage(self):
        self.assertEquals(self.testFileName, self.seleniumExecutionContext.seleniumInstance.get_location())

    def SeleniumDrivenUserActionsShouldReturnItselfWhenCalledWithAndThenAndNoSpecificChainingElementHasBeenSpecified(
        self
    ):
        self.assertEquals(self.action.andThen(), self.action)

    def SeleniumDrivenUserActionsShouldReturnChainingElementWhenCalledWithAndThenAndASpecificChainingElementHasBeenSpecified(
        self
    ):
        self.action.chainingElement = "chainingElement"
        self.assertEquals(self.action.andThen(), "chainingElement")

    def SeleniumDrivenUserActionsShouldLeaveCheckboxClickedwhenAskedToclickOnIt(self):
        self.assertFalse(self.seleniumExecutionContext.seleniumInstance.is_checked(Locators.CHECKBOX))
        self.action.clicks(Locators.CHECKBOX)
        self.assertTrue(self.seleniumExecutionContext.seleniumInstance.is_checked(Locators.CHECKBOX))

    def SeleniumDrivenUserActionsShouldUpdateLastVisitedLocationWhenCalledWithFillsOut(self):
        self.seleniumExecutionContext.setLastVisitedLocation = Mock()
        self.action.fillsOut(self.locator)
        self.assertTrue(self.seleniumExecutionContext.setLastVisitedLocation.called)

    def SeleniumDrivenUserActionsShouldThrowExceptionWhenWithThisIsCalledAndNoPreviousLocationWasSelected(self):

        try:
            self.action.withThis("Text")
            self.fail("withThis should fail when no location was previously selected")
        except (LocatorNotFoundException,), e:
            pass