Автоматизация панели инструментов Xamarin

Идея состоит в том, чтобы рассматривать матрицу как серию слоев, верхних правых слоев и нижних левых слоев. Чтобы напечатать матрицу по спирали, мы можем очистить слои от этой матрицы, напечатать очищенную часть и рекурсивно вызвать печать слева над частью. Рекурсия завершается, когда у нас больше нет слоев для печати. ​​

Входная матрица:

1 2 3 4 
5 6 7 8
9 0 1 2   
3 4 5 6 
7 8 9 1

После отслаивания верхнего правого слоя:

 1 2 3 4 
       8
5 6 7  2
9 0 1  6   
3 4 5  1 
7 8 9

После отслаивания нижнего левого слоя из подматрицы:

   6 7
5  0 1   
9  4 5
3 
7 8 9 

После отслаивания верхнего правого слоя из подматрицы:

    6 7
      1   
   0  5
   4

После отслаивания нижнего левого слоя из подматрицы:

  0
  4

Рекурсия завершается.


Функции C:

// function to print the top-right peel of the matrix and 
// recursively call the print bottom-left on the submatrix.
void printTopRight(int a[][COL], int x1, int y1, int x2, int y2) {
    int i = 0, j = 0;

    // print values in the row.
    for(i = x1; i<=x2; i++) {
        printf("%d ", a[y1][i]);
    }

    // print values in the column.
    for(j = y1 + 1; j <= y2; j++)         {
        printf("%d ", a[j][x2]);
    }

    // see if more layers need to be printed.
    if(x2-x1 > 0) {
        // if yes recursively call the function to 
        // print the bottom left of the sub matrix.
        printBottomLeft(a, x1, y1 + 1, x2-1, y2);
    }
}

// function to print the bottom-left peel of the matrix and 
// recursively call the print top-right on the submatrix.
void printBottomLeft(int a[][COL], int x1, int y1, int x2, int y2) {
    int i = 0, j = 0;

    // print the values in the row in reverse order.
    for(i = x2; i>=x1; i--) {
        printf("%d ", a[y2][i]);
    }

    // print the values in the col in reverse order.
    for(j = y2 - 1; j >= y1; j--) {
        printf("%d ", a[j][x1]);
    }

    // see if more layers need to be printed.
    if(x2-x1 > 0) {
        // if yes recursively call the function to 
        // print the top right of the sub matrix.
        printTopRight(a, x1+1, y1, x2, y2-1);
    }
}

void printSpiral(int arr[][COL]) {
    printTopRight(arr,0,0,COL-1,ROW-1);
    printf("\n");
}

Идеальная ссылка

2
задан Brandon Minnick 22 March 2019 в 17:28
поделиться

1 ответ

Я столкнулся с той же проблемой - по какой-то причине Android не может обнаружить ToolbarItem.AutomationId.

Обходной путь должен назначить ToolbarItem.Text то же значение, что и ToolbarItem.AutomationId.

Xamarin.Forms.ContentPage

<ContentPage.ToolbarItems>
    <ToolbarItem Icon="Settings" Text="SettingsToolbarItem" AutomationId="SettingsToolbarItem" Order="Primary" Priority="1" Command="{Binding ShowSettingsCommand}" />
</ContentPage.ToolbarItems>

Xamarin.UITest

using Query = System.Func<Xamarin.UITest.Queries.AppQuery, Xamarin.UITest.Queries.AppQuery>;
// ....
protected readonly Query systemMenuButton = x => x.Marked("SettingsToolbarItem");
//....

public void TapSystemMenuButton()
{
    app.Tap(systemMenuButton);

    app.Screenshot("Tapped System Menu Button");
}

Вот пример приложения, в котором я использую аналогичную логику для нажатия на ToolbarItem в UITest: https://github.com/brminnick/InvestmentDataSampleApp/

Редактировать

В комментариях вы упомянули, что у вас нет доступа к исходному коду приложения Xamarin.Forms .

Если вы не можете изменить исходный код Xamarin.Forms, вам придется использовать x => x.Class("ActionMenuItemView").Index(1).

Я не рекомендую идти по этому маршруту, потому что параметр int в Index может варьироваться в зависимости от устройства; не гарантируется, что он всегда будет 1.

public void TapSystemMenuButton()
{
    if (app is iOSApp)
        app.Tap(systemMenuButton);
    else
        app.Tap(x => x.Class("ActionMenuItemView").Index(1));

    app.Screenshot("Tapped System Menu Button");
}
0
ответ дан Brandon Minnick 22 March 2019 в 17:28
поделиться
Другие вопросы по тегам:

Похожие вопросы: