Studio
2023.10
バナーの背景画像
Studio ガイド
最終更新日 2024年4月26日

インポートしたライブラリ プロジェクトをコード化されたオートメーションで使用する

このチュートリアルでは、インポートしたライブラリ プロジェクトから取得したオブジェクトをコード化されたオートメーション内で使用する方法について説明します。この例では、インポートしたライブラリ プロジェクトから取得したオブジェクト リポジトリの要素とワークフローを使用する方法を示します。指定のシナリオでは、ACME Web サイトを自動化して、学生のスコア カードに必要事項を入力し、それをデータベースに追加します。

前提条件

UI Automation アクティビティ バージョン 23.10.3 以降をインストールします。

1. ライブラリ プロジェクトを作成する

ACME アプリの自動化 (厳密には学生のスコア カードへの入力) に不可欠な UI 要素を格納するライブラリ プロジェクトを作成します。さらに、ライブラリ プロジェクト内にローコード (.xaml) またはコード化されたワークフロー (.cs) を作成します。これは、後で別のコード化されたオートメーション内で使用するものです。
  1. AcmeLibrary という名前のライブラリ プロジェクトを作成します。
  2. [オブジェクト リポジトリ][記述子] セクション内で使用する、すべての UI 要素をキャプチャします。
  3. [ファイル] グループから、新しいコード化されたワークフローを作成します。

    この手順は、別のプロジェクトにライブラリをインポートするときに、コード化されたオートメーション内のオブジェクト リポジトリにアクセスできるようにするために重要です。

  4. Main ローコード ワークフローの名前を Send message box に変更し、[メッセージ ボックス] アクティビティを、「You've added a new score card for a student in Acme. (ACME の学生用に新しいスコア カードを追加しました。)」というテキストと共に追加します。
    注: チュートリアルで説明されている手順に従って、[メッセージ ボックス] アクティビティをコード化されたワークフローとして再作成することもできます。
  5. ライブラリ プロジェクトを保存し、フィードにパブリッシュします。

    このパブリッシュされたライブラリは、コード化されたオートメーション内の別のプロジェクトにインストールして使用します。

2. コード化されたオートメーションを作成する

