lefthandedgoat / canopy

f# web automation and testing library, built on top of Selenium (friendly to c# also)
http://lefthandedgoat.github.io/canopy/
MIT License
505 stars 117 forks source link

'enabled' assertion and text insertion issues #523

Closed teknikal-wizard closed 2 years ago

teknikal-wizard commented 2 years ago

Hi there,

I'm just updating some of our SAFE stack course modules, and I am finding some issues with canopy.

I have a button that is enabled when a text box has content, and disabled when it is empty.

I tried to write a simple test for this and it wasn't working.

I found that

  1. The enabled / disabled assertions were failing as the button is reported as notDisplayed when disabled, causing a timeout.
  2. Emptying the text box programmatically does not trigger the onChanged event so the button remains active, however adding text does trigger it)

I have attached a sample showing these cases.

Use dotnet run in the root for the main app app.zip

teknikal-wizard commented 2 years ago

@isaacabraham

lefthandedgoat commented 2 years ago

I get this:

../app/Build.fsproj(10,3): error MSB4019: The imported project "../app/.paket/Paket.Restore.targets" was not found. 
Confirm that the expression in the Import declaration ".paket/Paket.Restore.targets" is correct, 
and that the file exists on disk.

If you can just give me a snippet of the line that is failing and then a snippet of the html for the control you are trying to test that would probably work.

Displayed/Not displayed checks the display tag and the opacity. Your code may be visually disabling the control in a different way and you may have to write your own custom validator for that.

https://github.com/lefthandedgoat/canopy/blob/master/src/canopy/canopy.parallell.functions.fs#L604-L607

isaacabraham commented 2 years ago

@Ryan-Palmer-CIT you'd be better off making a repository and committing to there rather than a zip TBH.

teknikal-wizard commented 2 years ago

../app/Build.fsproj(10,3): error MSB4019: The imported project "../app/.paket/Paket.Restore.targets" was not found.

You might need to run dotnet tool restore first.

The control is just disabled in a normal way, you can see in the sample. I might have time to come back to this later but all the info is there.

lefthandedgoat commented 2 years ago

@Ryan-Palmer-CIT The issue is that in your html your button isnt a button its an <a> tag. I edited it to be an <input> and it worked.

If you want to keep it as an <a> you need to create your own definition for disabled (and probably enabled)

I used this and it worked on your code using <a>

    let isDisabled (element: OpenQA.Selenium.IWebElement) =
        if element.TagName = "input" then
            element.Enabled = false
        else
            let isDisabled' = element.GetAttribute("disabled")
            if isDisabled' = null then false else true

    let disabled item =
        try
            canopy.wait.wait canopy.configuration.compareTimeout (fun _ ->
                match box item with
                | :? OpenQA.Selenium.IWebElement as element -> isDisabled element            
                | :? string as cssSelector -> element cssSelector |> isDisabled
                | _ -> raise (canopy.types.CanopyNotStringOrElementException(sprintf "Can't check disabled on %O because it is not a string or webelement" item)))
        with
            | :? canopy.types.CanopyElementNotFoundException as ex -> raise (canopy.types.CanopyDisabledFailedException(sprintf "%s%sdisabled check for %O failed." ex.Message System.Environment.NewLine item))
            | :? OpenQA.Selenium.WebDriverTimeoutException -> raise (canopy.types.CanopyDisabledFailedException(sprintf "disabled check for %O failed." item))

Edit:

I updated the UI code to be a button instead of an <a> and that also fixed the test and is probably the 'most correct' solution

                        Bulma.button.button [
                            color.isPrimary
                            prop.id "addButton"
teknikal-wizard commented 2 years ago

Amazing! Thank you so much :)