<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                # 硒核心擴展(User-Extensions.js) > 原文: [https://www.guru99.com/selenium-core-extensions.html](https://www.guru99.com/selenium-core-extensions.html) 要了解擴展,首先讓我們了解 Selenium IDE 的三大支柱 1. Action: What operation you are performing on UI Screen ![Selenium Core Extensions (User-Extensions.js)](https://img.kancloud.cn/c0/3a/c03acc72008e856d10f08f230c6ffafc_391x265.png "Selenium Core Extensions") 2. 評估者/斷言:您對從 UI 獲得的數據進行何種驗證 ![Selenium Core Extensions (User-Extensions.js)](https://img.kancloud.cn/cc/9b/cc9b495c3b48e6f30e1292d2fc3b5a78_344x203.png "Selenium Core Extensions") 3. 定位器策略:如何在 UI 中找到元素。 ![Selenium Core Extensions (User-Extensions.js)](https://img.kancloud.cn/3a/6b/3a6b5d8827d747114d2fa9f567736b23_624x276.png "Selenium Core Extensions") 現在,Selenium IDE 擁有一個非常成熟的庫,其中包含大量的動作,斷言/評估器和定位器策略。 但是有時我們需要為項目需求添加更多功能。 在這種情況下,我們可以通過添加自定義擴展來擴展此庫。 這些自定義擴展名稱為“用戶擴展名”。 例如,我們需要一個 Action,它可以在將文本填充到 Web 元素之前將其轉換為大寫形式。 您無法在默認操作庫中找到此操作。 在這種情況下,您可以創建自己的“用戶擴展名”。 在本教程中,我們將學習如何創建用戶擴展名以將 Text 轉換為大寫 ## 創建 Selenium 用戶擴展的要求: 要為 Selenium IDE 創建用戶擴展,我們需要了解 [JavaScript](/interactive-javascript-tutorials.html) 和 [Java](/java-tutorial.html) Script 原型對象概念的基本概念。 ![Selenium Core Extensions (User-Extensions.js)](https://img.kancloud.cn/01/29/0129e8476c9c94d887f964f09c943112_566x91.png "Selenium Core Extensions") 要創建用戶擴展,您需要創建 Java 腳本方法并將其添加到 selenium 對象原型和 PageBot 對象原型中。 ## Selenium IDE 如何識別用戶擴展? 在啟動 Selenium IDE 時將用戶擴展添加到 Selenium IDE 中之后,將加載 javascript 原型中的所有這些擴展,并且 Selenium IDE 會通過它們的名稱識別它們。 ## 如何創建用戶擴展 **步驟 1)動作**-所有動作均以“ do”開始,即,如果該動作是大寫文本,則其名稱為 **doTextUpperCase。** 當我們在 Selenium IDE 中添加此操作方法時,Selenium IDE 本身將為此操作創建一個等待方法。 因此,在這種情況下,當我們創建 **doTextUpperCase** 操作時,Selenium IDE 將創建一個相應的等待函數作為 **TextUpperCaseAndWait** 。 它可以接受兩個參數 ***示例:大寫文本操作*** ``` Selenium.prototype.doTextUpperCase = function(locator, text) { // Here findElement is itself capable to handle all type of locator(xpath,css,name,id,className), We just need to pass the locator text var element = this.page().findElement(locator); // Create the text to type text = text.toUpperCase(); // Replace the element text with the new text this.page().replaceText(element, text); }; ``` **步驟 2)評估者/斷言-**在硒對象原型中注冊的所有評估者都將加上前綴 通過“獲取”或“是” getValueFromCompoundTable,isValueFromCompoundTable。在測試案例中,它可以接受兩個參數,一個用于目標,另一個用于值字段。 ![Selenium Core Extensions (User-Extensions.js)](https://img.kancloud.cn/4d/af/4daf7289b3042851cc5c18b5b09f1299_624x129.png "Selenium Core Extensions") 對于每個評估者,將具有以“ verify”,“ assert”為前綴的相應驗證功能,以及以“ waitFor”為前綴的 wait 函數。 ***示例:用于大寫文本評估者*** ``` Selenium.prototype.assertTextUpperCase = function(locator, text) { // All locator-strategies are automatically handled by "findElement" var element = this.page().findElement(locator); // Create the text to verify text = text.toUpperCase(); // Get the actual element value var actualValue = element.value; // Make sure the actual value matches the expected Assert.matches(expectedValue, actualValue); }; Selenium.prototype.isTextEqual = function(locator, text) { return this.getText(locator).value===text; }; Selenium.prototype.getTextValue = function(locator, text) { return this.getText(locator).value; }; ``` **步驟 3)定位器策略-**如果我們要創建自己的函數來定位元素,則 我們需要使用前綴為“ locateElementBy”的函數擴展 PageBot 原型。 它需要兩個參數,第一個是定位符字符串,第二個是文檔 需要搜索的地方。 示例:對于大寫文本定位器 ``` // The "inDocument" is a document you are searching. PageBot.prototype.locateElementByUpperCase = function(text, inDocument) { // Create the text to search for var expectedValue = text.toUpperCase(); // Loop through all elements, looking for ones that have // a value === our expected value var allElements = inDocument.getElementsByTagName("*"); // This star '*' is a kind of regular expression it will go through every element (in HTML DOM every element surely have a tag name like<body>,<a>,<h1>,<table>,<tr>,<td> etc. ). Here our motive is to find an element which matched with the Upper Case text we have passed so we will search it with all elements and when we get match we will have the correct web element. for (var i = 0; i < allElements.length; i++) { var testElement = allElements[i]; if (testElement.innerHTML && testElement.innerHTML === expectedValue) { return testElement; } } return null; }; ``` ## 如何使用新創建的核心擴展? 1. Go to Selenium IDE 單擊選項->選項... ![Selenium Core Extensions (User-Extensions.js)](https://img.kancloud.cn/78/a5/78a568a0706a6ecd6b3a42eb6a47772b_346x188.png "Selenium Core Extensions") 2. In General section select the location of the newly created Selenium Core Extension ![Selenium Core Extensions (User-Extensions.js)](https://img.kancloud.cn/b5/68/b568d4d7ac7b7db5da5f5ea1ac761199_499x253.png "Selenium Core Extensions") 3. 單擊“確定”,然后重新啟動 Selenium IDE。 ![Selenium Core Extensions (User-Extensions.js)](https://img.kancloud.cn/a8/22/a82222c55075a4e64301201600c17c03_519x76.png "Selenium Core Extensions") 4. 您將在命令列表中找到擴展名 ![Selenium Core Extensions (User-Extensions.js)](https://img.kancloud.cn/27/df/27df7c15426a2827c27efad165630dd3_504x196.png "Selenium Core Extensions") ## 這是 Selenium IDE 中使用的流行擴展/插件的列表 <colgroup><col> <col></colgroup> | **名稱** | **目的** | | 收藏夾 | 要將測試套件標記為收藏,并一鍵執行 | | Flex 飛行員 X | 對于基于 Flex 的自動化 | | FlexMonkium | 對于基于 Adobe Flex 的記錄和回放[在 Selenium IDE 中測試](/software-testing.html) | | 文件記錄 | 用于將日志保存到文件中 | | 流量控制 | 控制測試執行流程 | | 高亮元素 | 突出顯示 Web 控件 | | 隱式等待 | 等待元素一定的時間限制 | | 屏幕截圖失敗 | 截屏失敗 | | 檢測結果 | 一鍵式保存測試套件的[測試用例](/test-case.html)結果 | 您可以從 SeleniumHQ 官方網站的下載部分獲得所有這些信息。 http://docs.seleniumhq.org/download/ 摘要: * Selenium IDE 包含三個部分:操作,評估器/斷言,定位器策略。 * 當 Selenium IDE 不滿足當前要求時,將創建用戶擴展。 * 要創建用戶擴展名,需要將 javascript 添加到硒的對象原型中。 * 創建擴展后,需要將其添加到 Selenium IDE 中并重新啟動 IDE。 [下載本教程中使用的 Selenium Core 擴展](https://drive.google.com/uc?export=download&id=0B_vqvT0ovzHcc3pRcV84eUpiQmM)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看