Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

Testing if a Label is Present

$
0
0

Hello! The UI testing has been giving me some problems and I'm not sure why it's being so difficult. Right now I'm trying to just check if a label is present on the page but after trying a few different ways still nothing. Here's the code I'm working with:

<?xml version="1.0" encoding="UTF-8"?> <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="LogATourMobile.SignInPage"> <ContentPage.Content> <StackLayout Padding="20"> <Label Text="My App" FontSize="30" /> <Entry Placeholder="Email" Text="" Keyboard="Email" x:Name="emailField" TextChanged="OnFieldTextChanged" /> <Entry Placeholder="Password" Text="" IsPassword="true" x:Name="passwordField" TextChanged="OnFieldTextChanged" /> <Label Text="Sorry but your email or password could not be found" IsVisible="false" TextColor="Red" x:Name="errorMessage" /> <Button Text="Sign In" IsEnabled="false" x:Name="signInButton" Clicked="OnSignIn" /> <ActivityIndicator Color="White" IsRunning="false" IsVisible="false" x:Name="spinner" /> </StackLayout> </ContentPage.Content> </ContentPage>

[Test]
public void When_Sign_In_Unsuccessful_Show_An_Error()
{
    app.EnterText("Email", "bad@mail.com");
    app.EnterText("Password", "wrong");
    app.Tap("Sign In");

    var result = app.WaitForElement(e => e.Raw("label {text LIKE 'Sorry but'}"));
    Assert.AreEqual(result.Length, 1);
}

Every time I run this test it always says it found nothing but the label is definitely there on the page. Is there any other way to achieve this? I've tried using the Marked/Class query lookup methods but those aren't working either. I even set the StyleId and ClassId and still nothing. Am I just doing everything totally wrong? :)

Thanks for any help!

Update

Here's a screen shot of the app after the sign in fails.


Viewing all articles
Browse latest Browse all 77050

Trending Articles