ライブラリ プロジェクトの作成後、それを別のプロジェクトにインストールして、その再利用可能なアセット (オブジェクト リポジトリの要素やワークフローなど) を、それらがローコード (.xaml) かコード化 (.cs) かにかかわらず活用します。
ヒント: UI Automation API を使用する場合、IScreenDescriptor または IElementDescriptor を含むオーバーロードはオブジェクト リポジトリの要素を操作するためのものであるのに対し、TargetAnchorableModel を含むオーバーロードは UI Explorer で取得されたネイティブ セレクターで使用するためのものであることに注意してください。UI Automation API でセレクターを活用する方法について詳しくは、UI Automation API をご覧ください。
  1. [ファイル] グループから、新しいコード化されたワークフローを作成します。
  2. [パッケージを管理] に移動し、以前に作成したライブラリ プロジェクトをインストールします。
  3. [ファイル] グループから、新しいワークフローを作成します。
    1. ワークフローに notifyStudentScoreCardAdded という名前を付けます。
    2. [アクティビティ] パネル、[インストール済み] セクションの順に移動します。
    3. インポートしたライブラリ プロジェクトの名前 (この例では AcmeLibrary) を検索します。
    4. Send message box アクティビティを notifyStudentScoreCardAdded 内にドラッグ アンド ドロップします。
      これで、notifyStudentScoreCardAdded の動作は、インポートしたライブラリ プロジェクトから取得した Send message box ワークフローと同じになります。
  4. 読みやすくするために、インポートしたオブジェクト リポジトリ アプリケーションを変数として定義し、ワークフローの先頭に using ステートメントを適用できます。以下に例を示します。using app = <ProjectName>.ObjectRepository.Descriptors.<AppName>
    この方法では、app.<ScreenName>.<UiElementName> 形式で記述子を簡単に呼び出すことができます。
    この例では、ACME オブジェクト リポジトリを次のように定義します。
    namespace UsingImportedLibraryProjects
    {
        using AcmeApp = AcmeLibrary.ObjectRepository.Descriptors.Acme;namespace UsingImportedLibraryProjects
    {
        using AcmeApp = AcmeLibrary.ObjectRepository.Descriptors.Acme;
  5. これで、ACME 内で指定のシナリオを自動化できるようになりました。最初に、OpenAPI を使用して ACME のログイン画面を開きます。
    [Workflow]
            public void Execute()
            {
              // 1.Open the Acme app on the Login screen
              var AcmeLoginScreen = uiAutomation.Open(AcmeApp.LoginScreen); [Workflow]
            public void Execute()
            {
              // 1.Open the Acme app on the Login screen
              var AcmeLoginScreen = uiAutomation.Open(AcmeApp.LoginScreen);
  6. TypeInto API を使用して、ACME にログインするために必要な資格情報を入力します。
    // 2.Type in the necessary credentials
             AcmeLoginScreen.TypeInto(AcmeApp.LoginScreen.Email, "john.doe2023@uipath.com");
             AcmeLoginScreen.TypeInto(AcmeApp.LoginScreen.Password, "12345678");  // 2.Type in the necessary credentials
             AcmeLoginScreen.TypeInto(AcmeApp.LoginScreen.Email, "john.doe2023@uipath.com");
             AcmeLoginScreen.TypeInto(AcmeApp.LoginScreen.Password, "12345678");
  7. Click API とネイティブ セレクターを使用して、[Login] ボタンをクリックします。
    // 3.Use a native selector to click the Login button
    AcmeLoginScreen.Click(Target.FromSelector("<webctrl tag='BUTTON' type='submit'/>"));// 3.Use a native selector to click the Login button
    AcmeLoginScreen.Click(Target.FromSelector("<webctrl tag='BUTTON' type='submit'/>"));
  8. ログイン プロセスが実行されると、ACME Web アプリケーションの [Dashboard] 画面が表示されます。そのため、Attach API を使用して新しい画面にフォーカスします。
    // 4. Focus on the Dashboard screen
    var DashboardScreen = uiAutomation.Attach(AcmeApp.Dashboard);// 4. Focus on the Dashboard screen
    var DashboardScreen = uiAutomation.Attach(AcmeApp.Dashboard);
  9. Click API を使用して、Web サイトで [Students] エントリを選択します。
    // 5. Click the Students entry
    DashboardScreen.Click(AcmeApp.Dashboard.Students);// 5. Click the Students entry
    DashboardScreen.Click(AcmeApp.Dashboard.Students);
  10. Click API を使用して、[Score card] を選択し、[Students - Score Card] フォームを開きます。
    // 6. Click Score card, to start filling in a student score card
    DashboardScreen.Click(AcmeApp.Dashboard.Students.ScoreCard);// 6. Click Score card, to start filling in a student score card
    DashboardScreen.Click(AcmeApp.Dashboard.Students.ScoreCard);
  11. Attach API を使用して、[Students - Score Card] 画面にフォーカスします。
    // 7. Focus on the Score Card screen where you fill in the necessary information
    var ScoreCardScreen = uiAutomation.Attach(AcmeApp.StudentsScoreCard);// 7. Focus on the Score Card screen where you fill in the necessary information
    var ScoreCardScreen = uiAutomation.Attach(AcmeApp.StudentsScoreCard);
  12. TypeInto API を使用して、[Students - Score Card] フォームのフィールドの半分と、オブジェクト リポジトリから取得した要素に入力します。
    ScoreCardScreen.TypeInto(AcmeApp.StudentsScoreCard.StudentEmail, "john.doe@uipath.com");
    ScoreCardScreen.TypeInto(AcmeApp.StudentsScoreCard.FirstName, "John");
    ScoreCardScreen.TypeInto(AcmeApp.StudentsScoreCard.LastName, "Doe");
    ScoreCardScreen.TypeInto(AcmeApp.StudentsScoreCard.ParentEmail, "johnny.doe@uipath.com");
    ScoreCardScreen.TypeInto(AcmeApp.StudentsScoreCard.Tuition, "Private");ScoreCardScreen.TypeInto(AcmeApp.StudentsScoreCard.StudentEmail, "john.doe@uipath.com");
    ScoreCardScreen.TypeInto(AcmeApp.StudentsScoreCard.FirstName, "John");
    ScoreCardScreen.TypeInto(AcmeApp.StudentsScoreCard.LastName, "Doe");
    ScoreCardScreen.TypeInto(AcmeApp.StudentsScoreCard.ParentEmail, "johnny.doe@uipath.com");
    ScoreCardScreen.TypeInto(AcmeApp.StudentsScoreCard.Tuition, "Private");
  13. TypeInto API と、UI Explorer で見つけたネイティブ セレクターを組み合わせて使用し、フォームの残りのフィールドに入力します。
    ScoreCardScreen.TypeInto(Target.FromSelector("<webctrl id='mathematics' tag='INPUT' />"), "A");
    ScoreCardScreen.TypeInto(Target.FromSelector("<webctrl id='physics' tag='INPUT' />"), "B");
    ScoreCardScreen.TypeInto(Target.FromSelector("<webctrl id='biology' tag='INPUT' />"), "C");
    ScoreCardScreen.TypeInto(Target.FromSelector("<webctrl id='chemistry' tag='INPUT' />"), "A");
    ScoreCardScreen.TypeInto(Target.FromSelector("<webctrl id='geography' tag='INPUT' />"), "C");
    ScoreCardScreen.TypeInto(Target.FromSelector("<webctrl id='history' tag='INPUT' />"), "A");
    ScoreCardScreen.TypeInto(Target.FromSelector("<webctrl id='english' tag='INPUT' />"), "A");
    ScoreCardScreen.TypeInto(Target.FromSelector("<webctrl id='computer Science' tag='INPUT' />"), "C");
    ScoreCardScreen.TypeInto(Target.FromSelector("<webctrl id='professorComments' tag='INPUT' />"), "The student is doing okay, very hardworking and does its best");ScoreCardScreen.TypeInto(Target.FromSelector("<webctrl id='mathematics' tag='INPUT' />"), "A");
    ScoreCardScreen.TypeInto(Target.FromSelector("<webctrl id='physics' tag='INPUT' />"), "B");
    ScoreCardScreen.TypeInto(Target.FromSelector("<webctrl id='biology' tag='INPUT' />"), "C");
    ScoreCardScreen.TypeInto(Target.FromSelector("<webctrl id='chemistry' tag='INPUT' />"), "A");
    ScoreCardScreen.TypeInto(Target.FromSelector("<webctrl id='geography' tag='INPUT' />"), "C");
    ScoreCardScreen.TypeInto(Target.FromSelector("<webctrl id='history' tag='INPUT' />"), "A");
    ScoreCardScreen.TypeInto(Target.FromSelector("<webctrl id='english' tag='INPUT' />"), "A");
    ScoreCardScreen.TypeInto(Target.FromSelector("<webctrl id='computer Science' tag='INPUT' />"), "C");
    ScoreCardScreen.TypeInto(Target.FromSelector("<webctrl id='professorComments' tag='INPUT' />"), "The student is doing okay, very hardworking and does its best");
  14. Click API を使用して、[Add score card details] を選択します。
    // 10. Click the "Add score card details" button using an Object Repository descriptor
    ScoreCardScreen.Click(AcmeApp.StudentsScoreCard.AddScoreCardDetailsButton);// 10. Click the "Add score card details" button using an Object Repository descriptor
    ScoreCardScreen.Click(AcmeApp.StudentsScoreCard.AddScoreCardDetailsButton);
  15. RunWorkflow() メソッドを使用して、ライブラリ プロジェクトからインポートしたワークフローを呼び出します。このメソッドにプロジェクト内のワークフローのパスを指定します。
    // 11. Invoke imported workflow from library
    RunWorkflow("notifyStudentScoreCardAdded.xaml");// 11. Invoke imported workflow from library
    RunWorkflow("notifyStudentScoreCardAdded.xaml");
  16. Dispose() API を使用して、シナリオを自動化するために開いたブラウザー タブを閉じます。
    // 12. Close the applications/browsers you opened, to finish he automation
    ScoreCardScreen.Dispose();// 12. Close the applications/browsers you opened, to finish he automation
    ScoreCardScreen.Dispose();

サンプル プロジェクト

この手順に従ってチュートリアルをご自身で試してみるには、「Using imported library projects in coded automations (コード化されたオートメーションでインポートしたライブラリ プロジェクトを使用する)」というサンプル プロジェクトをご覧ください。このファイルには、ライブラリ プロジェクトも含まれています。

Was this page helpful?

サポートを受ける
RPA について学ぶ - オートメーション コース
UiPath コミュニティ フォーラム
UiPath ロゴ (白)
信頼とセキュリティ
© 2005-2024 UiPath. All rights reserved.