locked
UI tests navigation between pages RRS feed

  • Question

  • User377666 posted

    Hi. How can I write a UI test that will wait for my app to navigate to another page? I try to use "_app.WaitForElement" to wait for an element that has in destiny, but I get a TimeoutException, eg:

    [Test]
    public void QuandoInformarLoginSenhaCorretos_ExibirMapa()
    {
        _app.WaitForElement(e => e.Marked("btnLogar"));
        _app.Tap(t => t.Marked("txtUsuario"));
        _app.EnterText("fake");
        _app.Tap(t => t.Marked("txtSenha"));
        _app.EnterText("fake");
        _app.Tap(t => t.Marked("btnLogar"));// this line is to do a login in app and call new page
        _app.WaitForElement(e => e.Marked("frmMapa")); // this line search a element e destiny page, but I get a TimeoutException
        _app.Repl();
    }
    

    thank you.

    Friday, January 18, 2019 3:26 PM

Answers

  • User377666 posted

    I solved my question, I has no problems with UI tests, my problem was a bug who my unit tests don't get, I solved my problem when I refactor my code, thank you :)

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Tuesday, February 26, 2019 11:52 AM

All replies

  • User89714 posted

    @JoséJunior

    When you run the test, does the expected page actually appear, but after the test has timed out? If so, specify a timeout on the WaitForElement call that is long enough to handle how long it takes for the page to appear. If that still doesn't work, check that "frmMapa" is the correct thing to be searching for.

    Friday, January 18, 2019 5:12 PM
  • User377666 posted

    @JohnHardman I tried to put timeout in 3 minutes and not worked, I got same error.

    _app.WaitForElement(e => e.Marked("frmMapa"), "a aplicação não navegou para a pagina de mapas", new TimeSpan(0,3,0));
    

    For UI tests I using a fake backend: https://github.com/micromata/http-fake-backend

    and use localtunnel to provide access for physical smartphone: https://github.com/localtunnel/localtunnel

    I tried in UI tests and out of tests, In UI tests I get a exception, but out of tests works fine

    Tuesday, January 22, 2019 2:18 PM
  • User89714 posted

    @"JoséJunior"

    What does app.Repl() show at that point?

    Tuesday, January 22, 2019 2:26 PM
  • User377666 posted

    after define visible false in my ActivityIndicator in my viewmodel, this happen in flinally block:

    public DelegateCommand LogarCommand
        {
            get => new DelegateCommand(async () =>    
            {
                if (ExibirBotaoQRCode)
                {
                    await _pageDialogService.DisplayAlertAsync(AppResources.Login_erroLogin_titulo,
                            AppResources.Login_ServidorNaoInformado,
                            AppResources.MensagemGenerica_Dialog_OpcaoOk);
                    return;
                }
                try
                {
                    ValidarDados();
                    if ((ExibirErroSenha) || (ExibirErroUsuario))
                    {
                        return;
                    }
                    ExibirLoadDialog = true;
                    _loginService.IpServidor = _parametroDAO.BuscarIp();
                    UsuarioLogadoDTO usuarioLogado = await _loginService.Login(DadoLoginDTO);
                    if (usuarioLogado.SistemaBloqueado)
                    {
                        await _pageDialogService.DisplayAlertAsync(AppResources.Login_erroLogin_titulo,
                            AppResources.Login_erroLogin_sistemaBloqueado,
                            AppResources.MensagemGenerica_Dialog_OpcaoOk);
                    }
                    else if (usuarioLogado.Bloqueado)
                    {
                        await _pageDialogService.DisplayAlertAsync(AppResources.Login_erroLogin_titulo,
                            AppResources.Login_erroLogin_usuarioBloqueado,
                            AppResources.MensagemGenerica_Dialog_OpcaoOk);
                    }
                    else
                    {
                        SessaoUsuario.CriarSessao(usuarioLogado);
                        string paginaMapa = string.Format(
                            "/" + ViewsNamesConstants.PREFIXO_VIEW_MASTER_DETAIL,
                            ViewsNamesConstants.MASTER_DETAIL,
                            ViewsNamesConstants.MAPA);
                        await _navigationService.NavigateAsync(new Uri(paginaMapa));// navigate to next page
                    }
                }
                catch (HttpRequestException)
                {
                    await _pageDialogService.DisplayAlertAsync(AppResources.Login_erroLogin_titulo,
                            AppResources.MensagemGenerica_ErroConexao,
                            AppResources.MensagemGenerica_Dialog_OpcaoOk);
                }
                catch (SessaoException)
                {
                    await _pageDialogService.DisplayAlertAsync(AppResources.Login_erroLogin_titulo,
                            AppResources.Login_erroLogin_usuarioSenhaInvalido,
                            AppResources.MensagemGenerica_Dialog_OpcaoOk);
                }
                catch (LoginServiceException ex)
                {
                    await _pageDialogService.DisplayAlertAsync(AppResources.Login_erroLogin_titulo,        
                        ex.Message,        
                        AppResources.MensagemGenerica_Dialog_OpcaoOk);
                }
                finally
                {
                    ExibirLoadDialog = false;// hidden ActivityIndicator
                }
            });
    
        }
    
    Tuesday, January 22, 2019 3:50 PM
  • User89714 posted

    @"JoséJunior"

    For future reference - It's much easier for me (and others) if you copy the text from App.Repl rather than inserting a png file. Text is easier to search.

    If that Repl output is from a few seconds after pressing btnLogar, the problem isn't with the WaitForElement. It would appear that the page is not changing as a result of the pressing btnLogar. Is that the case? If so, then it's a case of debugging the application-under-test.

    Tuesday, January 22, 2019 4:03 PM
  • User377666 posted

    I tried to run again my test, I try to click in button via terminal and try click via "_app.Tap(t => t.Marked("btnLogar"))", nothing happened, but if I run in Visual Studio or install in device and try, the application call next page withou problem.

    Tuesday, January 22, 2019 4:29 PM
  • User377666 posted

    I solved my question, I has no problems with UI tests, my problem was a bug who my unit tests don't get, I solved my problem when I refactor my code, thank you :)

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Tuesday, February 26, 2019 11:52 AM
  • User89714 posted

    @"JoséJunior" said: I solved my question, I has no problems with UI tests, my problem was a bug who my unit tests don't get, I solved my problem when I refactor my code, thank you :)

    Was it the app under test that you had to debug/refactor, as per post at https://forums.xamarin.com/discussion/comment/361909/#Comment_361909 ?

    Tuesday, February 26, 2019 12:00 PM
  • User377666 posted

    The bug was very specific, because before to input login and password, I need to read a QR code to get address the api I want consume ( the app is for company's clients use in own internal system then the address change for each) if I read QR code and try login not work, but if I minimize the app, open again and try login works.

    Tuesday, February 26, 2019 12:20 PM