Studio
2023.10
False
Image de fond de la bannière
Guide de l’utilisateur de Studio
Dernière mise à jour 26 avr. 2024

Utilisation de projets de bibliothèque importés dans des automatisations codées

Ce tutoriel vous montre comment utiliser les objets de projets de bibliothèque importés dans des automatisations codées. L’exemple montre comment utiliser les éléments et les workflows du référentiel d’objets à partir d’un projet de bibliothèque importé. Le scénario donné consiste à automatiser le site Web de l’Acme, pour remplir une carte de score étudiante et l’ajouter à la base de données.

Prérequis

Installer les activités UIAutomation version 23.10.3 ou supérieure.

1. Créer le projet de bibliothèque

Créez un projet de bibliothèque pour stocker les éléments d’IU essentiels à l’automatisation de l’application Acme, en particulier pour remplir une carte de score étudiante. De plus, créez un workflow low-code (.xaml) ou codé (.cs) dans le projet de bibliothèque, que vous utiliserez plus tard dans une autre automatisation codée.
  1. Créez un projet de bibliothèque nommé AcmeLibrary.
  2. Capturez tous les éléments d’IU que vous souhaitez utiliser dans les sections Référentiel d’objets (Object Repository) et Descripteurs (Descriptors).
  3. Créez un nouveau Workflow codé à partir du groupe Fichier (File).

    Cette étape est cruciale pour activer l’accès au référentiel d’objets dans une automatisation codée lors de l’importation de la bibliothèque dans un autre projet.

  4. Renommez le Workflow low-code principal en Send message box et ajoutez une activité Zone de message (Message box) avec le texte suivant : « Vous avez ajouté une nouvelle carte de score pour un étudiant d’Acme. »
    Remarque : vous pouvez également recréer l’activité Zone de message (Message Box) en tant que workflow codé, en suivant les étapes décrites dans le tutoriel.
  5. Enregistrez et publiez le projet de bibliothèque dans un flux.

    Vous installerez et utiliserez cette bibliothèque publiée dans un autre projet au sein d’une automatisation codée.

2. Créer l’automatisation codée

Après avoir créé le projet de bibliothèque, installez-le dans un autre projet pour tirer parti de ses ressources réutilisables, y compris les éléments et les workflows du référentiel d’objets, qu’ils soient low-code (.xaml) ou codés (.cs).
Astuce : Lorsque vous utilisez les API UIAutomation, n’oubliez pas que les surcharges avec IScreenDescriptor ou IElementDescriptor sont destinées à fonctionner avec les éléments du Référentiel d’objets, tandis que les surcharges avec TargetAnchorableModel sont destinées à être utilisées avec des sélecteurs natifs obtenus via UI Explorer. Consultez la section API d’UIAutomation pour apprendre à exploiter les sélecteurs avec les API d’UIAutomation.
  1. À partir du groupe Fichier (File), créez un nouveau Workflow codé (Coded Workflow).
  2. Accédez à Gérer les packages (Manage Packages) et installez le projet de bibliothèque que vous avez précédemment créé.
  3. À partir du groupe Fichier (File), créez un nouveau Workflow.
    1. Nommez le workflow notifyStudentScoreCardAdded.
    2. Accédez au panneau Activités (Activities), puis à la section Installé (Installed).
    3. Recherchez le nom du projet de bibliothèque que vous avez importé (pour cet exemple, AcmeLibrary).
    4. Glissez-déposez l’activité Send message box à l’intérieur de notifyStudentScoreCardAdded.
      Désormais, le notifyStudentScoreCardAdded a le même comportement que le workflow Send message box du projet de bibliothèque importé.
  4. Pour améliorer la lisibilité, vous pouvez définir votre application de référentiel d’objets importée en tant que variable appliquant une instruction using au début de votre workflow. Voici un exemple : using app = <ProjectName>.ObjectRepository.Descriptors.<AppName>.
    Avec cette approche, vous pouvez facilement appeler des descripteurs au format suivant : app.<ScreenName>.<UiElementName>
    Pour cet exemple, nous définissons le Référentiel d’objets Acme comme suit :
    namespace UsingImportedLibraryProjects
    {
        using AcmeApp = AcmeLibrary.ObjectRepository.Descriptors.Acme;namespace UsingImportedLibraryProjects
    {
        using AcmeApp = AcmeLibrary.ObjectRepository.Descriptors.Acme;
  5. Vous pouvez maintenant automatiser le scénario donné dans Acme. Commencez par ouvrir l’écran de connexion Acme à l’aide de l’option l’API Ouvrir (Open).
    [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. Saisissez les informations d’identification nécessaires pour vous connecter à Acme, à l’aide de l’API SaisirDans (TypeInto).
    // 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. Utilisez l’API Cliquer (Click) avec un sélecteur natif pour cliquer sur le bouton Connexion (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. Le processus de connexion vous permet d’accéder à l’écran Tableau de bord (Dashboard) dans l’application Web Acme. Par conséquent, utilisez l’API Joindre (Attach) pour vous concentrer sur le nouvel écran.
    // 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. Sélectionnez l’entrée Étudiants (Students) sur le site Web à l’aide de l’API Cliquer (Click).
    // 5. Click the Students entry
    DashboardScreen.Click(AcmeApp.Dashboard.Students);// 5. Click the Students entry
    DashboardScreen.Click(AcmeApp.Dashboard.Students);
  10. Sélectionnez Carte de score (Score card) pour ouvrir le formulaire Étudiants - Carte de score (Studio - Score Card), à l’aide de l’API Cliquer (Click).
    // 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. Concentrez-vous sur l’écran Étudiants - Carte de score (Studio - Score Card), en utilisant l’API Joindre (Attach).
    // 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. Remplissez la moitié des champs du formulaire Étudiants - Carte de score (Studio - Score Card) à l’aide de l’API SaisirDans (TypeInto) et les éléments du Référentiel d’objets (Object Repository).
    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. Remplissez le reste des champs du formulaire à l’aide de l’API SaisirDans (TypeInto) en combinaison avec des sélecteurs natifs que vous découvrez via 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. Sélectionnez Ajouter des détails de carte de score à l’aide de l’API Cliquer (Click).
    // 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. Appelez le workflow que vous avez importé à partir du projet de bibliothèque à l’aide de la méthode RunWorkflow(). Fournissez à la méthode le chemin d’accès du workflow à l’intérieur du projet.
    // 11. Invoke imported workflow from library
    RunWorkflow("notifyStudentScoreCardAdded.xaml");// 11. Invoke imported workflow from library
    RunWorkflow("notifyStudentScoreCardAdded.xaml");
  16. Fermez les onglets du navigateur que vous avez ouverts pour automatiser le scénario, à l’aide de l’API Dispose().
    // 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();

Exemple de projet

Pour suivre les étapes et essayer le tutoriel vous-même, consultez l’exemple de projet suivant : Utilisation de projets de bibliothèque importés dans des automatisations codées. Le fichier contient également le projet de bibliothèque.

Cette page vous a-t-elle été utile ?

Obtenez l'aide dont vous avez besoin
Formation RPA - Cours d'automatisation
Forum de la communauté UiPath
Logo Uipath blanc
Confiance et sécurité
© 2005-2024 UiPath. All rights reserved.