提交 d6f5e599 编写于 作者: W wizardforcel

2020-06-14 19:57:25

上级 6bf5daa3
# 7 河。 Selenium IDE –暂停和反射
# 7 河。 Selenium IDE – 暂停和反射
> 原文: [https://javabeginnerstutorial.com/selenium/7r-ide-pause-reflect/](https://javabeginnerstutorial.com/selenium/7r-ide-pause-reflect/)
......
......@@ -36,11 +36,11 @@
## *提示:*
* 带着**微笑**出现。
* 合适的**衣服** –必须穿着舒适,整洁的衣服。
* **肢体语言** –避免将手放在口袋中或握在固定装置上,在讲话时以轻微的身体移动或手势来表达您的感觉。
* 取悦**语音** –使用适当的调制,在必要时重复,请尽量减少使用 uh,um 等填充物,实际上,您知道等等。
* 合适的**衣服** 必须穿着舒适,整洁的衣服。
* **肢体语言** 避免将手放在口袋中或握在固定装置上,在讲话时以轻微的身体移动或手势来表达您的感觉。
* 取悦**语音** 使用适当的调制,在必要时重复,请尽量减少使用 uh,um 等填充物,实际上,您知道等等。
* **传送信息的速度**也起着重要作用。
* **眼神交流** –使用眼动横扫听众,营造出个人化注意力的印象。
* **眼神交流** 使用眼动横扫听众,营造出个人化注意力的印象。
* 最重要的是:说话时,请勿在投影**的前面挡住**的视图。
如果您遵循我在这篇文章中提到的大部分内容,则一定会留下您的印记。
......@@ -53,4 +53,4 @@ Like the presentation I created and looking to make a copy of it and edit accord
###### 下一篇文章
##### [9a。 WebDriver –体系结构及其工作方式](https://javabeginnerstutorial.com/selenium/9a-webdriver-architecture/ "9a. WebDriver – Architecture and how it works")
\ No newline at end of file
##### [9a。 WebDriver – 体系结构及其工作方式](https://javabeginnerstutorial.com/selenium/9a-webdriver-architecture/ "9a. WebDriver – Architecture and how it works")
\ No newline at end of file
# 9a。 WebDriver –体系结构及其工作方式
# 9a。 WebDriver – 体系结构及其工作方式
> 原文: [https://javabeginnerstutorial.com/selenium/9a-webdriver-architecture/](https://javabeginnerstutorial.com/selenium/9a-webdriver-architecture/)
......@@ -16,7 +16,7 @@
2. WebDriver API 和
3. 车手
让我们一次讨论这一步骤。 *大字警报!* **绑定** –根据 Wikipedia,这意味着将一件事映射到另一件事。 只要记住这两个词,*粘合代码*即可。
让我们一次讨论这一步骤。 *大字警报!* **绑定** 根据 Wikipedia,这意味着将一件事映射到另一件事。 只要记住这两个词,*粘合代码*即可。
有很多高级编程语言,您可能想使用 C#,但其他人可能更喜欢 Python。 每个人都希望利用通用的 WebDriver API 来以自己舒适的语言自动化浏览器。 这是语言级别绑定进入图片的地方。 这些就像用相应语言编写的*粘合代码/包装库*与 WebDriver API 进行通信。 除了 Java,C#,Ruby,Python 绑定外,还有更多。 也很容易添加新的。
......@@ -40,4 +40,4 @@
###### 下一篇文章
##### [9b。 WebDriver –在 Eclipse 中设置](https://javabeginnerstutorial.com/selenium/9b-webdriver-eclipse-setup/ "9b. WebDriver – Set Up in Eclipse")
\ No newline at end of file
##### [9b。 WebDriver – 在 Eclipse 中设置](https://javabeginnerstutorial.com/selenium/9b-webdriver-eclipse-setup/ "9b. WebDriver – Set Up in Eclipse")
\ No newline at end of file
# 9b。 WebDriver –在 Eclipse 中设置
# 9b。 WebDriver – 在 Eclipse 中设置
> 原文: [https://javabeginnerstutorial.com/selenium/9b-webdriver-eclipse-setup/](https://javabeginnerstutorial.com/selenium/9b-webdriver-eclipse-setup/)
......@@ -86,4 +86,4 @@ System.setProperty("webdriver.gecko.driver", "<path_to_geckodriver.exe>");
###### 下一篇文章
##### [9c。 WebDriver –启动 Firefox](https://javabeginnerstutorial.com/selenium/9c-webdriver-first-test-script-firefox/ "9c. WebDriver – First test script by launching Firefox") 的第一个测试脚本
\ No newline at end of file
##### [9c。 WebDriver – 启动 Firefox](https://javabeginnerstutorial.com/selenium/9c-webdriver-first-test-script-firefox/ "9c. WebDriver – First test script by launching Firefox") 的第一个测试脚本
\ No newline at end of file
# 9c。 WebDriver –启动 Firefox 的第一个测试脚本
# 9c。 WebDriver – 启动 Firefox 的第一个测试脚本
> 原文: [https://javabeginnerstutorial.com/selenium/9c-webdriver-first-test-script-firefox/](https://javabeginnerstutorial.com/selenium/9c-webdriver-first-test-script-firefox/)
......@@ -161,4 +161,4 @@ quit()方法关闭所有浏览器窗口,并完全结束 WebDriver 会话
###### 下一篇文章
##### [9d。 WebDriver –执行测试](https://javabeginnerstutorial.com/selenium/9d-webdriver-executing-test/ "9d. WebDriver – Executing the Test")
\ No newline at end of file
##### [9d。 WebDriver – 执行测试](https://javabeginnerstutorial.com/selenium/9d-webdriver-executing-test/ "9d. WebDriver – Executing the Test")
\ No newline at end of file
# 9d。 WebDriver –执行测试
# 9d。 WebDriver – 执行测试
> 原文: [https://javabeginnerstutorial.com/selenium/9d-webdriver-executing-test/](https://javabeginnerstutorial.com/selenium/9d-webdriver-executing-test/)
......@@ -24,4 +24,4 @@ WebDriver 系列的第一个 ***BrainBell*** 的时间:*回忆!* 您知道
###### 下一篇文章
##### [9e。 WebDriver –用于启动其他浏览器的代码示例](https://javabeginnerstutorial.com/selenium/9e-webdriver-code-launching-browsers/ "9e. WebDriver – Code samples for launching other browsers")
\ No newline at end of file
##### [9e。 WebDriver – 用于启动其他浏览器的代码示例](https://javabeginnerstutorial.com/selenium/9e-webdriver-code-launching-browsers/ "9e. WebDriver – Code samples for launching other browsers")
\ No newline at end of file
# 9e。 WebDriver –用于启动其他浏览器的代码示例
# 9e。 WebDriver – 用于启动其他浏览器的代码示例
> 原文: [https://javabeginnerstutorial.com/selenium/9e-webdriver-code-launching-browsers/](https://javabeginnerstutorial.com/selenium/9e-webdriver-code-launching-browsers/)
......@@ -58,7 +58,7 @@ public class HelloWorld_IE {
}
```
如果注意到的话,此代码与我们在上一篇文章“ **第一个测试脚本通过启动 Firefox** ”中看到的代码非常相似。
如果注意到的话,此代码与我们在上一篇文章“ **第一个测试脚本通过启动 Firefox** ”中看到的代码非常相似。
这些其他浏览器需要设置系统属性,因为不支持直接启动该属性。
......
......@@ -49,4 +49,4 @@
###### 下一篇文章
##### [9 克。 WebDriver –在 JUnit4](https://javabeginnerstutorial.com/selenium/9g-webdriver-running-tests-junit4/ "9g. WebDriver – Running WebDriver tests in JUnit4") 中运行 WebDriver 测试
\ No newline at end of file
##### [9 克。 WebDriver – 在 JUnit4](https://javabeginnerstutorial.com/selenium/9g-webdriver-running-tests-junit4/ "9g. WebDriver – Running WebDriver tests in JUnit4") 中运行 WebDriver 测试
\ No newline at end of file
# 9 克 WebDriver –在 JUnit4 中运行 WebDriver 测试
# 9 克 WebDriver – 在 JUnit4 中运行 WebDriver 测试
> 原文: [https://javabeginnerstutorial.com/selenium/9g-webdriver-running-tests-junit4/](https://javabeginnerstutorial.com/selenium/9g-webdriver-running-tests-junit4/)
......@@ -12,7 +12,7 @@
![JUnit implementation](img/ac2ffc78ad525227b36a8a3fa84ed450.png)
现在我们已经准备好上课的文件了,让我们采用与“ [**第一个测试脚本通过启动 Firefox**](https://javabeginnerstutorial.com/selenium/9c-webdriver-first-test-script-firefox/) ”帖子中相同的方案。
现在我们已经准备好上课的文件了,让我们采用与“ [**第一个测试脚本通过启动 Firefox**](https://javabeginnerstutorial.com/selenium/9c-webdriver-first-test-script-firefox/) ”帖子中相同的方案。
1. 打开 Firefox 浏览器。
2. 导航到“ https://www.google.com/”
......@@ -88,11 +88,11 @@ public class FirstJunitTest {
大字警报! **注释:**这些将特定的含义传达给 JUnit。 他们告诉 JUnit,应该附加到它的*公共无效*方法,
**@Test** –被当作测试方法运行。
**@Test** 被当作测试方法运行。
**@Before** –在指定的每种测试方法之前运行。 这用于各种目的。 读取或分配数据,初始化或如果多个测试需要先创建相似的对象才能执行,则最好在之前注释的方法下进行指定。
**@Before** 在指定的每种测试方法之前运行。 这用于各种目的。 读取或分配数据,初始化或如果多个测试需要先创建相似的对象才能执行,则最好在之前注释的方法下进行指定。
**@After** –在执行每种测试方法之后运行。 通常,会指定与环境清理相关的命令,例如,关闭打开的资源/数据库连接,删除临时数据,释放内存等。即使@Before 或@Test 方法引发异常,也可以保证运行带 after 注释的方法。
**@After** 在执行每种测试方法之后运行。 通常,会指定与环境清理相关的命令,例如,关闭打开的资源/数据库连接,删除临时数据,释放内存等。即使@Before 或@Test 方法引发异常,也可以保证运行带 after 注释的方法。
键入这些注释,在它们下方会出现一条弯曲的线。 悬停时,日食将建议所有可能的快速修复。 单击建议导入 *org.junit* 程序包的第一个修复程序。
......@@ -120,4 +120,4 @@ public class FirstJunitTest {
###### 下一篇文章
##### [9 小时。 WebDriver –隐式等待](https://javabeginnerstutorial.com/selenium/9h-webdriver-implicit-waits/ "9h. WebDriver – Implicit Waits")
\ No newline at end of file
##### [9 小时。 WebDriver – 隐式等待](https://javabeginnerstutorial.com/selenium/9h-webdriver-implicit-waits/ "9h. WebDriver – Implicit Waits")
\ No newline at end of file
# 9 小时 WebDriver –隐式等待
# 9 小时 WebDriver – 隐式等待
> 原文: [https://javabeginnerstutorial.com/selenium/9h-webdriver-implicit-waits/](https://javabeginnerstutorial.com/selenium/9h-webdriver-implicit-waits/)
......@@ -62,4 +62,4 @@ driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
###### 下一篇文章
##### [9i。 WebDriver –显式等待](https://javabeginnerstutorial.com/selenium/9i-webdriver-explicit-waits/ "9i. WebDriver – Explicit Waits")
\ No newline at end of file
##### [9i。 WebDriver – 显式等待](https://javabeginnerstutorial.com/selenium/9i-webdriver-explicit-waits/ "9i. WebDriver – Explicit Waits")
\ No newline at end of file
# 9i。 WebDriver –显式等待
# 9i。 WebDriver – 显式等待
> 原文: [https://javabeginnerstutorial.com/selenium/9i-webdriver-explicit-waits/](https://javabeginnerstutorial.com/selenium/9i-webdriver-explicit-waits/)
大家好! 这篇文章是先前文章 [**9h 的延续。 WebDriver –隐式等待**](https://javabeginnerstutorial.com/selenium/9h-webdriver-implicit-waits/)
大家好! 这篇文章是先前文章 [**9h 的延续。 WebDriver – 隐式等待**](https://javabeginnerstutorial.com/selenium/9h-webdriver-implicit-waits/)
事不宜迟,让我们利用“显式等待”的力量。 显式等待需要更多的编码,但是与隐式等待相比,它具有巨大的优势。 在这里,我们可以等到某种情况发生后再进行测试。 如果在指定的超时值内未满足条件,则将引发异常。
......@@ -19,10 +19,10 @@ WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.id("e
ExpectedCondition 预定义方法的一些示例是,
* [*elementToBeClickable*](https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/support/ui/ExpectedConditions.html#elementToBeClickable-org.openqa.selenium.By-)[](https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/By.html) 定位符提供的 [*)–用于检查元素的期望是可见的并已启用,以便您可以单击它。*](https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/By.html)
* [*elementToBeClickable*](https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/support/ui/ExpectedConditions.html#elementToBeClickable-org.openqa.selenium.By-)[](https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/By.html) 定位符提供的 [*)– 用于检查元素的期望是可见的并已启用,以便您可以单击它。*](https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/By.html)
* [*elementToBeSelected*](https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/support/ui/ExpectedConditions.html#elementToBeSelected-org.openqa.selenium.WebElement-) *(* [*WebElement*](https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/WebElement.html) 元素)-检查是否选择了给定元素。
* [*presentOfElementLocated*](https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/support/ui/ExpectedConditions.html#presenceOfElementLocated-org.openqa.selenium.By-) *(* 定位符提供的 [*)–期望检查元素的 DOM 上是否存在元素 页。*](https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/By.html)
* [*urlToBe*](https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/support/ui/ExpectedConditions.html#urlToBe-java.lang.String-) *(java.lang.String* url)–当前页面的 URL 是一个特定的 URL。
* [*presentOfElementLocated*](https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/support/ui/ExpectedConditions.html#presenceOfElementLocated-org.openqa.selenium.By-) *(* 定位符提供的 [*)– 期望检查元素的 DOM 上是否存在元素 页。*](https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/By.html)
* [*urlToBe*](https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/support/ui/ExpectedConditions.html#urlToBe-java.lang.String-) *(java.lang.String* url)– 当前页面的 URL 是一个特定的 URL。
* [*可见性*](https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/support/ui/ExpectedConditions.html#visibilityOf-org.openqa.selenium.WebElement-) *(* [*WebElement*](https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/WebElement.html) 元素)-用于检查已知存在于元素上的元素的期望 页面的 DOM 是可见的。
您可以在此处找到[,找到适用于 Java 的 ExpectedConditions 包的所有可用方法及其用法的详细信息。](https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/support/ui/ExpectedConditions.html)
......@@ -75,4 +75,4 @@ public WebElement fluentWait(final By locator) {
###### 下一篇文章
##### [9j。 WebDriver –定位元素:第 1 部分(按 ID,名称,标记名)](https://javabeginnerstutorial.com/selenium/9j-webdriver-locating-elements-1/ "9j. WebDriver – Locating elements: Part 1 (by id, name, tagName)")
\ No newline at end of file
##### [9j。 WebDriver – 定位元素:第 1 部分(按 ID,名称,标记名)](https://javabeginnerstutorial.com/selenium/9j-webdriver-locating-elements-1/ "9j. WebDriver – Locating elements: Part 1 (by id, name, tagName)")
\ No newline at end of file
# 9j。 WebDriver –定位元素:第 1 部分(按 id,名称,tagName)
# 9j。 WebDriver – 定位元素:第 1 部分(按 id,名称,tagName)
> 原文: [https://javabeginnerstutorial.com/selenium/9j-webdriver-locating-elements-1/](https://javabeginnerstutorial.com/selenium/9j-webdriver-locating-elements-1/)
......@@ -12,12 +12,12 @@ driver.findElement(By.LocatorStrategyType ("Locator_Value"));
**说明:**
* *驱动程序* –实现 WebDriver 接口的相应驱动程序类的实例变量
* *findElement()* –查找并返回具有指定位置策略的第一个 Web 元素
* *findElements()* –查找并返回与给定位置策略匹配的 Web 元素列表
* *按* –始终使用按类别定位目标
* *驱动程序* 实现 WebDriver 接口的相应驱动程序类的实例变量
* *findElement()* 查找并返回具有指定位置策略的第一个 Web 元素
* *findElements()* 查找并返回与给定位置策略匹配的 Web 元素列表
* *按* 始终使用按类别定位目标
* *LocatorStrategyType* – ID,名称,标记名,类名,cssSelector,linkText,partialLinkText,xpath 是可用于在页面上定位元素的某些定位器类型
* *Locator_Value* –可以标识元素的 value / HTML 标记
* *Locator_Value* 可以标识元素的 value / HTML 标记
#### 可用的定位器类型包括:
......@@ -44,8 +44,8 @@ id 是在页面上定位元素的最有用和首选的方式,因为它是唯
***示例***打开 Goog​​le 帐户创建页面。 让我们通过 ID 识别名字文本框。
* Google Chrome –右键单击要确定其 ID 的网络元素,然后选择“检查”。 或通过单击 F12 打开开发人员工具,单击左上角的检查元素图标,然后在页面上单击所需的 Web 元素。 两种方法都将突出显示与所选元素相对应的 HTML 代码。
* Mozilla Firefox –右键单击 Web 元素,然后选择“使用 Firebug 检查元素”(以防您错过了 [<u>Firebug 安装和使用</u>](https://javabeginnerstutorial.com/selenium/7n-ide-using-firebug/) 上的帖子)。 或者,如果您确实不想使用 Firebug,则右键单击该元素并选择“检查元素”。 在两种情况下,都将打开并突出显示相应的 HTML 代码。
* Google Chrome – 右键单击要确定其 ID 的网络元素,然后选择“检查”。 或通过单击 F12 打开开发人员工具,单击左上角的检查元素图标,然后在页面上单击所需的 Web 元素。 两种方法都将突出显示与所选元素相对应的 HTML 代码。
* Mozilla Firefox – 右键单击 Web 元素,然后选择“使用 Firebug 检查元素”(以防您错过了 [<u>Firebug 安装和使用</u>](https://javabeginnerstutorial.com/selenium/7n-ide-using-firebug/) 上的帖子)。 或者,如果您确实不想使用 Firebug,则右键单击该元素并选择“检查元素”。 在两种情况下,都将打开并突出显示相应的 HTML 代码。
![Locating by Id](img/c073039501d98689d51ef3a4addb1095.png)
......@@ -177,9 +177,9 @@ System.out.println("First button text: " + signInButton.getText());
将导入两个新的软件包,
**导入** org.openqa.selenium.WebElement –实例化一个新的 Web 元素。
**导入** org.openqa.selenium.WebElement – 实例化一个新的 Web 元素。
**导入** org.openqa.selenium.By; –该包引用了被称为定位器类型的 By 类。
**导入** org.openqa.selenium.By; – 该包引用了被称为定位器类型的 By 类。
注释清楚地提供给每一行代码,因此很容易解释。
......@@ -193,4 +193,4 @@ System.out.println("First button text: " + signInButton.getText());
###### 下一篇文章
##### [9k。 WebDriver –定位元素:第 2 部分(按 className,linkText,partialLinkText)](https://javabeginnerstutorial.com/selenium/9k-webdriver-locating-elements-2/ "9k. WebDriver – Locating elements: Part 2 (by className, linkText, partialLinkText)")
\ No newline at end of file
##### [9k。 WebDriver – 定位元素:第 2 部分(按 className,linkText,partialLinkText)](https://javabeginnerstutorial.com/selenium/9k-webdriver-locating-elements-2/ "9k. WebDriver – Locating elements: Part 2 (by className, linkText, partialLinkText)")
\ No newline at end of file
# 9k。 WebDriver –定位元素:第 2 部分(按 className,linkText,partialLinkText)
# 9k。 WebDriver – 定位元素:第 2 部分(按 className,linkText,partialLinkText)
> 原文: [https://javabeginnerstutorial.com/selenium/9k-webdriver-locating-elements-2/](https://javabeginnerstutorial.com/selenium/9k-webdriver-locating-elements-2/)
......@@ -157,4 +157,4 @@ public class ElementLocatorTest2 {
###### 下一篇文章
##### [9l。 WebDriver –定位元素:第 3a 部分(由 cssSelector 提供)](https://javabeginnerstutorial.com/selenium/9l-webdriver-locating-elements-3a/ "9l. WebDriver – Locating elements: Part 3a (by cssSelector)")
\ No newline at end of file
##### [9l。 WebDriver – 定位元素:第 3a 部分(由 cssSelector 提供)](https://javabeginnerstutorial.com/selenium/9l-webdriver-locating-elements-3a/ "9l. WebDriver – Locating elements: Part 3a (by cssSelector)")
\ No newline at end of file
# 9 升 WebDriver –定位元素:第 3a 部分(由 cssSelector 提供)
# 9 升 WebDriver – 定位元素:第 3a 部分(由 cssSelector 提供)
> 原文: [https://javabeginnerstutorial.com/selenium/9l-webdriver-locating-elements-3a/](https://javabeginnerstutorial.com/selenium/9l-webdriver-locating-elements-3a/)
......@@ -161,4 +161,4 @@ driver.findElement(By.cssSelector("input[type='Password'][name='Passwd'"));
###### 下一篇文章
##### [9m。 WebDriver –定位元素:第 3b 部分(由 cssSelector 续)](https://javabeginnerstutorial.com/selenium/9m-webdriver-locating-elements-3b/ "9m. WebDriver – Locating elements: Part 3b (by cssSelector contd.)")
\ No newline at end of file
##### [9m。 WebDriver – 定位元素:第 3b 部分(由 cssSelector 续)](https://javabeginnerstutorial.com/selenium/9m-webdriver-locating-elements-3b/ "9m. WebDriver – Locating elements: Part 3b (by cssSelector contd.)")
\ No newline at end of file
# 9m。 WebDriver –定位元素:第 3b 部分(由 cssSelector 续)
# 9m。 WebDriver – 定位元素:第 3b 部分(由 cssSelector 续)
> 原文: [https://javabeginnerstutorial.com/selenium/9m-webdriver-locating-elements-3b/](https://javabeginnerstutorial.com/selenium/9m-webdriver-locating-elements-3b/)
嗨,忍者! 这篇文章是我们先前文章“ [*9l”的延续。 WebDriver –定位元素:第 3a 部分(由 cssSelector 提供)*](https://javabeginnerstutorial.com/selenium/9l-webdriver-locating-elements-3a/) ”。 在继续进行操作之前,请确保对它进行了仔细的研究。
嗨,忍者! 这篇文章是我们先前文章“ [*9l”的延续。 WebDriver – 定位元素:第 3a 部分(由 cssSelector 提供)*](https://javabeginnerstutorial.com/selenium/9l-webdriver-locating-elements-3a/) ”。 在继续进行操作之前,请确保对它进行了仔细的研究。
使用 cssSelector 定位器的最后两种方法尚待讨论:
......@@ -260,4 +260,4 @@ public class ElementLocatorTest3 {
###### 下一篇文章
##### [9n。 WebDriver –定位元素:第 4a 部分(通过 xpath)](https://javabeginnerstutorial.com/selenium/9n-webdriver-locating-elements-4a/ "9n. WebDriver – Locating elements: Part 4a (by xpath)")
\ No newline at end of file
##### [9n。 WebDriver – 定位元素:第 4a 部分(通过 xpath)](https://javabeginnerstutorial.com/selenium/9n-webdriver-locating-elements-4a/ "9n. WebDriver – Locating elements: Part 4a (by xpath)")
\ No newline at end of file
# 9n。 WebDriver –定位元素:第 4a 部分(通过 xpath)
# 9n。 WebDriver – 定位元素:第 4a 部分(通过 xpath)
> 原文: [https://javabeginnerstutorial.com/selenium/9n-webdriver-locating-elements-4a/](https://javabeginnerstutorial.com/selenium/9n-webdriver-locating-elements-4a/)
......@@ -273,4 +273,4 @@ public class ElementLocatorTest4 {
###### 下一篇文章
##### [9o。 WebDriver –定位元素:第 4b 部分(由 XPath 续)](https://javabeginnerstutorial.com/selenium/9o-webdriver-locating-elements-4b/ "9o. WebDriver – Locating elements: Part 4b (by XPath contd.)")
\ No newline at end of file
##### [9o。 WebDriver – 定位元素:第 4b 部分(由 XPath 续)](https://javabeginnerstutorial.com/selenium/9o-webdriver-locating-elements-4b/ "9o. WebDriver – Locating elements: Part 4b (by XPath contd.)")
\ No newline at end of file
# 9o。 WebDriver –定位元素:第 4b 部分(由 XPath 续)
# 9o。 WebDriver – 定位元素:第 4b 部分(由 XPath 续)
> 原文: [https://javabeginnerstutorial.com/selenium/9o-webdriver-locating-elements-4b/](https://javabeginnerstutorial.com/selenium/9o-webdriver-locating-elements-4b/)
嗨冠军! 欢迎来到我们关于定位元素的最后一篇文章。 好极了!!!
这是我们上一篇文章“ [9n。 WebDriver –定位元素:第 4a 部分(由 XPath 提供)](https://javabeginnerstutorial.com/selenium/9n-webdriver-locating-elements-4a/)”。 您以前曾经听过我说过这个,然后您会再次听我说过……在继续使用 XPath 策略之前,请先阅读第 4a 部分。
这是我们上一篇文章“ [9n。 WebDriver – 定位元素:第 4a 部分(由 XPath 提供)](https://javabeginnerstutorial.com/selenium/9n-webdriver-locating-elements-4a/)”。 您以前曾经听过我说过这个,然后您会再次听我说过……在继续使用 XPath 策略之前,请先阅读第 4a 部分。
在这篇文章中,我们将研究以下技术,
......
......@@ -26,7 +26,7 @@ type="text">
![Shortcut](img/87d67dcea7c38175d9c6e55c5ca89c74.png)
1. 输入“ ***css = input [name ='RecoveryEmailAddress']*** ”作为目标。 要了解此命令的形成方式,请签出 [7l。 Selenium IDE –定位元素(续)。 (通过 CSS,DOM,XPath)](https://javabeginnerstutorial.com/selenium/7l-ide-locating-elements-contd/)
1. 输入“ ***css = input [name ='RecoveryEmailAddress']*** ”作为目标。 要了解此命令的形成方式,请签出 [7l。 Selenium IDE – 定位元素(续)。 (通过 CSS,DOM,XPath)](https://javabeginnerstutorial.com/selenium/7l-ide-locating-elements-contd/)
2. 点击**'查找'**
3. **“您当前的电子邮件地址”** 文本框在 Gmail 帐户注册页面上突出显示。
......@@ -38,4 +38,4 @@ type="text">
###### 下一篇文章
##### [9q。 WebDriver –处理验证码](https://javabeginnerstutorial.com/selenium/9q-webdriver-handling-captcha/ "9q. WebDriver – Handling a CAPTCHA")
\ No newline at end of file
##### [9q。 WebDriver – 处理验证码](https://javabeginnerstutorial.com/selenium/9q-webdriver-handling-captcha/ "9q. WebDriver – Handling a CAPTCHA")
\ No newline at end of file
# 9q。 WebDriver –处理验证码
# 9q。 WebDriver – 处理验证码
> 原文: [https://javabeginnerstutorial.com/selenium/9q-webdriver-handling-captcha/](https://javabeginnerstutorial.com/selenium/9q-webdriver-handling-captcha/)
......@@ -138,4 +138,4 @@ driver.findElement(By.id("recaptcha_response_field")).sendKeys(captchaVal);
###### 下一篇文章
##### [9r。 WebDriver –断言和验证](https://javabeginnerstutorial.com/selenium/9r-webdriver-assert-and-verify/ "9r. WebDriver – Assert and Verify")
\ No newline at end of file
##### [9r。 WebDriver – 断言和验证](https://javabeginnerstutorial.com/selenium/9r-webdriver-assert-and-verify/ "9r. WebDriver – Assert and Verify")
\ No newline at end of file
# 9 河 WebDriver –断言和验证
# 9 河 WebDriver – 断言和验证
> 原文: [https://javabeginnerstutorial.com/selenium/9r-webdriver-assert-and-verify/](https://javabeginnerstutorial.com/selenium/9r-webdriver-assert-and-verify/)
......@@ -13,7 +13,7 @@ Hiya 超级巨星! 我们已经定位元素很多天了。 让我们今天换
## 何时使用断言和验证?
最简单的答案是由您决定,换句话说,就是您的愿望! 您可以根据情况使用断言或验证,即是希望测试中止还是在检查失败后继续进行。
最简单的答案是由您决定,换句话说,就是您的愿望! 您可以根据情况使用断言或验证,即是希望测试中止还是在检查失败后继续进行。
### 使用断言的好处
......@@ -55,4 +55,4 @@ System.out.println("Assert not equals failed");
![Assert condition failed](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20720%20340'%3E%3C/svg%3E)
<noscript><img alt="Assert condition failed" class="alignnone size-full wp-image-14150" height="340" src="img/9272cef7d4d831fd5ed1b3ae54bbd374.png" width="720"/><p>上图中的控制台显示<code>assertEquals</code>条件成功,因此将打印检查后的语句,“ <strong>声明等于通过。 </strong>”,而<code>assertNotEquals</code>条件失败,因此将不执行此检查之后的行。 打印语句“ <strong>声明不等于失败</strong>”不会打印到控制台。</p><h3>情况 3:尽管 assertNotEquals 条件失败,但通过测试用例</h3><p>要仅验证实际值和预期值是否不相等,请使用<code>try-catch</code>块。</p><p><strong>Code snippet</strong></p><pre><code class="language-java">//Verify title not equal using try-catch block try { // Making the test fail Assert.assertNotEquals("WebDriver Demo Website", pageTitle); } catch(Error e){ // Following lines will be printed when the assert condition fails System.out.println("Assert not equals failed. But test execution is not aborted."); System.out.println("Error message: " + e.toString()); }</code></pre><p>即使<code>assertNotEquals</code>条件失败,catch 块中的语句也将被执行,并且错误消息将被打印到控制台。</p><p><img alt="Verify condition fails" class="alignnone size-full wp-image-14149" data-lazy-sizes="(max-width: 825px) 100vw, 825px" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2018/12/2_VerifyFailure-1.jpg" data-lazy-srcset="https://javabeginnerstutorial.com/wp-content/uploads/2018/12/2_VerifyFailure-1.jpg 825w, https://javabeginnerstutorial.com/wp-content/uploads/2018/12/2_VerifyFailure-1-300x124.jpg 300w, https://javabeginnerstutorial.com/wp-content/uploads/2018/12/2_VerifyFailure-1-768x318.jpg 768w" height="342" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20825%20342'%3E%3C/svg%3E" width="825"/></p><noscript><img alt="Verify condition fails" class="alignnone size-full wp-image-14149" height="342" sizes="(max-width: 825px) 100vw, 825px" src="img/d09793dee60556d778b6b7f310560194.png" srcset="https://javabeginnerstutorial.com/wp-content/uploads/2018/12/2_VerifyFailure-1.jpg 825w, https://javabeginnerstutorial.com/wp-content/uploads/2018/12/2_VerifyFailure-1-300x124.jpg 300w, https://javabeginnerstutorial.com/wp-content/uploads/2018/12/2_VerifyFailure-1-768x318.jpg 768w" width="825"/><p>如图所示,测试用例执行成功,并且错误被打印到控制台。</p><h2>完整的代码</h2><pre><code class="language-java">import java.util.concurrent.TimeUnit; import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; public class AssertAndVerify { // Declaring variables private WebDriver driver; private String baseUrl; @Before public void setUp() throws Exception { // Selenium version 3 beta releases require system property set up System.setProperty("webdriver.gecko.driver", "E:\\Softwares\\" + "Selenium\\geckodriver-v0.10.0-win64\\geckodriver.exe"); // Create a new instance for the class FirefoxDriver // that implements WebDriver interface driver = new FirefoxDriver(); // Implicit wait for 5 seconds driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); // Assign the URL to be invoked to a String variable baseUrl = "https://chandanachaitanya.github.io/selenium-practice-site/"; } @Test public void testPageTitle() throws Exception { // Open baseUrl in Firefox browser window driver.get(baseUrl); // Get the page title String pageTitle = driver.getTitle(); // Print the title to console System.out.println("The actual title is: " + pageTitle); // Check if actual and expected values are equal Assert.assertEquals("WebDriver Demo Website", pageTitle); // Printing success message System.out.println("Assert equals passed."); // Making the test fail //Assert.assertNotEquals("WebDriver Demo Website", pageTitle); // Following lines will not be executed as above assert condition fails //System.out.println("Assert not equals failed"); //Verify title not equal using try-catch block try { // Making the test fail Assert.assertNotEquals("WebDriver Demo Website", pageTitle); } catch(Error e){ // Following lines will be printed when the assert condition fails System.out.println("Assert not equals failed. But test execution is not aborted."); System.out.println("Error message: " + e.toString()); } } // End of @Test @After public void tearDown() throws Exception { // Close the Firefox browser driver.close(); } }</code></pre><p>所有代码文件都放置在<a href="https://github.com/JBTAdmin/Selenium/tree/master/WebDriver"> GitHub 存储库</a>中,以方便访问。 您可以为存储库加注星标和分支以方便使用。 请仔细阅读“ README.md”文件以获取明确说明。</p><p>总结了断言和验证的这一部分。 祝你有美好的一天!</p><div class="sticky-nav" style="font-size: 15px;"><div class="sticky-nav-image"></div><div class="sticky-nav-holder"><div class="sticky-nav_item"><h6 class="heading-sm">下一篇文章</h6></div><h5 class="sticky-nav_heading " style="font-size: 15px;"><a href="https://javabeginnerstutorial.com/selenium/9s-webdriver-handling-text-boxes-images/" title="9s. WebDriver – Handling text boxes and images"> 9 秒。 WebDriver –处理文本框和图像</a></h5></div></div> </body> </html></noscript>
\ No newline at end of file
<noscript><img alt="Assert condition failed" class="alignnone size-full wp-image-14150" height="340" src="img/9272cef7d4d831fd5ed1b3ae54bbd374.png" width="720"/><p>上图中的控制台显示<code>assertEquals</code>条件成功,因此将打印检查后的语句,“ <strong>声明等于通过。 </strong>”,而<code>assertNotEquals</code>条件失败,因此将不执行此检查之后的行。 打印语句“ <strong>声明不等于失败</strong>”不会打印到控制台。</p><h3>情况 3:尽管 assertNotEquals 条件失败,但通过测试用例</h3><p>要仅验证实际值和预期值是否不相等,请使用<code>try-catch</code>块。</p><p><strong>Code snippet</strong></p><pre><code class="language-java">//Verify title not equal using try-catch block try { // Making the test fail Assert.assertNotEquals("WebDriver Demo Website", pageTitle); } catch(Error e){ // Following lines will be printed when the assert condition fails System.out.println("Assert not equals failed. But test execution is not aborted."); System.out.println("Error message: " + e.toString()); }</code></pre><p>即使<code>assertNotEquals</code>条件失败,catch 块中的语句也将被执行,并且错误消息将被打印到控制台。</p><p><img alt="Verify condition fails" class="alignnone size-full wp-image-14149" data-lazy-sizes="(max-width: 825px) 100vw, 825px" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2018/12/2_VerifyFailure-1.jpg" data-lazy-srcset="https://javabeginnerstutorial.com/wp-content/uploads/2018/12/2_VerifyFailure-1.jpg 825w, https://javabeginnerstutorial.com/wp-content/uploads/2018/12/2_VerifyFailure-1-300x124.jpg 300w, https://javabeginnerstutorial.com/wp-content/uploads/2018/12/2_VerifyFailure-1-768x318.jpg 768w" height="342" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20825%20342'%3E%3C/svg%3E" width="825"/></p><noscript><img alt="Verify condition fails" class="alignnone size-full wp-image-14149" height="342" sizes="(max-width: 825px) 100vw, 825px" src="img/d09793dee60556d778b6b7f310560194.png" srcset="https://javabeginnerstutorial.com/wp-content/uploads/2018/12/2_VerifyFailure-1.jpg 825w, https://javabeginnerstutorial.com/wp-content/uploads/2018/12/2_VerifyFailure-1-300x124.jpg 300w, https://javabeginnerstutorial.com/wp-content/uploads/2018/12/2_VerifyFailure-1-768x318.jpg 768w" width="825"/><p>如图所示,测试用例执行成功,并且错误被打印到控制台。</p><h2>完整的代码</h2><pre><code class="language-java">import java.util.concurrent.TimeUnit; import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; public class AssertAndVerify { // Declaring variables private WebDriver driver; private String baseUrl; @Before public void setUp() throws Exception { // Selenium version 3 beta releases require system property set up System.setProperty("webdriver.gecko.driver", "E:\\Softwares\\" + "Selenium\\geckodriver-v0.10.0-win64\\geckodriver.exe"); // Create a new instance for the class FirefoxDriver // that implements WebDriver interface driver = new FirefoxDriver(); // Implicit wait for 5 seconds driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); // Assign the URL to be invoked to a String variable baseUrl = "https://chandanachaitanya.github.io/selenium-practice-site/"; } @Test public void testPageTitle() throws Exception { // Open baseUrl in Firefox browser window driver.get(baseUrl); // Get the page title String pageTitle = driver.getTitle(); // Print the title to console System.out.println("The actual title is: " + pageTitle); // Check if actual and expected values are equal Assert.assertEquals("WebDriver Demo Website", pageTitle); // Printing success message System.out.println("Assert equals passed."); // Making the test fail //Assert.assertNotEquals("WebDriver Demo Website", pageTitle); // Following lines will not be executed as above assert condition fails //System.out.println("Assert not equals failed"); //Verify title not equal using try-catch block try { // Making the test fail Assert.assertNotEquals("WebDriver Demo Website", pageTitle); } catch(Error e){ // Following lines will be printed when the assert condition fails System.out.println("Assert not equals failed. But test execution is not aborted."); System.out.println("Error message: " + e.toString()); } } // End of @Test @After public void tearDown() throws Exception { // Close the Firefox browser driver.close(); } }</code></pre><p>所有代码文件都放置在<a href="https://github.com/JBTAdmin/Selenium/tree/master/WebDriver"> GitHub 存储库</a>中,以方便访问。 您可以为存储库加注星标和分支以方便使用。 请仔细阅读“ README.md”文件以获取明确说明。</p><p>总结了断言和验证的这一部分。 祝你有美好的一天!</p><div class="sticky-nav" style="font-size: 15px;"><div class="sticky-nav-image"></div><div class="sticky-nav-holder"><div class="sticky-nav_item"><h6 class="heading-sm">下一篇文章</h6></div><h5 class="sticky-nav_heading " style="font-size: 15px;"><a href="https://javabeginnerstutorial.com/selenium/9s-webdriver-handling-text-boxes-images/" title="9s. WebDriver – Handling text boxes and images"> 9 秒。 WebDriver – 处理文本框和图像</a></h5></div></div> </body> </html></noscript>
\ No newline at end of file
# 9s。 WebDriver –处理文本框和图像
# 9s。 WebDriver – 处理文本框和图像
> 原文: [https://javabeginnerstutorial.com/selenium/9s-webdriver-handling-text-boxes-images/](https://javabeginnerstutorial.com/selenium/9s-webdriver-handling-text-boxes-images/)
......@@ -176,4 +176,4 @@ public class Click_Image {
###### 下一篇文章
##### [9t。 WebDriver –处理单选按钮和复选框](https://javabeginnerstutorial.com/selenium/9t-webdriver-handling-radio-buttons-checkboxes/ "9t. WebDriver – Handling radio buttons and checkboxes")
\ No newline at end of file
##### [9t。 WebDriver – 处理单选按钮和复选框](https://javabeginnerstutorial.com/selenium/9t-webdriver-handling-radio-buttons-checkboxes/ "9t. WebDriver – Handling radio buttons and checkboxes")
\ No newline at end of file
# 9 吨 WebDriver –处理单选按钮和复选框
# 9 吨 WebDriver – 处理单选按钮和复选框
> 原文: [https://javabeginnerstutorial.com/selenium/9t-webdriver-handling-radio-buttons-checkboxes/](https://javabeginnerstutorial.com/selenium/9t-webdriver-handling-radio-buttons-checkboxes/)
......@@ -46,7 +46,7 @@ driver.findElement(By.cssSelector("input[value='Magazines']"));
## 2\. **检查单选按钮/复选框是否显示**
使用 Selenium WebDriver,检查特定的单选按钮或复选框是否按预期显示在网页上是小菜一碟! 我们有 isDisplayed()方法来进行救援。 此方法返回一个布尔值(显示 **true** –元素,显示 **false** – element)。
使用 Selenium WebDriver,检查特定的单选按钮或复选框是否按预期显示在网页上是小菜一碟! 我们有 isDisplayed()方法来进行救援。 此方法返回一个布尔值(显示 **true** 元素,显示 **false** – element)。
***示例*** **让我们检查网页上是否显示了“ Tricycle”复选框。
......@@ -64,7 +64,7 @@ driver.findElement(By.name("vehicle2")).isDisplayed();
## 3\. **检查单选按钮/复选框是否已启用,以便可以选择它**
同样,为了验证是否启用了特定的单选按钮或复选框,我们有 isEnabled()方法。 这还会返回一个布尔值( **true**元素已启用, **false**元素已禁用)。
同样,为了验证是否启用了特定的单选按钮或复选框,我们有 isEnabled()方法。 这还会返回一个布尔值( **true** 元素已启用, **false**元素已禁用)。
***示例*** **让我们检查是否启用了“ Tricycle”复选框。 如果是的话,让我们检查一下,否则我们只会在控制台上打印一条消息。
......@@ -90,7 +90,7 @@ if (tricycleCheckbox.isEnabled()) {
## 4\. **检查默认情况下是否选中单选按钮/复选框**
为了验证默认情况下是否选中了特定的单选按钮或复选框,我们有 isSelected()方法。 这还会返回一个布尔值( **true**元素已选择, **false**未选择元素)。
为了验证默认情况下是否选中了特定的单选按钮或复选框,我们有 isSelected()方法。 这还会返回一个布尔值( **true** 元素已选择, **false**未选择元素)。
***示例*** **让我们检查一下默认情况下是否选中了“杂志”单选按钮。 如果是,请让我们将该消息打印到控制台,否则我们将单击它以选择“杂志”选项。
......@@ -340,4 +340,4 @@ System.out.println("AFTER: Is "+ list.get(i).getAttribute("value") + " selected?
###### 下一篇文章
##### [9u。 WebDriver –通过两种方式选择项目(下拉菜单和多项选择)](https://javabeginnerstutorial.com/selenium/9u-webdriver-select-items-two-ways/ "9u. WebDriver – Selecting items in two ways (Dropdowns and multiple selections)")
\ No newline at end of file
##### [9u。 WebDriver – 通过两种方式选择项目(下拉菜单和多项选择)](https://javabeginnerstutorial.com/selenium/9u-webdriver-select-items-two-ways/ "9u. WebDriver – Selecting items in two ways (Dropdowns and multiple selections)")
\ No newline at end of file
# 9u。 WebDriver –通过两种方式选择项目(下拉菜单和多项选择)
# 9u。 WebDriver – 通过两种方式选择项目(下拉菜单和多项选择)
> 原文: [https://javabeginnerstutorial.com/selenium/9u-webdriver-select-items-two-ways/](https://javabeginnerstutorial.com/selenium/9u-webdriver-select-items-two-ways/)
......@@ -330,4 +330,4 @@ public class SelectItems {
###### 下一篇文章
##### [9v。 WebDriver –以两种方式处理表格](https://javabeginnerstutorial.com/selenium/9v-webdriver-handling-tables-two-ways/ "9v. WebDriver – Handling tables in two ways")
\ No newline at end of file
##### [9v。 WebDriver – 以两种方式处理表格](https://javabeginnerstutorial.com/selenium/9v-webdriver-handling-tables-two-ways/ "9v. WebDriver – Handling tables in two ways")
\ No newline at end of file
# 9v。 WebDriver –以两种方式处理表
# 9v。 WebDriver – 以两种方式处理表
> 原文: [https://javabeginnerstutorial.com/selenium/9v-webdriver-handling-tables-two-ways/](https://javabeginnerstutorial.com/selenium/9v-webdriver-handling-tables-two-ways/)
......@@ -147,4 +147,4 @@ public class HandlingTables {
###### 下一篇文章
##### [9w。 WebDriver –遍历表元素](https://javabeginnerstutorial.com/selenium/9w-webdriver-looping-table-elements/ "9w. WebDriver – Looping through table elements")
\ No newline at end of file
##### [9w。 WebDriver – 遍历表元素](https://javabeginnerstutorial.com/selenium/9w-webdriver-looping-table-elements/ "9w. WebDriver – Looping through table elements")
\ No newline at end of file
# 9 周 WebDriver –遍历表元素
# 9 周 WebDriver – 遍历表元素
> 原文: [https://javabeginnerstutorial.com/selenium/9w-webdriver-looping-table-elements/](https://javabeginnerstutorial.com/selenium/9w-webdriver-looping-table-elements/)
......@@ -93,7 +93,7 @@ for(int j=0; j<colNum; j++){
您有能力集中精力下坡吗? 如果是,让我们看看 BrainBell!
***BrainBell –可视化!*** *我们大多数人都知道,为我们希望记住的概念创建心理图片比单词更清晰,更容易记住。 我们不知道或做的是仔细观察它几秒钟。 这将有助于轻松调用它。*
***BrainBell – 可视化!*** *我们大多数人都知道,为我们希望记住的概念创建心理图片比单词更清晰,更容易记住。 我们不知道或做的是仔细观察它几秒钟。 这将有助于轻松调用它。*
话虽如此,让我们看一下到目前为止讨论的整体情况!
......@@ -222,4 +222,4 @@ public class LoopingThroughTableElements {
###### 下一篇文章
##### [9 倍。 WebDriver –处理警报/弹出框](https://javabeginnerstutorial.com/selenium/9x-webdriver-handling-alerts-popup-box/ "9x. WebDriver – Handling alerts/pop-up boxes")
\ No newline at end of file
##### [9 倍。 WebDriver – 处理警报/弹出框](https://javabeginnerstutorial.com/selenium/9x-webdriver-handling-alerts-popup-box/ "9x. WebDriver – Handling alerts/pop-up boxes")
\ No newline at end of file
# 9 倍。 WebDriver –处理警报/弹出框
# 9 倍。 WebDriver – 处理警报/弹出框
> 原文: [https://javabeginnerstutorial.com/selenium/9x-webdriver-handling-alerts-popup-box/](https://javabeginnerstutorial.com/selenium/9x-webdriver-handling-alerts-popup-box/)
......@@ -30,4 +30,4 @@ window.confirm("Click 'OK' or 'Cancel'.");
![Confirm Box](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20473%20231'%3E%3C/svg%3E)
<noscript><img alt="Confirm Box" class="alignnone size-full wp-image-12511" height="231" src="img/eb42ced4a961c35a4e35d860b23ca096.png" width="473"/><h2><strong> 3.提示框</strong></h2><p>在我们希望用户输入值的情况下,将使用提示框。 与其他警报框类似,用户必须单击“确定”或“取消”按钮才能继续操作。 提示框在单击“确定”时返回输入值,而在单击“取消”时返回空值。</p><p><u> JavaScript 代码:</u> <span class="ezoic-adpicker-ad" id="ezoic-pub-ad-placeholder-124"> </span> <span class="ezoic-ad box-4 adtester-container adtester-container-124" data-ez-name="javabeginnerstutorial_com-box-4" style="display:block !important;float:none;margin-bottom:2px !important;margin-left:0px !important;margin-right:0px !important;margin-top:2px !important;min-height:110px;min-width:728px;text-align:center !important;"> <span class="ezoic-ad ezoic-adl" ezah="90" ezaw="728" id="div-gpt-ad-javabeginnerstutorial_com-box-4-0" style="position:relative;z-index:0;display:inline-block;min-height:90px;min-width:728px;"> </span> </span></p><pre><code class="language-javascript">window.prompt("Which Selenium Tool do you like the most?","e.g. Selenium IDE");</code></pre><p><img alt="Prompt Box" class="alignnone size-full wp-image-12508" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2017/08/PromptBox-1.jpg" height="231" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20478%20231'%3E%3C/svg%3E" width="478"/></p><noscript><img alt="Prompt Box" class="alignnone size-full wp-image-12508" height="231" src="img/f245ded24a74c295f8cd11219e80647a.png" width="478"/><p>希望您现在对基于 Web 的弹出窗口的不同类型有清楚的了解。</p><h2><strong>处理弹出框:</strong></h2><p>Selenium WebDriver 尚未提供任何处理这些弹出框的方法。 你相信我刚才说的吗?</p><p>哈! 我知道没有骗你的! WebDriver 总是对我们所有问题都有答案。 <strong>警报接口</strong>随<strong> org.openqa.selenium.Alert </strong> <em>包</em>一起提供!</p><p>经常使用的一些最有用的方法是:</p><h3>1\. WebDriver switchTo()</h3><p>这是用于从主窗口切换到弹出窗口或显示的警报的方法。</p><pre><code class="language-java">driver.switchTo().alert();</code></pre><h3>2.无效 accept()</h3><p>此方法用于接受警报。 点击“确定”按钮。</p><pre><code class="language-java">driver.switchTo().alert().accept();</code></pre><h3>3.无效 dismiss()</h3><p>此方法用于消除警报。 点击“取消”按钮。</p><pre><code class="language-java">driver.switchTo().alert().dismiss();</code></pre><h3>4.字符串 getText()</h3><p>要使文本显示在弹出框中,请使用此方法,它将文本作为字符串返回。</p><pre><code class="language-java">driver.switchTo().alert().getText();</code></pre><h3>5\. void sendKeys(String textToSend)</h3><p>此方法用于在显示的弹出框中(通常是提示框)输入特定的 String。</p><pre><code class="language-java">driver.switchTo().alert().sendKeys(“sampleText”);</code></pre><h2><strong> <u>场景</u> </strong></h2><p>让我们来看一个实现这些方法的测试用例,以更深入地了解这些概念,</p><ol><li>打开 Firefox 浏览器</li><li>导航到<a href="https://chandanachaitanya.github.io/selenium-practice-site/">演示站点</a></li><li>使用 ID 找到“警告框”按钮</li><li>单击按钮以弹出警报框</li><li>获取警报弹出窗口的显示文本并将其打印到控制台</li><li>接受警报弹出窗口</li><li>使用 ID 找到“确认框”按钮</li><li>单击按钮以确认框弹出</li><li>将警报消息打印到控制台</li><li>关闭确认弹出窗口</li><li>使用 XPath 找到“提示框”按钮</li><li>单击按钮,弹出提示框</li><li>获取提示框消息并将其显示到控制台</li><li>接受 promt 弹出窗口</li><li>验证 Eclipse IDE 控制台输出屏幕和 JUnit 窗格是否成功</li></ol><p>此方案的 JUnit 代码是,</p><pre><code class="language-java">package com.blog.junitTests; import java.util.concurrent.TimeUnit; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.openqa.selenium.Alert; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; public class PopupBoxes { // Declaring variables private WebDriver driver; private String baseUrl; @Before public void setUp() throws Exception { // Selenium version 3 beta releases require system property set up System.setProperty("webdriver.gecko.driver", "E:\\Softwares\\" + "Selenium\\geckodriver-v0.10.0-win64\\geckodriver.exe"); // Create a new instance for the class FirefoxDriver // that implements WebDriver interface driver = new FirefoxDriver(); // Implicit wait for 5 seconds driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); // Assign the URL to be invoked to a String variable baseUrl = "https://chandanachaitanya.github.io/selenium-practice-site/"; } @Test public void testPageTitle() throws Exception { // Open baseUrl in Firefox browser window driver.get(baseUrl); // Locate 'Alert Box' button using id WebElement alertBoxBtn = driver.findElement(By.id("alertBox")); // Click the button for alert box popup alertBoxBtn.click(); // Switch the control to 'Alert Box' popup Alert alertPopUp = driver.switchTo().alert(); // Print the alert message to console System.out.println("Alert Box message: " + alertPopUp.getText()); // Accept the alert popup alertPopUp.accept(); Thread.sleep(5000); // Locate 'Confirm Box' button using id WebElement confirmBoxBtn = driver.findElement(By.id("confirmBox")); // Click the button for confirm box popup confirmBoxBtn.click(); // Switch control to 'Confirm Box' popup Alert confirmPopUp = driver.switchTo().alert(); // Dismiss the popup confirmPopUp.dismiss(); System.out.println("Confirm box popup dismissed!"); Thread.sleep(5000); // Locate 'Prompt Box' button using XPath WebElement promptBoxBtn = driver.findElement(By.xpath("/html/body/form/div[4]/div[3]/button")); // Click the button for prompt box popup promptBoxBtn.click(); // Switch control to 'Prompt Box' popup Alert promptPopUp = driver.switchTo().alert(); // Display the prompt message to console System.out.println(promptPopUp.getText()); // Click 'OK' promptPopUp.accept(); } //End of @Test @After public void tearDown() throws Exception { // Close the Firefox browser driver.close(); } }</code></pre><p><em>代码说明:</em></p><ol><li>为了实例化一个弹出框,我们将必须导入“ <strong> import </strong> openqa.selenium.Alert package”。</li></ol><p>键入上述代码后,“ Alert”一词下方会出现一条弯曲的线。 悬停时,蚀将建议所有可能的快速修复。 单击建议导入“警报”软件包的第一个修补程序。</p><p><img alt="Import alert package" class="alignnone size-full wp-image-12510" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2017/08/AlertImport-1.jpg" height="197" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20393%20197'%3E%3C/svg%3E" width="393"/></p><noscript><img alt="Import alert package" class="alignnone size-full wp-image-12510" height="197" src="img/8c7bdadd655552e5973edd3979ae7a74.png" width="393"/><pre><code class="language-java">// Switch the control to 'Alert Box' popup Alert alertPopUp = driver.switchTo().alert();</code></pre><p>该软件包指定了 Alert 界面,该界面用于处理基于 Web 的弹出框。</p><p>“ alertPopUp”是为引用显示的弹出窗口而创建的新实例变量。</p><p>2.要将控件从主窗口切换到弹出窗口,</p><pre><code class="language-java">driver.switchTo().alert();</code></pre><p>3.要使文本显示在弹出框中,请在引用所生成警报的实例变量上使用 getText()方法。</p><pre><code class="language-java">// Print the alert message to console System.out.println("Alert Box message: " + alertPopUp.getText());</code></pre><p>4.要接受警报,请使用 accept()方法。</p><pre><code class="language-java">// Accept the alert popup alertPopUp.accept();</code></pre><p>5.要关闭警报,请使用 dismiss()方法。</p><pre><code class="language-java">// Dismiss the popup confirmPopUp.dismiss();</code></pre><p><em>执行结果:</em></p><p>在 JUnit 窗口中,绿色条显示测试用例已成功执行。 控制台窗口显示没有任何错误。 它还按预期显示所有打印的消息。</p><p><img alt="Alert Eclipse output" class="alignnone size-full wp-image-12507" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2017/08/EclipseOutput-1.jpg" height="342" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20677%20342'%3E%3C/svg%3E" width="677"/></p><noscript><img alt="Alert Eclipse output" class="alignnone size-full wp-image-12507" height="342" src="img/5f21cb9c556c1522fd9bcdb900117ab4.png" width="677"/><p>是时候练习了,我很快会在另一篇文章中见。 祝你有美好的一天!</p><p> </p><p> </p><div class="sticky-nav" style="font-size: 15px;"><div class="sticky-nav-image"></div><div class="sticky-nav-holder"><div class="sticky-nav_item"><h6 class="heading-sm">下一篇文章</h6></div><h5 class="sticky-nav_heading " style="font-size: 15px;"><a href="https://javabeginnerstutorial.com/selenium/9y-webdriver-handling-multiple-windows/" title="9y. WebDriver – Handling multiple windows"> 9 岁。 WebDriver –处理多个窗口</a></h5></div></div> </body> </html></noscript>
\ No newline at end of file
<noscript><img alt="Confirm Box" class="alignnone size-full wp-image-12511" height="231" src="img/eb42ced4a961c35a4e35d860b23ca096.png" width="473"/><h2><strong> 3.提示框</strong></h2><p>在我们希望用户输入值的情况下,将使用提示框。 与其他警报框类似,用户必须单击“确定”或“取消”按钮才能继续操作。 提示框在单击“确定”时返回输入值,而在单击“取消”时返回空值。</p><p><u> JavaScript 代码:</u> <span class="ezoic-adpicker-ad" id="ezoic-pub-ad-placeholder-124"> </span> <span class="ezoic-ad box-4 adtester-container adtester-container-124" data-ez-name="javabeginnerstutorial_com-box-4" style="display:block !important;float:none;margin-bottom:2px !important;margin-left:0px !important;margin-right:0px !important;margin-top:2px !important;min-height:110px;min-width:728px;text-align:center !important;"> <span class="ezoic-ad ezoic-adl" ezah="90" ezaw="728" id="div-gpt-ad-javabeginnerstutorial_com-box-4-0" style="position:relative;z-index:0;display:inline-block;min-height:90px;min-width:728px;"> </span> </span></p><pre><code class="language-javascript">window.prompt("Which Selenium Tool do you like the most?","e.g. Selenium IDE");</code></pre><p><img alt="Prompt Box" class="alignnone size-full wp-image-12508" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2017/08/PromptBox-1.jpg" height="231" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20478%20231'%3E%3C/svg%3E" width="478"/></p><noscript><img alt="Prompt Box" class="alignnone size-full wp-image-12508" height="231" src="img/f245ded24a74c295f8cd11219e80647a.png" width="478"/><p>希望您现在对基于 Web 的弹出窗口的不同类型有清楚的了解。</p><h2><strong>处理弹出框:</strong></h2><p>Selenium WebDriver 尚未提供任何处理这些弹出框的方法。 你相信我刚才说的吗?</p><p>哈! 我知道没有骗你的! WebDriver 总是对我们所有问题都有答案。 <strong>警报接口</strong>随<strong> org.openqa.selenium.Alert </strong> <em>包</em>一起提供!</p><p>经常使用的一些最有用的方法是:</p><h3>1\. WebDriver switchTo()</h3><p>这是用于从主窗口切换到弹出窗口或显示的警报的方法。</p><pre><code class="language-java">driver.switchTo().alert();</code></pre><h3>2.无效 accept()</h3><p>此方法用于接受警报。 点击“确定”按钮。</p><pre><code class="language-java">driver.switchTo().alert().accept();</code></pre><h3>3.无效 dismiss()</h3><p>此方法用于消除警报。 点击“取消”按钮。</p><pre><code class="language-java">driver.switchTo().alert().dismiss();</code></pre><h3>4.字符串 getText()</h3><p>要使文本显示在弹出框中,请使用此方法,它将文本作为字符串返回。</p><pre><code class="language-java">driver.switchTo().alert().getText();</code></pre><h3>5\. void sendKeys(String textToSend)</h3><p>此方法用于在显示的弹出框中(通常是提示框)输入特定的 String。</p><pre><code class="language-java">driver.switchTo().alert().sendKeys(“sampleText”);</code></pre><h2><strong> <u>场景</u> </strong></h2><p>让我们来看一个实现这些方法的测试用例,以更深入地了解这些概念,</p><ol><li>打开 Firefox 浏览器</li><li>导航到<a href="https://chandanachaitanya.github.io/selenium-practice-site/">演示站点</a></li><li>使用 ID 找到“警告框”按钮</li><li>单击按钮以弹出警报框</li><li>获取警报弹出窗口的显示文本并将其打印到控制台</li><li>接受警报弹出窗口</li><li>使用 ID 找到“确认框”按钮</li><li>单击按钮以确认框弹出</li><li>将警报消息打印到控制台</li><li>关闭确认弹出窗口</li><li>使用 XPath 找到“提示框”按钮</li><li>单击按钮,弹出提示框</li><li>获取提示框消息并将其显示到控制台</li><li>接受 promt 弹出窗口</li><li>验证 Eclipse IDE 控制台输出屏幕和 JUnit 窗格是否成功</li></ol><p>此方案的 JUnit 代码是,</p><pre><code class="language-java">package com.blog.junitTests; import java.util.concurrent.TimeUnit; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.openqa.selenium.Alert; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; public class PopupBoxes { // Declaring variables private WebDriver driver; private String baseUrl; @Before public void setUp() throws Exception { // Selenium version 3 beta releases require system property set up System.setProperty("webdriver.gecko.driver", "E:\\Softwares\\" + "Selenium\\geckodriver-v0.10.0-win64\\geckodriver.exe"); // Create a new instance for the class FirefoxDriver // that implements WebDriver interface driver = new FirefoxDriver(); // Implicit wait for 5 seconds driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); // Assign the URL to be invoked to a String variable baseUrl = "https://chandanachaitanya.github.io/selenium-practice-site/"; } @Test public void testPageTitle() throws Exception { // Open baseUrl in Firefox browser window driver.get(baseUrl); // Locate 'Alert Box' button using id WebElement alertBoxBtn = driver.findElement(By.id("alertBox")); // Click the button for alert box popup alertBoxBtn.click(); // Switch the control to 'Alert Box' popup Alert alertPopUp = driver.switchTo().alert(); // Print the alert message to console System.out.println("Alert Box message: " + alertPopUp.getText()); // Accept the alert popup alertPopUp.accept(); Thread.sleep(5000); // Locate 'Confirm Box' button using id WebElement confirmBoxBtn = driver.findElement(By.id("confirmBox")); // Click the button for confirm box popup confirmBoxBtn.click(); // Switch control to 'Confirm Box' popup Alert confirmPopUp = driver.switchTo().alert(); // Dismiss the popup confirmPopUp.dismiss(); System.out.println("Confirm box popup dismissed!"); Thread.sleep(5000); // Locate 'Prompt Box' button using XPath WebElement promptBoxBtn = driver.findElement(By.xpath("/html/body/form/div[4]/div[3]/button")); // Click the button for prompt box popup promptBoxBtn.click(); // Switch control to 'Prompt Box' popup Alert promptPopUp = driver.switchTo().alert(); // Display the prompt message to console System.out.println(promptPopUp.getText()); // Click 'OK' promptPopUp.accept(); } //End of @Test @After public void tearDown() throws Exception { // Close the Firefox browser driver.close(); } }</code></pre><p><em>代码说明:</em></p><ol><li>为了实例化一个弹出框,我们将必须导入“ <strong> import </strong> openqa.selenium.Alert package”。</li></ol><p>键入上述代码后,“ Alert”一词下方会出现一条弯曲的线。 悬停时,蚀将建议所有可能的快速修复。 单击建议导入“警报”软件包的第一个修补程序。</p><p><img alt="Import alert package" class="alignnone size-full wp-image-12510" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2017/08/AlertImport-1.jpg" height="197" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20393%20197'%3E%3C/svg%3E" width="393"/></p><noscript><img alt="Import alert package" class="alignnone size-full wp-image-12510" height="197" src="img/8c7bdadd655552e5973edd3979ae7a74.png" width="393"/><pre><code class="language-java">// Switch the control to 'Alert Box' popup Alert alertPopUp = driver.switchTo().alert();</code></pre><p>该软件包指定了 Alert 界面,该界面用于处理基于 Web 的弹出框。</p><p>“ alertPopUp”是为引用显示的弹出窗口而创建的新实例变量。</p><p>2.要将控件从主窗口切换到弹出窗口,</p><pre><code class="language-java">driver.switchTo().alert();</code></pre><p>3.要使文本显示在弹出框中,请在引用所生成警报的实例变量上使用 getText()方法。</p><pre><code class="language-java">// Print the alert message to console System.out.println("Alert Box message: " + alertPopUp.getText());</code></pre><p>4.要接受警报,请使用 accept()方法。</p><pre><code class="language-java">// Accept the alert popup alertPopUp.accept();</code></pre><p>5.要关闭警报,请使用 dismiss()方法。</p><pre><code class="language-java">// Dismiss the popup confirmPopUp.dismiss();</code></pre><p><em>执行结果:</em></p><p>在 JUnit 窗口中,绿色条显示测试用例已成功执行。 控制台窗口显示没有任何错误。 它还按预期显示所有打印的消息。</p><p><img alt="Alert Eclipse output" class="alignnone size-full wp-image-12507" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2017/08/EclipseOutput-1.jpg" height="342" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20677%20342'%3E%3C/svg%3E" width="677"/></p><noscript><img alt="Alert Eclipse output" class="alignnone size-full wp-image-12507" height="342" src="img/5f21cb9c556c1522fd9bcdb900117ab4.png" width="677"/><p>是时候练习了,我很快会在另一篇文章中见。 祝你有美好的一天!</p><p> </p><p> </p><div class="sticky-nav" style="font-size: 15px;"><div class="sticky-nav-image"></div><div class="sticky-nav-holder"><div class="sticky-nav_item"><h6 class="heading-sm">下一篇文章</h6></div><h5 class="sticky-nav_heading " style="font-size: 15px;"><a href="https://javabeginnerstutorial.com/selenium/9y-webdriver-handling-multiple-windows/" title="9y. WebDriver – Handling multiple windows"> 9 岁。 WebDriver – 处理多个窗口</a></h5></div></div> </body> </html></noscript>
\ No newline at end of file
# 9 岁 WebDriver –处理多个窗口
# 9 岁 WebDriver – 处理多个窗口
> 原文: [https://javabeginnerstutorial.com/selenium/9y-webdriver-handling-multiple-windows/](https://javabeginnerstutorial.com/selenium/9y-webdriver-handling-multiple-windows/)
......@@ -130,4 +130,4 @@ driver.getTitle());
![multiple windows eclipse output](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20819%20391'%3E%3C/svg%3E)
<noscript><img alt="multiple windows eclipse output" class="alignnone size-full wp-image-12533" height="391" src="img/bbdef2f2920307b3b20ab96a9a969b78.png" width="819"/><p>有了这个,我很快就会在另一篇文章中见。 祝你有美好的一天!</p><div class="sticky-nav" style="font-size: 15px;"><div class="sticky-nav-image"></div><div class="sticky-nav-holder"><div class="sticky-nav_item"><h6 class="heading-sm">下一篇文章</h6></div><h5 class="sticky-nav_heading " style="font-size: 15px;"><a href="https://javabeginnerstutorial.com/selenium/9z-webdriver-window-maximize/" title="9z. WebDriver – Window maximize"> 9z。 WebDriver –最大化窗口</a></h5></div></div> </body> </html></noscript>
\ No newline at end of file
<noscript><img alt="multiple windows eclipse output" class="alignnone size-full wp-image-12533" height="391" src="img/bbdef2f2920307b3b20ab96a9a969b78.png" width="819"/><p>有了这个,我很快就会在另一篇文章中见。 祝你有美好的一天!</p><div class="sticky-nav" style="font-size: 15px;"><div class="sticky-nav-image"></div><div class="sticky-nav-holder"><div class="sticky-nav_item"><h6 class="heading-sm">下一篇文章</h6></div><h5 class="sticky-nav_heading " style="font-size: 15px;"><a href="https://javabeginnerstutorial.com/selenium/9z-webdriver-window-maximize/" title="9z. WebDriver – Window maximize"> 9z。 WebDriver – 最大化窗口</a></h5></div></div> </body> </html></noscript>
\ No newline at end of file
# 9z。 WebDriver –最大化窗口
# 9z。 WebDriver – 最大化窗口
> 原文: [https://javabeginnerstutorial.com/selenium/9z-webdriver-window-maximize/](https://javabeginnerstutorial.com/selenium/9z-webdriver-window-maximize/)
......@@ -101,4 +101,4 @@ public class WindowMaximize {
![](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20819%20391'%3E%3C/svg%3E)
<noscript><img alt="" class="alignnone size-full wp-image-12549" height="391" src="img/8747d9f868b65e6dad7be604914dd691.png" width="819"/><p>如有任何疑问,请不要在评论部分大喊大叫!</p><p>我很快会在另一篇文章中再见。 祝你有美好的一天!</p><div class="sticky-nav" style="font-size: 15px;"><div class="sticky-nav-image"></div><div class="sticky-nav-holder"><div class="sticky-nav_item"><h6 class="heading-sm">下一篇文章</h6></div><h5 class="sticky-nav_heading " style="font-size: 15px;"><a href="https://javabeginnerstutorial.com/selenium/9aa-webdriver-executing-javascript-code/" title="9aa. WebDriver – Executing JavaScript code"> 9aa。 WebDriver –执行 JavaScript 代码</a></h5></div></div> </body> </html></noscript>
\ No newline at end of file
<noscript><img alt="" class="alignnone size-full wp-image-12549" height="391" src="img/8747d9f868b65e6dad7be604914dd691.png" width="819"/><p>如有任何疑问,请不要在评论部分大喊大叫!</p><p>我很快会在另一篇文章中再见。 祝你有美好的一天!</p><div class="sticky-nav" style="font-size: 15px;"><div class="sticky-nav-image"></div><div class="sticky-nav-holder"><div class="sticky-nav_item"><h6 class="heading-sm">下一篇文章</h6></div><h5 class="sticky-nav_heading " style="font-size: 15px;"><a href="https://javabeginnerstutorial.com/selenium/9aa-webdriver-executing-javascript-code/" title="9aa. WebDriver – Executing JavaScript code"> 9aa。 WebDriver – 执行 JavaScript 代码</a></h5></div></div> </body> </html></noscript>
\ No newline at end of file
# 9aa。 WebDriver –执行 JavaScript 代码
# 9aa。 WebDriver – 执行 JavaScript 代码
> 原文: [https://javabeginnerstutorial.com/selenium/9aa-webdriver-executing-javascript-code/](https://javabeginnerstutorial.com/selenium/9aa-webdriver-executing-javascript-code/)
......@@ -6,4 +6,4 @@
![Executing JavaScript in browser](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20791%20669'%3E%3C/svg%3E)
<noscript><img alt="Executing JavaScript in browser" class="alignnone size-full wp-image-13955" height="669" src="img/bc2efaf567c829cdf5dbeb4e67e88112.png" width="791"/><p>除此之外,在其他情况下,我们可能找不到合适的 Selenium API 来执行特定操作。 但是我们可以通过执行 JavaScript 代码来执行该操作。 Selenium WebDriver 提供了一个界面,可以帮助我们做到这一点!</p><p><strong> JavascriptExecutor </strong>…您听说过,就像那些名人一样。 好吧,现在是我们该去见那颗璀璨的星星的时候了。 JavascriptExecutor 不需要添加任何外部 JAR 文件或插件。 只需导入一个包即可完成工作,“导入<strong> org.openqa.selenium.JavascriptExecutor” </strong>。 它有两种重要的方法可以执行我们的 Selenium 测试中的 JavaScript 代码,以自动化测试中的应用程序,即</p><ul><li><strong> executeScript </strong>(脚本,参数)</li><li><strong> executeAsyncScript </strong>(脚本,参数)</li></ul><p><img alt="JavascriptExecutor methods" class="alignnone size-full wp-image-13956" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2018/09/2_JS-Executor-methods-1.jpg" height="130" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20511%20130'%3E%3C/svg%3E" width="511"/></p><noscript><img alt="JavascriptExecutor methods" class="alignnone size-full wp-image-13956" height="130" src="img/a2b574fd1517d1155515eab84c2019a6.png" width="511"/><p>让我们通过几个简单的步骤来理解这一点。</p><h2><strong>步骤 1:</strong></h2><p>导入以下软件包,<code data-enlighter-language="java">import org.openqa.selenium.JavascriptExecutor;</code></p><p>创建一个 JavascriptExecutor 对象,并通过将其类型转换为 JavascriptExecutor 来分配驱动程序对象。</p><pre><code class="language-java">// Typecast driver to JavascriptExecutor JavascriptExecutor jsExecutor = (JavascriptExecutor)driver;</code></pre><h2><strong>步骤 2:</strong></h2><p>这样创建的 JavascriptExecutor 对象允许我们从 Selenium 测试中执行 JavaScript 代码。</p><pre><code class="language-java">// Scroll down by 100 pixels jsExecutor.executeScript("window.scrollBy(0,100)");</code></pre><p><span class="ezoic-adpicker-ad" id="ezoic-pub-ad-placeholder-124"> </span> <span class="ezoic-ad box-4 adtester-container adtester-container-124" data-ez-name="javabeginnerstutorial_com-box-4" style="display:block !important;float:none;margin-bottom:2px !important;margin-left:0px !important;margin-right:0px !important;margin-top:2px !important;min-height:110px;min-width:728px;text-align:center !important;"> <span class="ezoic-ad ezoic-adl" ezah="90" ezaw="728" id="div-gpt-ad-javabeginnerstutorial_com-box-4-0" style="position:relative;z-index:0;display:inline-block;min-height:90px;min-width:728px;"> </span> </span>此“ excuteScript”方法采用两个参数。 第一个是 JavaScript 代码,第二个是 Java 脚本代码所需的可选参数列表。</p><h2><strong> <u>总体图片</u> </strong></h2><p>让我们看一个测试案例,实现到目前为止所介绍的技术,</p><h3><em>场景</em></h3><ol><li>打开 Firefox 浏览器</li><li>导航到演示站点(<a href="https://chandanachaitanya.github.io/selenium-practice-site/"> https://chandanachaitanya.github.io/selenium-practice-site/ </a>)</li><li>使用和不使用 JavaScript 代码打印页面 URL 进行控制台</li><li>垂直向下滚动页面 100 像素</li><li>刷新页面</li><li>导航到 Google 主页</li><li>使用 JavaScript 代码执行上述三个操作</li><li>验证 Eclipse IDE 控制台输出屏幕和 JUnit 窗格是否成功</li></ol><p>此方案的 JUnit 代码是,</p><pre><code class="language-java">import java.util.concurrent.TimeUnit; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; public class JavaScriptExecutorTest { // Declaring variables private WebDriver driver; private String baseUrl; @Before public void setUp() throws Exception { // Selenium version 3 beta releases require system property set up System.setProperty("webdriver.gecko.driver", "E:\\Softwares\\" + "Selenium\\geckodriver-v0.10.0-win64\\geckodriver.exe"); // Create a new instance for the class FirefoxDriver // that implements WebDriver interface driver = new FirefoxDriver();53 // Implicit wait for 5 seconds driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); // Assign the URL to be invoked to a String variable baseUrl = "https://chandanachaitanya.github.io/selenium-practice-site/"; } @Test public void testPageTitle() throws Exception { // Open baseUrl in Firefox browser window driver.get(baseUrl); Thread.sleep(5000); // Typecast driver to JavascriptExecutor JavascriptExecutor jsExecutor = (JavascriptExecutor)driver; // Execute JavaScript code and assign it to a String String pageURL = (String)jsExecutor.executeScript("return document.URL;"); // Print the URL to the console System.out.println("URL : " + pageURL); // Print the URL without JavaScript to the console System.out.println("URL without JavascriptExecutor: " + driver.getCurrentUrl()); // Scroll down by 100 pixels jsExecutor.executeScript("window.scrollBy(0,100)"); // Refresh the page jsExecutor.executeScript("history.go(0)"); // Navigating to a different page jsExecutor.executeScript("window.location = 'https://www.google.com/';"); } // End of @Test @After public void tearDown() throws Exception { // Close the Firefox browser driver.close(); } }</code></pre><h3><em>执行结果:</em></h3><p>为每行代码提供了注释,使其易于说明。</p><p>在 JUnit 窗格中,绿色条显示测试用例已成功执行。 控制台窗口显示没有任何错误。 它还按预期显示所有打印的消息。</p><p><img alt="Eclipse IDE console output" class="alignnone size-full wp-image-13954" data-lazy-sizes="(max-width: 813px) 100vw, 813px" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2018/09/3_Console-output.jpg" data-lazy-srcset="https://javabeginnerstutorial.com/wp-content/uploads/2018/09/3_Console-output.jpg 813w, https://javabeginnerstutorial.com/wp-content/uploads/2018/09/3_Console-output-300x96.jpg 300w, https://javabeginnerstutorial.com/wp-content/uploads/2018/09/3_Console-output-768x245.jpg 768w" height="259" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20813%20259'%3E%3C/svg%3E" width="813"/></p><noscript><img alt="Eclipse IDE console output" class="alignnone size-full wp-image-13954" height="259" sizes="(max-width: 813px) 100vw, 813px" src="img/9197339b0edc0ae7320e695f9f25a475.png" srcset="https://javabeginnerstutorial.com/wp-content/uploads/2018/09/3_Console-output.jpg 813w, https://javabeginnerstutorial.com/wp-content/uploads/2018/09/3_Console-output-300x96.jpg 300w, https://javabeginnerstutorial.com/wp-content/uploads/2018/09/3_Console-output-768x245.jpg 768w" width="813"/><p>是时候尝试今天的技能了。 是的,戴上安全帽,以免遇到任何异常!</p><p>所有代码文件都放置在<a href="https://github.com/JBTAdmin/Selenium"> GitHub 存储库</a>中,以方便访问。 您可以为存储库加注星标和分支以方便使用。 请仔细阅读“ README.md”文件以获取明确说明。</p><p>祝你有美好的一天!</p><p> </p><div class="sticky-nav" style="font-size: 15px;"><div class="sticky-nav-image"></div><div class="sticky-nav-holder"><div class="sticky-nav_item"><h6 class="heading-sm">下一篇文章</h6></div><h5 class="sticky-nav_heading " style="font-size: 15px;"><a href="https://javabeginnerstutorial.com/selenium/9bb-webdriver-actions-class/" title="9ab. WebDriver – Using Actions Class"> 9ab。 WebDriver –使用动作类</a></h5></div></div> </body> </html></noscript>
\ No newline at end of file
<noscript><img alt="Executing JavaScript in browser" class="alignnone size-full wp-image-13955" height="669" src="img/bc2efaf567c829cdf5dbeb4e67e88112.png" width="791"/><p>除此之外,在其他情况下,我们可能找不到合适的 Selenium API 来执行特定操作。 但是我们可以通过执行 JavaScript 代码来执行该操作。 Selenium WebDriver 提供了一个界面,可以帮助我们做到这一点!</p><p><strong> JavascriptExecutor </strong>…您听说过,就像那些名人一样。 好吧,现在是我们该去见那颗璀璨的星星的时候了。 JavascriptExecutor 不需要添加任何外部 JAR 文件或插件。 只需导入一个包即可完成工作,“导入<strong> org.openqa.selenium.JavascriptExecutor” </strong>。 它有两种重要的方法可以执行我们的 Selenium 测试中的 JavaScript 代码,以自动化测试中的应用程序,即</p><ul><li><strong> executeScript </strong>(脚本,参数)</li><li><strong> executeAsyncScript </strong>(脚本,参数)</li></ul><p><img alt="JavascriptExecutor methods" class="alignnone size-full wp-image-13956" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2018/09/2_JS-Executor-methods-1.jpg" height="130" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20511%20130'%3E%3C/svg%3E" width="511"/></p><noscript><img alt="JavascriptExecutor methods" class="alignnone size-full wp-image-13956" height="130" src="img/a2b574fd1517d1155515eab84c2019a6.png" width="511"/><p>让我们通过几个简单的步骤来理解这一点。</p><h2><strong>步骤 1:</strong></h2><p>导入以下软件包,<code data-enlighter-language="java">import org.openqa.selenium.JavascriptExecutor;</code></p><p>创建一个 JavascriptExecutor 对象,并通过将其类型转换为 JavascriptExecutor 来分配驱动程序对象。</p><pre><code class="language-java">// Typecast driver to JavascriptExecutor JavascriptExecutor jsExecutor = (JavascriptExecutor)driver;</code></pre><h2><strong>步骤 2:</strong></h2><p>这样创建的 JavascriptExecutor 对象允许我们从 Selenium 测试中执行 JavaScript 代码。</p><pre><code class="language-java">// Scroll down by 100 pixels jsExecutor.executeScript("window.scrollBy(0,100)");</code></pre><p><span class="ezoic-adpicker-ad" id="ezoic-pub-ad-placeholder-124"> </span> <span class="ezoic-ad box-4 adtester-container adtester-container-124" data-ez-name="javabeginnerstutorial_com-box-4" style="display:block !important;float:none;margin-bottom:2px !important;margin-left:0px !important;margin-right:0px !important;margin-top:2px !important;min-height:110px;min-width:728px;text-align:center !important;"> <span class="ezoic-ad ezoic-adl" ezah="90" ezaw="728" id="div-gpt-ad-javabeginnerstutorial_com-box-4-0" style="position:relative;z-index:0;display:inline-block;min-height:90px;min-width:728px;"> </span> </span>此“ excuteScript”方法采用两个参数。 第一个是 JavaScript 代码,第二个是 Java 脚本代码所需的可选参数列表。</p><h2><strong> <u>总体图片</u> </strong></h2><p>让我们看一个测试案例,实现到目前为止所介绍的技术,</p><h3><em>场景</em></h3><ol><li>打开 Firefox 浏览器</li><li>导航到演示站点(<a href="https://chandanachaitanya.github.io/selenium-practice-site/"> https://chandanachaitanya.github.io/selenium-practice-site/ </a>)</li><li>使用和不使用 JavaScript 代码打印页面 URL 进行控制台</li><li>垂直向下滚动页面 100 像素</li><li>刷新页面</li><li>导航到 Google 主页</li><li>使用 JavaScript 代码执行上述三个操作</li><li>验证 Eclipse IDE 控制台输出屏幕和 JUnit 窗格是否成功</li></ol><p>此方案的 JUnit 代码是,</p><pre><code class="language-java">import java.util.concurrent.TimeUnit; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; public class JavaScriptExecutorTest { // Declaring variables private WebDriver driver; private String baseUrl; @Before public void setUp() throws Exception { // Selenium version 3 beta releases require system property set up System.setProperty("webdriver.gecko.driver", "E:\\Softwares\\" + "Selenium\\geckodriver-v0.10.0-win64\\geckodriver.exe"); // Create a new instance for the class FirefoxDriver // that implements WebDriver interface driver = new FirefoxDriver();53 // Implicit wait for 5 seconds driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); // Assign the URL to be invoked to a String variable baseUrl = "https://chandanachaitanya.github.io/selenium-practice-site/"; } @Test public void testPageTitle() throws Exception { // Open baseUrl in Firefox browser window driver.get(baseUrl); Thread.sleep(5000); // Typecast driver to JavascriptExecutor JavascriptExecutor jsExecutor = (JavascriptExecutor)driver; // Execute JavaScript code and assign it to a String String pageURL = (String)jsExecutor.executeScript("return document.URL;"); // Print the URL to the console System.out.println("URL : " + pageURL); // Print the URL without JavaScript to the console System.out.println("URL without JavascriptExecutor: " + driver.getCurrentUrl()); // Scroll down by 100 pixels jsExecutor.executeScript("window.scrollBy(0,100)"); // Refresh the page jsExecutor.executeScript("history.go(0)"); // Navigating to a different page jsExecutor.executeScript("window.location = 'https://www.google.com/';"); } // End of @Test @After public void tearDown() throws Exception { // Close the Firefox browser driver.close(); } }</code></pre><h3><em>执行结果:</em></h3><p>为每行代码提供了注释,使其易于说明。</p><p>在 JUnit 窗格中,绿色条显示测试用例已成功执行。 控制台窗口显示没有任何错误。 它还按预期显示所有打印的消息。</p><p><img alt="Eclipse IDE console output" class="alignnone size-full wp-image-13954" data-lazy-sizes="(max-width: 813px) 100vw, 813px" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2018/09/3_Console-output.jpg" data-lazy-srcset="https://javabeginnerstutorial.com/wp-content/uploads/2018/09/3_Console-output.jpg 813w, https://javabeginnerstutorial.com/wp-content/uploads/2018/09/3_Console-output-300x96.jpg 300w, https://javabeginnerstutorial.com/wp-content/uploads/2018/09/3_Console-output-768x245.jpg 768w" height="259" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20813%20259'%3E%3C/svg%3E" width="813"/></p><noscript><img alt="Eclipse IDE console output" class="alignnone size-full wp-image-13954" height="259" sizes="(max-width: 813px) 100vw, 813px" src="img/9197339b0edc0ae7320e695f9f25a475.png" srcset="https://javabeginnerstutorial.com/wp-content/uploads/2018/09/3_Console-output.jpg 813w, https://javabeginnerstutorial.com/wp-content/uploads/2018/09/3_Console-output-300x96.jpg 300w, https://javabeginnerstutorial.com/wp-content/uploads/2018/09/3_Console-output-768x245.jpg 768w" width="813"/><p>是时候尝试今天的技能了。 是的,戴上安全帽,以免遇到任何异常!</p><p>所有代码文件都放置在<a href="https://github.com/JBTAdmin/Selenium"> GitHub 存储库</a>中,以方便访问。 您可以为存储库加注星标和分支以方便使用。 请仔细阅读“ README.md”文件以获取明确说明。</p><p>祝你有美好的一天!</p><p> </p><div class="sticky-nav" style="font-size: 15px;"><div class="sticky-nav-image"></div><div class="sticky-nav-holder"><div class="sticky-nav_item"><h6 class="heading-sm">下一篇文章</h6></div><h5 class="sticky-nav_heading " style="font-size: 15px;"><a href="https://javabeginnerstutorial.com/selenium/9bb-webdriver-actions-class/" title="9ab. WebDriver – Using Actions Class"> 9ab。 WebDriver – 使用动作类</a></h5></div></div> </body> </html></noscript>
\ No newline at end of file
# 9ab。 WebDriver –使用动作类
# 9ab。 WebDriver – 使用动作类
> 原文: [https://javabeginnerstutorial.com/selenium/9bb-webdriver-actions-class/](https://javabeginnerstutorial.com/selenium/9bb-webdriver-actions-class/)
......@@ -8,7 +8,7 @@
### 1.单击(WebElement 目标)
参数:*目标* –要单击的元素。
参数:*目标* 要单击的元素。
说明:单击给定目标的中间。
......@@ -26,9 +26,9 @@ Parameter: *target* – element to click.
参数:
*来源* –要拖动的元素,即模拟按钮按下的位置
*来源* 要拖动的元素,即模拟按钮按下的位置
*目标* –在以下位置移动并释放鼠标的元素
*目标* 在以下位置移动并释放鼠标的元素
说明:在源元素的位置单击并按住,移至目标元素的位置,然后释放鼠标。
......@@ -36,7 +36,7 @@ Parameter: *target* – element to click.
Parameters:
*源* –模拟按钮按下的元素。
*源* 模拟按钮按下的元素。
*xOffset* -水平移动偏移。
......@@ -236,4 +236,4 @@ actions
![Actions output 1](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20727%20338'%3E%3C/svg%3E)
<noscript><img alt="Actions output 1" class="alignnone size-full wp-image-14169" height="338" sizes="(max-width: 727px) 100vw, 727px" src="img/a68025a724b5fa9a039ffea6277c6cec.png" srcset="https://javabeginnerstutorial.com/wp-content/uploads/2018/12/1_BrowserOutput1-1.jpg 727w, https://javabeginnerstutorial.com/wp-content/uploads/2018/12/1_BrowserOutput1-1-300x139.jpg 300w" width="727"/><p>自行车复选框位于并按预期检查。</p><p><img alt="Actions output 2" class="alignnone size-full wp-image-14170" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2018/12/2_BrowserOutput2.jpg" height="405" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20764%20405'%3E%3C/svg%3E" width="764"/></p><noscript><img alt="Actions output 2" class="alignnone size-full wp-image-14170" height="405" src="img/42cf6db6c7594635f8626fa848cb1b00.png" width="764"/><p>双击文本<code>Message</code>,结果将突出显示。 在文本框中,“ hi there”用大写字母键入。 从可排序列表中将<code>click()</code>从其默认的第一位置拖动到第三位置。</p><p>在 JUnit 窗格中,绿色条显示测试用例已成功执行。 同样,控制台窗口显示没有错误以及所有打印的消息如预期的那样。</p><p><img alt="Actions eclipse IDE output" class="alignnone size-full wp-image-14171" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2018/12/3_EclipseOutput-1.jpg" height="323" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20637%20323'%3E%3C/svg%3E" width="637"/></p><noscript><img alt="Actions eclipse IDE output" class="alignnone size-full wp-image-14171" height="323" src="img/fc8513d158727fc823c0450b50cb21b2.png" width="637"/><p>是时候把忍者带出来了。 尝试使用尽可能多的动作类方法,并从中获得乐趣!</p><p>上面讨论的所有代码都可以在<a href="https://github.com/JBTAdmin/Selenium"> GitHub 存储库</a>的“ WebDriver”文件夹中找到。 您可以为存储库加注星标和分支以方便使用。 请仔细阅读<code>README.md</code>文件以获取明确说明。</p><p>祝你有美好的一天!</p><div class="sticky-nav" style="font-size: 15px;"><div class="sticky-nav-image"></div><div class="sticky-nav-holder"><div class="sticky-nav_item"><h6 class="heading-sm">下一篇文章</h6></div><h5 class="sticky-nav_heading " style="font-size: 15px;"><a href="https://javabeginnerstutorial.com/selenium/9ac-webdriver-unable-to-locate-an-element-easily-read-on/" title="9ac. WebDriver – Unable to locate an element easily? Read on…"> 9ac。 WebDriver –无法轻松定位元素? 继续阅读…</a></h5></div></div> </body> </html></noscript>
\ No newline at end of file
<noscript><img alt="Actions output 1" class="alignnone size-full wp-image-14169" height="338" sizes="(max-width: 727px) 100vw, 727px" src="img/a68025a724b5fa9a039ffea6277c6cec.png" srcset="https://javabeginnerstutorial.com/wp-content/uploads/2018/12/1_BrowserOutput1-1.jpg 727w, https://javabeginnerstutorial.com/wp-content/uploads/2018/12/1_BrowserOutput1-1-300x139.jpg 300w" width="727"/><p>自行车复选框位于并按预期检查。</p><p><img alt="Actions output 2" class="alignnone size-full wp-image-14170" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2018/12/2_BrowserOutput2.jpg" height="405" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20764%20405'%3E%3C/svg%3E" width="764"/></p><noscript><img alt="Actions output 2" class="alignnone size-full wp-image-14170" height="405" src="img/42cf6db6c7594635f8626fa848cb1b00.png" width="764"/><p>双击文本<code>Message</code>,结果将突出显示。 在文本框中,“ hi there”用大写字母键入。 从可排序列表中将<code>click()</code>从其默认的第一位置拖动到第三位置。</p><p>在 JUnit 窗格中,绿色条显示测试用例已成功执行。 同样,控制台窗口显示没有错误以及所有打印的消息如预期的那样。</p><p><img alt="Actions eclipse IDE output" class="alignnone size-full wp-image-14171" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2018/12/3_EclipseOutput-1.jpg" height="323" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20637%20323'%3E%3C/svg%3E" width="637"/></p><noscript><img alt="Actions eclipse IDE output" class="alignnone size-full wp-image-14171" height="323" src="img/fc8513d158727fc823c0450b50cb21b2.png" width="637"/><p>是时候把忍者带出来了。 尝试使用尽可能多的动作类方法,并从中获得乐趣!</p><p>上面讨论的所有代码都可以在<a href="https://github.com/JBTAdmin/Selenium"> GitHub 存储库</a>的“ WebDriver”文件夹中找到。 您可以为存储库加注星标和分支以方便使用。 请仔细阅读<code>README.md</code>文件以获取明确说明。</p><p>祝你有美好的一天!</p><div class="sticky-nav" style="font-size: 15px;"><div class="sticky-nav-image"></div><div class="sticky-nav-holder"><div class="sticky-nav_item"><h6 class="heading-sm">下一篇文章</h6></div><h5 class="sticky-nav_heading " style="font-size: 15px;"><a href="https://javabeginnerstutorial.com/selenium/9ac-webdriver-unable-to-locate-an-element-easily-read-on/" title="9ac. WebDriver – Unable to locate an element easily? Read on…"> 9ac。 WebDriver – 无法轻松定位元素? 继续阅读…</a></h5></div></div> </body> </html></noscript>
\ No newline at end of file
# 9ac。 WebDriver –无法轻松定位元素? 继续阅读...
# 9ac。 WebDriver – 无法轻松定位元素? 继续阅读...
> 原文: [https://javabeginnerstutorial.com/selenium/9ac-webdriver-unable-to-locate-an-element-easily-read-on/](https://javabeginnerstutorial.com/selenium/9ac-webdriver-unable-to-locate-an-element-easily-read-on/)
......@@ -40,4 +40,4 @@ custom 属性允许我们在 HTML 元素上存储额外的数据或信息。 要
###### 下一篇文章
##### [10a。 高级 WebDriver –使用 Apache ANT](https://javabeginnerstutorial.com/selenium/10a-advanced-webdriver-apache-ant/ "10a. Advanced WebDriver – Using Apache ANT")
\ No newline at end of file
##### [10a。 高级 WebDriver – 使用 Apache ANT](https://javabeginnerstutorial.com/selenium/10a-advanced-webdriver-apache-ant/ "10a. Advanced WebDriver – Using Apache ANT")
\ No newline at end of file
# 10a。 高级 WebDriver –使用 Apache ANT
# 10a。 高级 WebDriver – 使用 Apache ANT
> 原文: [https://javabeginnerstutorial.com/selenium/10a-advanced-webdriver-apache-ant/](https://javabeginnerstutorial.com/selenium/10a-advanced-webdriver-apache-ant/)
......@@ -47,12 +47,12 @@ Apache ANT 具有强大的功能,足以超越“谢谢”的门槛! 我们
每个构建文件都有
1. 项目至少包含一个目标
2. 目标执行工作单元的一组任务
3. 任务可以执行的一段代码
1. 项目至少包含一个目标
2. 目标执行工作单元的一组任务
3. 任务可以执行的一段代码
示例 build.xml 文件如下,
![sample build.xml](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20839%20425'%3E%3C/svg%3E)
<noscript><img alt="sample build.xml" class="alignnone size-full wp-image-12640" height="425" src="img/28116bee6867f10c68cb8a7b00821a1e.png" width="839"/><p>让我们一次将构建文件提取一个标签。</p><p><strong>项目</strong>:这具有三个属性。</p><ol><li>名称–项目名称</li><li>default –如果未提供任何内容,则应执行的默认目标</li><li>baseDir –从中计算文件中相对路径的基本目录。 “。” 指执行的当前目录</li></ol><p><strong>目标</strong>:如示例构建文件中所示,一个项目可以具有一个或多个目标。 目标是一组任务。 我们可以选择希望 ANT 执行的目标,并用逗号分隔它们的名称。 如果未指定目标,则将执行默认目标。</p><p>这里要注意的重要属性是“依赖”。 这指定了它所依赖的目标名称。 例如,编译目标将仅在其依赖的初始化目标执行后执行。 因此,depends 属性指定执行目标的顺序。</p><p><strong>任务</strong>:这是一段可以执行的代码。 每个任务可以具有一个或多个属性作为键值对。</p><p>句法:</p><p>&lt; <em>名称</em> <em> attribute1 </em> =” <em> value1 </em><em> attribute2 </em> =” <em> value2 </em>”…/ &gt;</p><p><em>名称</em>是任务的名称,<em>属性 N </em><em> valueN </em>分别是属性名称和值名称。</p><p>这是现成的<a href="https://ant.apache.org/manual/tasklist.html">内置任务</a>的长长列表。 我们也可以编写自己的任务。 (还记得吗?都是用 Java 编写的)。</p><p>您一定想知道,为什么要深入研究构建文件,而不是立即安装并开始执行操作! 传递这么多 ANT 知识是有原因的。 随着我们在旅途中的进一步发展,您将对此表示赞赏。 请稍等...</p><p>现在开始营业!</p><p><strong>步骤 1 </strong>:转到“ https://ant.apache.org/bindownload.cgi”,然后单击“ apache-ant-1.10.2-bin.zip”以在下面下载.zip 文件 “蚂蚁的当前版本”。</p><p><img alt="Download link" class="alignnone size-full wp-image-12641" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2018/04/1_downloadLink.jpg" height="98" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20572%2098'%3E%3C/svg%3E" width="572"/></p><noscript><img alt="Download link" class="alignnone size-full wp-image-12641" height="98" src="img/14970a7f07b1ccaa7596be317ad9fa33.png" width="572"/><p><strong>步骤 2:</strong>下载.zip 存档后,将所有文件提取到本地计算机上的目录中。</p><p><strong>步骤 3 </strong>:如下设置环境变量 ANT_HOME 和 Path,</p><p>右键点击“计算机”-&gt;属性-&gt;高级系统设置-&gt;“高级”标签-&gt;环境变量-&gt;在系统变量下单击“新建”。</p><p>ANT_HOME 设置为提取 Apache ANT 文件的文件夹的路径。</p><p><img alt="System variable settings" class="alignnone size-full wp-image-12642" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2018/04/2_SystemVariable.jpg" height="162" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20376%20162'%3E%3C/svg%3E" width="376"/></p><noscript><img alt="System variable settings" class="alignnone size-full wp-image-12642" height="162" src="img/ba0bc910e93456af8ef5bbf18bafd97b.png" width="376"/><p>类似地,编辑 Path 变量以包含%ANT_HOME%\ bin。</p><p><strong>步骤 4 </strong>:通过在“命令提示符”中键入以下命令来验证是否已安装 Apache ANT</p><p><em>蚂蚁版本</em></p><p><img alt="ANT version check in cmd" class="alignnone size-full wp-image-12643" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2018/04/3_CmdVersionCheck.jpg" height="86" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20354%2086'%3E%3C/svg%3E" width="354"/></p><noscript><img alt="ANT version check in cmd" class="alignnone size-full wp-image-12643" height="86" src="img/418f05483293c425772a4636e1d0364c.png" width="354"/><p><strong>步骤 5:</strong>下一个任务是打开 Eclipse IDE,</p><ul><li>右键单击 Java 项目-&gt;导出</li><li>在“常规”下,选择“蚂蚁构建文件”,然后点击“下一步”</li><li>确保已选择所需的项目</li><li>取消选中“创建目标以使用 Eclipse 编译器编译项目”,以删除对 Eclipse 的任何依赖</li></ul><p><img alt="Generating ANT buildfile" class="alignnone size-full wp-image-12638" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2018/04/4_Buildfiles-1.jpg" height="407" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20509%20407'%3E%3C/svg%3E" width="509"/></p><noscript><img alt="Generating ANT buildfile" class="alignnone size-full wp-image-12638" height="407" src="img/f6b7286b63d7900c3782225e686a6833.png" width="509"/><p>单击“完成”以查看自动生成的 eclipse 文件。</p><p>就是这样! 您已经准备好将所有项目作为 ANT 构建运行。 这很简单,不是吗?</p><p><strong> <em>即时贴:</em> </strong> <em> Eclipse 与 ANT 集成在一起。 为了确保 Eclipse 的“蚂蚁之家”指向最新版本的 ANT,请单击 Windows-&gt;首选项-&gt; Ant-&gt;运行时。 点击“类路径”标签。 展开“蚂蚁房屋入境”并验证路径。 如果指向的是其他版本,请单击“蚂蚁之家”并浏览用于提取 Apache ANT 文件的文件夹的位置。 </em></p><p>在我们的下一篇文章中,让我们做到这一点,并在 ANT 目标的帮助下生成 JUnit 报告。</p><p>安装愉快!</p><div class="sticky-nav" style="font-size: 15px;"><div class="sticky-nav-image"></div><div class="sticky-nav-holder"><div class="sticky-nav_item"><h6 class="heading-sm">下一篇文章</h6></div><h5 class="sticky-nav_heading " style="font-size: 15px;"><a href="https://javabeginnerstutorial.com/selenium/10b-advanced-webdriver-generating-junit-reports/" title="10b. Advanced WebDriver – Generating JUnit Report"> 10b。 高级 WebDriver –生成 JUnit 报告</a></h5></div></div> </body> </html></noscript>
\ No newline at end of file
<noscript><img alt="sample build.xml" class="alignnone size-full wp-image-12640" height="425" src="img/28116bee6867f10c68cb8a7b00821a1e.png" width="839"/><p>让我们一次将构建文件提取一个标签。</p><p><strong>项目</strong>:这具有三个属性。</p><ol><li>名称 – 项目名称</li><li>default – 如果未提供任何内容,则应执行的默认目标</li><li>baseDir – 从中计算文件中相对路径的基本目录。 “。” 指执行的当前目录</li></ol><p><strong>目标</strong>:如示例构建文件中所示,一个项目可以具有一个或多个目标。 目标是一组任务。 我们可以选择希望 ANT 执行的目标,并用逗号分隔它们的名称。 如果未指定目标,则将执行默认目标。</p><p>这里要注意的重要属性是“依赖”。 这指定了它所依赖的目标名称。 例如,编译目标将仅在其依赖的初始化目标执行后执行。 因此,depends 属性指定执行目标的顺序。</p><p><strong>任务</strong>:这是一段可以执行的代码。 每个任务可以具有一个或多个属性作为键值对。</p><p>句法:</p><p>&lt; <em>名称</em> <em> attribute1 </em> =” <em> value1 </em><em> attribute2 </em> =” <em> value2 </em>”…/ &gt;</p><p><em>名称</em>是任务的名称,<em>属性 N </em><em> valueN </em>分别是属性名称和值名称。</p><p>这是现成的<a href="https://ant.apache.org/manual/tasklist.html">内置任务</a>的长长列表。 我们也可以编写自己的任务。 (还记得吗?都是用 Java 编写的)。</p><p>您一定想知道,为什么要深入研究构建文件,而不是立即安装并开始执行操作! 传递这么多 ANT 知识是有原因的。 随着我们在旅途中的进一步发展,您将对此表示赞赏。 请稍等...</p><p>现在开始营业!</p><p><strong>步骤 1 </strong>:转到“ https://ant.apache.org/bindownload.cgi”,然后单击“ apache-ant-1.10.2-bin.zip”以在下面下载.zip 文件 “蚂蚁的当前版本”。</p><p><img alt="Download link" class="alignnone size-full wp-image-12641" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2018/04/1_downloadLink.jpg" height="98" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20572%2098'%3E%3C/svg%3E" width="572"/></p><noscript><img alt="Download link" class="alignnone size-full wp-image-12641" height="98" src="img/14970a7f07b1ccaa7596be317ad9fa33.png" width="572"/><p><strong>步骤 2:</strong>下载.zip 存档后,将所有文件提取到本地计算机上的目录中。</p><p><strong>步骤 3 </strong>:如下设置环境变量 ANT_HOME 和 Path,</p><p>右键点击“计算机”-&gt;属性-&gt;高级系统设置-&gt;“高级”标签-&gt;环境变量-&gt;在系统变量下单击“新建”。</p><p>ANT_HOME 设置为提取 Apache ANT 文件的文件夹的路径。</p><p><img alt="System variable settings" class="alignnone size-full wp-image-12642" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2018/04/2_SystemVariable.jpg" height="162" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20376%20162'%3E%3C/svg%3E" width="376"/></p><noscript><img alt="System variable settings" class="alignnone size-full wp-image-12642" height="162" src="img/ba0bc910e93456af8ef5bbf18bafd97b.png" width="376"/><p>类似地,编辑 Path 变量以包含%ANT_HOME%\ bin。</p><p><strong>步骤 4 </strong>:通过在“命令提示符”中键入以下命令来验证是否已安装 Apache ANT</p><p><em>蚂蚁版本</em></p><p><img alt="ANT version check in cmd" class="alignnone size-full wp-image-12643" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2018/04/3_CmdVersionCheck.jpg" height="86" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20354%2086'%3E%3C/svg%3E" width="354"/></p><noscript><img alt="ANT version check in cmd" class="alignnone size-full wp-image-12643" height="86" src="img/418f05483293c425772a4636e1d0364c.png" width="354"/><p><strong>步骤 5:</strong>下一个任务是打开 Eclipse IDE,</p><ul><li>右键单击 Java 项目-&gt;导出</li><li>在“常规”下,选择“蚂蚁构建文件”,然后点击“下一步”</li><li>确保已选择所需的项目</li><li>取消选中“创建目标以使用 Eclipse 编译器编译项目”,以删除对 Eclipse 的任何依赖</li></ul><p><img alt="Generating ANT buildfile" class="alignnone size-full wp-image-12638" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2018/04/4_Buildfiles-1.jpg" height="407" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20509%20407'%3E%3C/svg%3E" width="509"/></p><noscript><img alt="Generating ANT buildfile" class="alignnone size-full wp-image-12638" height="407" src="img/f6b7286b63d7900c3782225e686a6833.png" width="509"/><p>单击“完成”以查看自动生成的 eclipse 文件。</p><p>就是这样! 您已经准备好将所有项目作为 ANT 构建运行。 这很简单,不是吗?</p><p><strong> <em>即时贴:</em> </strong> <em> Eclipse 与 ANT 集成在一起。 为了确保 Eclipse 的“蚂蚁之家”指向最新版本的 ANT,请单击 Windows-&gt;首选项-&gt; Ant-&gt;运行时。 点击“类路径”标签。 展开“蚂蚁房屋入境”并验证路径。 如果指向的是其他版本,请单击“蚂蚁之家”并浏览用于提取 Apache ANT 文件的文件夹的位置。 </em></p><p>在我们的下一篇文章中,让我们做到这一点,并在 ANT 目标的帮助下生成 JUnit 报告。</p><p>安装愉快!</p><div class="sticky-nav" style="font-size: 15px;"><div class="sticky-nav-image"></div><div class="sticky-nav-holder"><div class="sticky-nav_item"><h6 class="heading-sm">下一篇文章</h6></div><h5 class="sticky-nav_heading " style="font-size: 15px;"><a href="https://javabeginnerstutorial.com/selenium/10b-advanced-webdriver-generating-junit-reports/" title="10b. Advanced WebDriver – Generating JUnit Report"> 10b。 高级 WebDriver – 生成 JUnit 报告</a></h5></div></div> </body> </html></noscript>
\ No newline at end of file
# 10b。 高级 WebDriver –生成 JUnit 报告
# 10b。 高级 WebDriver – 生成 JUnit 报告
> 原文: [https://javabeginnerstutorial.com/selenium/10b-advanced-webdriver-generating-junit-reports/](https://javabeginnerstutorial.com/selenium/10b-advanced-webdriver-generating-junit-reports/)
......
......@@ -50,8 +50,8 @@ Apache ANT 的 JunitReport 任务通过执行以下步骤来生成报告,
还记得吗,我们有两种格式? 因此,要自定义:
* 框架编辑 junit-frames.xsl
* noframes –编辑 junit-noframes.xsl
* 框架编辑 junit-frames.xsl
* noframes – 编辑 junit-noframes.xsl
就我而言,这两个 XSL 文件都位于“ E:\ apache-ant-1.10.2 \ etc”路径中。 作为本文的一部分,让我们研究“框架”格式。 这意味着我们将编辑“ **junit-frames.xsl** ”文件。 复制此文件并将其粘贴到项目路径中。 不要重命名文件。 为了使所有更改都能正常进行,请向报告任务添加属性**'styledir'**,如下所示。 这指定了定义的样式表 junit-frames.xsl 的位置。 **“。”** 指定此样式表位于当前目录中(与构建文件的目录相同)。
......
......@@ -51,4 +51,4 @@
![Before adding column](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20703%20219'%3E%3C/svg%3E)
<noscript><img alt="Before adding column" class="alignnone size-full wp-image-13133" height="219" src="img/84b0d9a3e774aca418746f37ade3cea2.png" width="703"/><h3>之后<em></em></h3><p><img alt="After adding a column" class="alignnone size-full wp-image-13134" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2018/05/19_CustomColAfter-1.jpg" height="226" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20776%20226'%3E%3C/svg%3E" width="776"/></p><noscript><img alt="After adding a column" class="alignnone size-full wp-image-13134" height="226" src="img/e4eeb80cc04eebc2a725bfb1f5fcb85b.png" width="776"/><h2>改变风格</h2><p>努力思考如何更改生成的报告中的样式? 无需为此费心! 因为和其他网页一样,我们也有一个 CSS 样式表来处理此报告的样式。 只需在“ junit-frames.xsl”文件中搜索名称为“ stylesheet.css”的模板即可。</p><pre><code class="language-xml">&lt;!-- this is the stylesheet css to use for nearly everything --&gt; &lt;xsl:template name="stylesheet.css"&gt;</code></pre><p>主体,表,标题,堆栈跟踪,错误,失败,段落,属性的样式均在此模板中指定。 继续前进,戴上帽子! 对 CSS 的每一行进行试验,并查看呈现的更改。 是的,您也可以添加自己的 CSS!</p><p><span class="ezoic-adpicker-ad" id="ezoic-pub-ad-placeholder-124"> </span> <span class="ezoic-ad box-4 adtester-container adtester-container-124" data-ez-name="javabeginnerstutorial_com-box-4" style="display:block !important;float:none;margin-bottom:2px !important;margin-left:0px !important;margin-right:0px !important;margin-top:2px !important;min-height:110px;min-width:728px;text-align:center !important;"> <span class="ezoic-ad" ezah="90" ezaw="728" id="div-gpt-ad-javabeginnerstutorial_com-box-4-0" style="position:relative;z-index:0;display:inline-block;min-height:90px;min-width:728px;"> </span> </span>让我们来看一个入门的小例子。 表的详细信息和失败样式如下所示,</p><pre><code class="language-xml">table.details tr th{ font-weight: bold; text-align:left; background:#a6caf0; } .Failure { font-weight:bold; color:purple; }</code></pre><p>让我们将这些更改如下:</p><ol><li>所有表格标题均居中对齐</li><li>表格标题行的背景颜色为“绿色黄色”(#ADFF2F)</li><li>失败文字颜色变为栗色</li></ol><pre><code class="language-xml">table.details tr th{ font-weight: bold; text-align:center; background:#ADFF2F; } .Failure { font-weight:bold; color:maroon; }</code></pre><h3><em>BEFORE</em></h3><p><img alt="Before changing styles" class="alignnone size-full wp-image-13135" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2018/05/20_StylesBefore-1.jpg" height="458" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201095%20458'%3E%3C/svg%3E" width="1095"/></p><noscript><img alt="Before changing styles" class="alignnone size-full wp-image-13135" height="458" src="img/27f8f130e1cca67cd5d99f7988b85882.png" width="1095"/><h3><em>AFTER</em></h3><p><img alt="After changing the styles" class="alignnone size-full wp-image-13136" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2018/05/21_StylesAfter.jpg" height="437" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201058%20437'%3E%3C/svg%3E" width="1058"/></p><noscript><img alt="After changing the styles" class="alignnone size-full wp-image-13136" height="437" src="img/fe7ac3a7f76a08a05e580ed21c64bea7.png" width="1058"/><p>我知道,它看起来并不吸引眼球,但我们证明了我们想要的。 所以,你去了!</p><h2><strong>在标头部分</strong>中添加徽标</h2><p>我们大多数人都喜欢生成的报告上的徽标。 谁不喜欢个性化和一点营销? 如果您懂一点 HTML,就非常简单。 在名为“ pageHeader”的模板上,添加一个图像标签,并在 src 属性中指定路径。 我已将徽标图像放置在生成 index.html 文件的项目的“ junit”文件夹中。</p><pre><code class="language-xml">&lt;xsl:template name="pageHeader"&gt; &lt;!-- &lt;h1&gt;&lt;xsl:value-of select="$TITLE"/&gt;&lt;/h1&gt; --&gt; &lt;h1&gt;Custom JUnit Report&lt;/h1&gt; &lt;table width="100%"&gt; &lt;tr&gt; &lt;td align="left"&gt;&lt;/td&gt; &lt;td align="right"&gt;&lt;img width="50" height="50" alt="Selenium" src="myLogo.jpg"/&gt; Designed by ninjas!&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;hr size="1"/&gt; &lt;/xsl:template&gt;</code></pre><h3><em>结果</em></h3><p><img alt="Adding a Logo" class="alignnone size-full wp-image-13137" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2018/05/22_Logo.jpg" height="208" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201089%20208'%3E%3C/svg%3E" width="1089"/></p><noscript><img alt="Adding a Logo" class="alignnone size-full wp-image-13137" height="208" src="img/4d78e6dc472ceb1d9f1e11333fc47113.png" width="1089"/><p><strong>修改静态文本</strong></p><p>这是锦上添花(哦!您现在已经知道了)。 要修改报告中显示的任何静态文本,您只需在“ junit-frames.xsl”文件中进行更改。 是的,你没看错。 就这么简单!</p><p>假设在报告的摘要表中,而不是“测试”,我希望它是“测试数量”。 只需在 h2 标签上显示“摘要”的正文部分更改文本,</p><pre><code class="language-xml">&lt;table class="details" border="0" cellpadding="5" cellspacing="2" width="95%"&gt; &lt;tr valign="top"&gt; &lt;th&gt;Number of Tests&lt;/th&gt; &lt;th&gt;Failures&lt;/th&gt; &lt;th&gt;Errors&lt;/th&gt; &lt;th&gt;Skipped&lt;/th&gt; &lt;th&gt;Success rate&lt;/th&gt; &lt;th&gt;Time&lt;/th&gt; &lt;/tr&gt;</code></pre><h3><em>RESULT</em></h3><p><img alt="Modifying static text" class="alignnone size-full wp-image-13132" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2018/05/23_staticText.jpg" height="243" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201028%20243'%3E%3C/svg%3E" width="1028"/></p><noscript><img alt="Modifying static text" class="alignnone size-full wp-image-13132" height="243" src="img/95e2e8910446d894375595f166f57c3f.png" width="1028"/><p>是时候对我们到目前为止所学到的东西进行反思。</p><p>在另一篇文章中再见。 定制愉快!</p><div class="sticky-nav" style="font-size: 15px;"><div class="sticky-nav-image"></div><div class="sticky-nav-holder"><div class="sticky-nav_item"><h6 class="heading-sm">下一篇文章</h6></div><h5 class="sticky-nav_heading " style="font-size: 15px;"><a href="https://javabeginnerstutorial.com/selenium/10e-advanced-webdriver-generating-pdf-report/" title="10e. Advanced WebDriver – Generating a PDF report"> 10e。 Advanced WebDriver –生成 PDF 报告</a></h5></div></div> </body> </html></noscript>
\ No newline at end of file
<noscript><img alt="Before adding column" class="alignnone size-full wp-image-13133" height="219" src="img/84b0d9a3e774aca418746f37ade3cea2.png" width="703"/><h3>之后<em></em></h3><p><img alt="After adding a column" class="alignnone size-full wp-image-13134" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2018/05/19_CustomColAfter-1.jpg" height="226" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20776%20226'%3E%3C/svg%3E" width="776"/></p><noscript><img alt="After adding a column" class="alignnone size-full wp-image-13134" height="226" src="img/e4eeb80cc04eebc2a725bfb1f5fcb85b.png" width="776"/><h2>改变风格</h2><p>努力思考如何更改生成的报告中的样式? 无需为此费心! 因为和其他网页一样,我们也有一个 CSS 样式表来处理此报告的样式。 只需在“ junit-frames.xsl”文件中搜索名称为“ stylesheet.css”的模板即可。</p><pre><code class="language-xml">&lt;!-- this is the stylesheet css to use for nearly everything --&gt; &lt;xsl:template name="stylesheet.css"&gt;</code></pre><p>主体,表,标题,堆栈跟踪,错误,失败,段落,属性的样式均在此模板中指定。 继续前进,戴上帽子! 对 CSS 的每一行进行试验,并查看呈现的更改。 是的,您也可以添加自己的 CSS!</p><p><span class="ezoic-adpicker-ad" id="ezoic-pub-ad-placeholder-124"> </span> <span class="ezoic-ad box-4 adtester-container adtester-container-124" data-ez-name="javabeginnerstutorial_com-box-4" style="display:block !important;float:none;margin-bottom:2px !important;margin-left:0px !important;margin-right:0px !important;margin-top:2px !important;min-height:110px;min-width:728px;text-align:center !important;"> <span class="ezoic-ad" ezah="90" ezaw="728" id="div-gpt-ad-javabeginnerstutorial_com-box-4-0" style="position:relative;z-index:0;display:inline-block;min-height:90px;min-width:728px;"> </span> </span>让我们来看一个入门的小例子。 表的详细信息和失败样式如下所示,</p><pre><code class="language-xml">table.details tr th{ font-weight: bold; text-align:left; background:#a6caf0; } .Failure { font-weight:bold; color:purple; }</code></pre><p>让我们将这些更改如下:</p><ol><li>所有表格标题均居中对齐</li><li>表格标题行的背景颜色为“绿色黄色”(#ADFF2F)</li><li>失败文字颜色变为栗色</li></ol><pre><code class="language-xml">table.details tr th{ font-weight: bold; text-align:center; background:#ADFF2F; } .Failure { font-weight:bold; color:maroon; }</code></pre><h3><em>BEFORE</em></h3><p><img alt="Before changing styles" class="alignnone size-full wp-image-13135" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2018/05/20_StylesBefore-1.jpg" height="458" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201095%20458'%3E%3C/svg%3E" width="1095"/></p><noscript><img alt="Before changing styles" class="alignnone size-full wp-image-13135" height="458" src="img/27f8f130e1cca67cd5d99f7988b85882.png" width="1095"/><h3><em>AFTER</em></h3><p><img alt="After changing the styles" class="alignnone size-full wp-image-13136" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2018/05/21_StylesAfter.jpg" height="437" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201058%20437'%3E%3C/svg%3E" width="1058"/></p><noscript><img alt="After changing the styles" class="alignnone size-full wp-image-13136" height="437" src="img/fe7ac3a7f76a08a05e580ed21c64bea7.png" width="1058"/><p>我知道,它看起来并不吸引眼球,但我们证明了我们想要的。 所以,你去了!</p><h2><strong>在标头部分</strong>中添加徽标</h2><p>我们大多数人都喜欢生成的报告上的徽标。 谁不喜欢个性化和一点营销? 如果您懂一点 HTML,就非常简单。 在名为“ pageHeader”的模板上,添加一个图像标签,并在 src 属性中指定路径。 我已将徽标图像放置在生成 index.html 文件的项目的“ junit”文件夹中。</p><pre><code class="language-xml">&lt;xsl:template name="pageHeader"&gt; &lt;!-- &lt;h1&gt;&lt;xsl:value-of select="$TITLE"/&gt;&lt;/h1&gt; --&gt; &lt;h1&gt;Custom JUnit Report&lt;/h1&gt; &lt;table width="100%"&gt; &lt;tr&gt; &lt;td align="left"&gt;&lt;/td&gt; &lt;td align="right"&gt;&lt;img width="50" height="50" alt="Selenium" src="myLogo.jpg"/&gt; Designed by ninjas!&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;hr size="1"/&gt; &lt;/xsl:template&gt;</code></pre><h3><em>结果</em></h3><p><img alt="Adding a Logo" class="alignnone size-full wp-image-13137" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2018/05/22_Logo.jpg" height="208" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201089%20208'%3E%3C/svg%3E" width="1089"/></p><noscript><img alt="Adding a Logo" class="alignnone size-full wp-image-13137" height="208" src="img/4d78e6dc472ceb1d9f1e11333fc47113.png" width="1089"/><p><strong>修改静态文本</strong></p><p>这是锦上添花(哦!您现在已经知道了)。 要修改报告中显示的任何静态文本,您只需在“ junit-frames.xsl”文件中进行更改。 是的,你没看错。 就这么简单!</p><p>假设在报告的摘要表中,而不是“测试”,我希望它是“测试数量”。 只需在 h2 标签上显示“摘要”的正文部分更改文本,</p><pre><code class="language-xml">&lt;table class="details" border="0" cellpadding="5" cellspacing="2" width="95%"&gt; &lt;tr valign="top"&gt; &lt;th&gt;Number of Tests&lt;/th&gt; &lt;th&gt;Failures&lt;/th&gt; &lt;th&gt;Errors&lt;/th&gt; &lt;th&gt;Skipped&lt;/th&gt; &lt;th&gt;Success rate&lt;/th&gt; &lt;th&gt;Time&lt;/th&gt; &lt;/tr&gt;</code></pre><h3><em>RESULT</em></h3><p><img alt="Modifying static text" class="alignnone size-full wp-image-13132" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2018/05/23_staticText.jpg" height="243" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201028%20243'%3E%3C/svg%3E" width="1028"/></p><noscript><img alt="Modifying static text" class="alignnone size-full wp-image-13132" height="243" src="img/95e2e8910446d894375595f166f57c3f.png" width="1028"/><p>是时候对我们到目前为止所学到的东西进行反思。</p><p>在另一篇文章中再见。 定制愉快!</p><div class="sticky-nav" style="font-size: 15px;"><div class="sticky-nav-image"></div><div class="sticky-nav-holder"><div class="sticky-nav_item"><h6 class="heading-sm">下一篇文章</h6></div><h5 class="sticky-nav_heading " style="font-size: 15px;"><a href="https://javabeginnerstutorial.com/selenium/10e-advanced-webdriver-generating-pdf-report/" title="10e. Advanced WebDriver – Generating a PDF report"> 10e。 Advanced WebDriver – 生成 PDF 报告</a></h5></div></div> </body> </html></noscript>
\ No newline at end of file
# 10e。 高级 WebDriver –生成 PDF 报告
# 10e。 高级 WebDriver – 生成 PDF 报告
> 原文: [https://javabeginnerstutorial.com/selenium/10e-advanced-webdriver-generating-pdf-report/](https://javabeginnerstutorial.com/selenium/10e-advanced-webdriver-generating-pdf-report/)
嗨冠军! 到目前为止,我们在报告方面已经涵盖了很多基础,您已经达到了高潮文章。 如果要将 HTML 报告附加到电子邮件并将其发送给利益相关者,则生成 HTML 报告可能没有帮助。 由于 ANT 生成的 JUnit 报告具有 index.html 文件,该文件又嵌入了其他一些 HTML 文件,例如 overview-frame.html,所有类-frame.html 和 overview-summary.html 文件。
在这种情况下我们该怎么办? 我们如何将其附加到电子邮件? 我们不能将其作为单个文件而不是一组 HTML 文件获得吗? –所有这些问题的唯一答案是,生成一个 **PDF 文件**
在这种情况下我们该怎么办? 我们如何将其附加到电子邮件? 我们不能将其作为单个文件而不是一组 HTML 文件获得吗? – 所有这些问题的唯一答案是,生成一个 **PDF 文件**
让我们看看在不干扰我们到目前为止所做的[定制](https://javabeginnerstutorial.com/selenium/10c-advanced-webdriver-junit-report-customization/)的情况下生成 PDF 报告的过程,
......@@ -14,4 +14,4 @@
![PDF Essentials Download](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20792%20382'%3E%3C/svg%3E)
<noscript><img alt="PDF Essentials Download" class="alignnone size-full wp-image-13353" height="382" sizes="(max-width: 792px) 100vw, 792px" src="img/f3daaf777964f1e44dde697809da3616.png" srcset="https://javabeginnerstutorial.com/wp-content/uploads/2018/06/25_pdfEssentialsDownload.jpg 792w, https://javabeginnerstutorial.com/wp-content/uploads/2018/06/25_pdfEssentialsDownload-300x145.jpg 300w, https://javabeginnerstutorial.com/wp-content/uploads/2018/06/25_pdfEssentialsDownload-768x370.jpg 768w" width="792"/><p>将文件内容解压缩到本地文件夹并记下路径。 另外,请确保分发中包含“ build-junitpdfreport.xml”文件和“ lib”文件夹以及某些其他文件和文件夹。</p><h2><strong>步骤 2:</strong></h2><p>是时候在 Eclipse IDE 中浏览“ Build.xml”文件了。 有几行要添加。 首先要做的是告诉我们的项目,该 junitpdfreport 基本 zip 文件的内容在哪里提取。 在构建文件的&lt;项目&gt;标签中,将以下行及其路径添加到分发位置。</p><pre><code class="language-xml">&lt;!-- JUnit PDF report installation location --&gt; &lt;import file="E:/junitpdfreport_essentials_1_0/build-junitpdfreport.xml"/&gt;</code></pre><h2><strong>步骤 3:</strong></h2><p>将以下目标也添加到构建文件中,以便 ANT 知道该怎么做。</p><pre><code class="language-xml">&lt;!-- PDF Report --&gt; &lt;target name="pdfReport"&gt; &lt;junitpdfreport todir="${junit.output.dir}" styledir="default"&gt; &lt;fileset dir="${junit.output.dir}"&gt; &lt;include name="TEST-*.xml"/&gt; &lt;/fileset&gt; &lt;/junitpdfreport&gt; &lt;/target&gt;</code></pre><p>让我们尝试一次解密这一行,</p><p><span class="ezoic-adpicker-ad" id="ezoic-pub-ad-placeholder-124"> </span> <span class="ezoic-ad box-4 adtester-container adtester-container-124" data-ez-name="javabeginnerstutorial_com-box-4" style="display:block !important;float:none;margin-bottom:2px !important;margin-left:0px !important;margin-right:0px !important;margin-top:2px !important;min-height:110px;min-width:728px;text-align:center !important;"> <span class="ezoic-ad" ezah="90" ezaw="728" id="div-gpt-ad-javabeginnerstutorial_com-box-4-0" style="position:relative;z-index:0;display:inline-block;min-height:90px;min-width:728px;"> </span> </span> 1\. <code data-enlighter-language="xml">junitpdfreport todir="${junit.output.dir}"</code></p><p>–这是将生成的 pdf 报告保存的位置。</p><p>2\. <code data-enlighter-language="xml">fileset dir="${junit.output.dir}" </code></p><p>–提供所有 JUnit 测试结果所在的位置(请记住为执行的每个测试生成的 XML 文件,格式为“ TEST-*。xml”)。</p><p>就我而言,我有以下测试文件:TEST-com.blog.junitTests.RadioBtns_Checkboxes.xml,TEST-com.blog.junitTests.SelectItems.xml 和 TESTS-TestSuites.xml 保存在位置'junit / '。</p><h2><strong>步骤 4:</strong></h2><p>右键单击并选择“ 2 ANT Build”,然后在“编辑配置”弹出窗口中选中“目标”标签。 确保已选中“ pdfReport”目标,它是执行顺序中提到的最后一个目标。</p><p><img alt="PDF target configuration" class="alignnone size-full wp-image-13358" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2018/06/24_pdfTargetConfig.jpg" height="521" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20782%20521'%3E%3C/svg%3E" width="782"/></p><noscript><img alt="PDF target configuration" class="alignnone size-full wp-image-13358" height="521" src="img/3afeff61fc34dbc54a4173a3a68f5898.png" width="782"/><p>点击“运行”以执行构建文件。</p><h2><strong>步骤 5:</strong></h2><p>在指定的输出目录(本例中为“ junit /”)中验证生成的 PDF 报告。</p><p><img alt="JUnit Folder" class="alignnone size-full wp-image-13354" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2018/06/26_pdfJnitFolder.jpg" height="397" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20461%20397'%3E%3C/svg%3E" width="461"/></p><noscript><img alt="JUnit Folder" class="alignnone size-full wp-image-13354" height="397" src="img/aa7d07ec593be85f4cb61b59a93dfac6.png" width="461"/><p>生成的 PDF 文件共有 8 页。 例如,前 5 页如下所示,</p><p><img alt="PDF report part 1" class="alignnone size-full wp-image-13355" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2018/06/27_pdf_Report1.jpg" height="493" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20872%20493'%3E%3C/svg%3E" width="872"/></p><noscript><img alt="PDF report part 1" class="alignnone size-full wp-image-13355" height="493" src="img/355dee55d351b9aac326eded2118a8db.png" width="872"/><p><img alt="PDF Report part 2" class="alignnone size-full wp-image-13356" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2018/06/28_pdf_Report2-1.jpg" height="472" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20873%20472'%3E%3C/svg%3E" width="873"/></p><noscript><img alt="PDF Report part 2" class="alignnone size-full wp-image-13356" height="472" src="img/a9d33aeeff32831e2eb61b9318a47817.png" width="873"/><p>最后但并非最不重要的是,该构建文件的快照显示了 HTML 报告和 PDF 报告目标代码,</p><p><img alt="ANT buildfile" class="alignnone size-full wp-image-13357" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2018/06/29_pdfBuildFile-1.jpg" height="592" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20873%20592'%3E%3C/svg%3E" width="873"/></p><noscript><img alt="ANT buildfile" class="alignnone size-full wp-image-13357" height="592" src="img/42bef927c7f8c0a40ebd7edc15606835.png" width="873"/><p>在您达到本文结尾时,让我们利用练习的力量。 在另一个主题上再见,让您掌握 WebDriver!</p><div class="sticky-nav" style="font-size: 15px;"><div class="sticky-nav-image"></div><div class="sticky-nav-holder"><div class="sticky-nav_item"><h6 class="heading-sm">下一篇文章</h6></div><h5 class="sticky-nav_heading " style="font-size: 15px;"><a href="https://javabeginnerstutorial.com/selenium/10f-advanced-webdriver-taking-screenshot/" title="10f. Advanced WebDriver – Taking a Screenshot"> 10f。 高级 WebDriver –截屏</a></h5></div></div> </body> </html></noscript>
\ No newline at end of file
<noscript><img alt="PDF Essentials Download" class="alignnone size-full wp-image-13353" height="382" sizes="(max-width: 792px) 100vw, 792px" src="img/f3daaf777964f1e44dde697809da3616.png" srcset="https://javabeginnerstutorial.com/wp-content/uploads/2018/06/25_pdfEssentialsDownload.jpg 792w, https://javabeginnerstutorial.com/wp-content/uploads/2018/06/25_pdfEssentialsDownload-300x145.jpg 300w, https://javabeginnerstutorial.com/wp-content/uploads/2018/06/25_pdfEssentialsDownload-768x370.jpg 768w" width="792"/><p>将文件内容解压缩到本地文件夹并记下路径。 另外,请确保分发中包含“ build-junitpdfreport.xml”文件和“ lib”文件夹以及某些其他文件和文件夹。</p><h2><strong>步骤 2:</strong></h2><p>是时候在 Eclipse IDE 中浏览“ Build.xml”文件了。 有几行要添加。 首先要做的是告诉我们的项目,该 junitpdfreport 基本 zip 文件的内容在哪里提取。 在构建文件的&lt;项目&gt;标签中,将以下行及其路径添加到分发位置。</p><pre><code class="language-xml">&lt;!-- JUnit PDF report installation location --&gt; &lt;import file="E:/junitpdfreport_essentials_1_0/build-junitpdfreport.xml"/&gt;</code></pre><h2><strong>步骤 3:</strong></h2><p>将以下目标也添加到构建文件中,以便 ANT 知道该怎么做。</p><pre><code class="language-xml">&lt;!-- PDF Report --&gt; &lt;target name="pdfReport"&gt; &lt;junitpdfreport todir="${junit.output.dir}" styledir="default"&gt; &lt;fileset dir="${junit.output.dir}"&gt; &lt;include name="TEST-*.xml"/&gt; &lt;/fileset&gt; &lt;/junitpdfreport&gt; &lt;/target&gt;</code></pre><p>让我们尝试一次解密这一行,</p><p><span class="ezoic-adpicker-ad" id="ezoic-pub-ad-placeholder-124"> </span> <span class="ezoic-ad box-4 adtester-container adtester-container-124" data-ez-name="javabeginnerstutorial_com-box-4" style="display:block !important;float:none;margin-bottom:2px !important;margin-left:0px !important;margin-right:0px !important;margin-top:2px !important;min-height:110px;min-width:728px;text-align:center !important;"> <span class="ezoic-ad" ezah="90" ezaw="728" id="div-gpt-ad-javabeginnerstutorial_com-box-4-0" style="position:relative;z-index:0;display:inline-block;min-height:90px;min-width:728px;"> </span> </span> 1\. <code data-enlighter-language="xml">junitpdfreport todir="${junit.output.dir}"</code></p><p>– 这是将生成的 pdf 报告保存的位置。</p><p>2\. <code data-enlighter-language="xml">fileset dir="${junit.output.dir}" </code></p><p>– 提供所有 JUnit 测试结果所在的位置(请记住为执行的每个测试生成的 XML 文件,格式为“ TEST-*。xml”)。</p><p>就我而言,我有以下测试文件:TEST-com.blog.junitTests.RadioBtns_Checkboxes.xml,TEST-com.blog.junitTests.SelectItems.xml 和 TESTS-TestSuites.xml 保存在位置'junit / '。</p><h2><strong>步骤 4:</strong></h2><p>右键单击并选择“ 2 ANT Build”,然后在“编辑配置”弹出窗口中选中“目标”标签。 确保已选中“ pdfReport”目标,它是执行顺序中提到的最后一个目标。</p><p><img alt="PDF target configuration" class="alignnone size-full wp-image-13358" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2018/06/24_pdfTargetConfig.jpg" height="521" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20782%20521'%3E%3C/svg%3E" width="782"/></p><noscript><img alt="PDF target configuration" class="alignnone size-full wp-image-13358" height="521" src="img/3afeff61fc34dbc54a4173a3a68f5898.png" width="782"/><p>点击“运行”以执行构建文件。</p><h2><strong>步骤 5:</strong></h2><p>在指定的输出目录(本例中为“ junit /”)中验证生成的 PDF 报告。</p><p><img alt="JUnit Folder" class="alignnone size-full wp-image-13354" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2018/06/26_pdfJnitFolder.jpg" height="397" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20461%20397'%3E%3C/svg%3E" width="461"/></p><noscript><img alt="JUnit Folder" class="alignnone size-full wp-image-13354" height="397" src="img/aa7d07ec593be85f4cb61b59a93dfac6.png" width="461"/><p>生成的 PDF 文件共有 8 页。 例如,前 5 页如下所示,</p><p><img alt="PDF report part 1" class="alignnone size-full wp-image-13355" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2018/06/27_pdf_Report1.jpg" height="493" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20872%20493'%3E%3C/svg%3E" width="872"/></p><noscript><img alt="PDF report part 1" class="alignnone size-full wp-image-13355" height="493" src="img/355dee55d351b9aac326eded2118a8db.png" width="872"/><p><img alt="PDF Report part 2" class="alignnone size-full wp-image-13356" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2018/06/28_pdf_Report2-1.jpg" height="472" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20873%20472'%3E%3C/svg%3E" width="873"/></p><noscript><img alt="PDF Report part 2" class="alignnone size-full wp-image-13356" height="472" src="img/a9d33aeeff32831e2eb61b9318a47817.png" width="873"/><p>最后但并非最不重要的是,该构建文件的快照显示了 HTML 报告和 PDF 报告目标代码,</p><p><img alt="ANT buildfile" class="alignnone size-full wp-image-13357" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2018/06/29_pdfBuildFile-1.jpg" height="592" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20873%20592'%3E%3C/svg%3E" width="873"/></p><noscript><img alt="ANT buildfile" class="alignnone size-full wp-image-13357" height="592" src="img/42bef927c7f8c0a40ebd7edc15606835.png" width="873"/><p>在您达到本文结尾时,让我们利用练习的力量。 在另一个主题上再见,让您掌握 WebDriver!</p><div class="sticky-nav" style="font-size: 15px;"><div class="sticky-nav-image"></div><div class="sticky-nav-holder"><div class="sticky-nav_item"><h6 class="heading-sm">下一篇文章</h6></div><h5 class="sticky-nav_heading " style="font-size: 15px;"><a href="https://javabeginnerstutorial.com/selenium/10f-advanced-webdriver-taking-screenshot/" title="10f. Advanced WebDriver – Taking a Screenshot"> 10f。 高级 WebDriver – 截屏</a></h5></div></div> </body> </html></noscript>
\ No newline at end of file
# 10 楼 高级 WebDriver –截屏
# 10 楼 高级 WebDriver – 截屏
> 原文: [https://javabeginnerstutorial.com/selenium/10f-advanced-webdriver-taking-screenshot/](https://javabeginnerstutorial.com/selenium/10f-advanced-webdriver-taking-screenshot/)
......@@ -83,8 +83,8 @@ public static String timestamp() {
使用两种方法创建一个名为“ SaveScreenshot.java”的新类。
1. `public static void capture(String testCaseName, WebDriver driver)` –具有捕获屏幕快照并将其保存到所需位置的所有代码。
2. `public static String timestamp()` –用于生成时间戳并将其提供给上述方法,以使每个保存的屏幕截图都是唯一的。
1. `public static void capture(String testCaseName, WebDriver driver)` 具有捕获屏幕快照并将其保存到所需位置的所有代码。
2. `public static String timestamp()` 用于生成时间戳并将其提供给上述方法,以使每个保存的屏幕截图都是唯一的。
## 样本场景
......@@ -205,4 +205,4 @@ public class ScreenshotTest {
![Eclipse output](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20815%20362'%3E%3C/svg%3E)
<noscript><img alt="Eclipse output" class="alignnone size-full wp-image-13444" height="362" src="img/d9bba1da5599720cb4111735fe851a62.png" width="815"/><p>在 Eclipse IDE 中,“ JUnit”窗格清楚地显示了测试用例“ <strong> ScreenshotTest.java </strong>”已通过,并且控制台没有错误。</p><p>如代码中所指定,屏幕快照以上述格式的名称保存在“ <strong> E:/ Selenium / screenshots </strong>”路径中。</p><p><img alt="Saved Screenshot" class="alignnone size-full wp-image-13445" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2018/06/2_SavedScreenshot-1.jpg" height="257" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20669%20257'%3E%3C/svg%3E" width="669"/></p><noscript><img alt="Saved Screenshot" class="alignnone size-full wp-image-13445" height="257" src="img/a83607c72020b85243e2b2f56815046b.png" width="669"/><p>这是捕获的屏幕截图,</p><p><img alt="Captured Screenshot" class="alignnone size-full wp-image-13443" data-lazy-sizes="(max-width: 1033px) 100vw, 1033px" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2018/06/3_ScreenshotTaken.jpg" data-lazy-srcset="https://javabeginnerstutorial.com/wp-content/uploads/2018/06/3_ScreenshotTaken.jpg 1033w, https://javabeginnerstutorial.com/wp-content/uploads/2018/06/3_ScreenshotTaken-300x170.jpg 300w, https://javabeginnerstutorial.com/wp-content/uploads/2018/06/3_ScreenshotTaken-1024x582.jpg 1024w, https://javabeginnerstutorial.com/wp-content/uploads/2018/06/3_ScreenshotTaken-768x436.jpg 768w" height="587" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201033%20587'%3E%3C/svg%3E" width="1033"/></p><noscript><img alt="Captured Screenshot" class="alignnone size-full wp-image-13443" height="587" sizes="(max-width: 1033px) 100vw, 1033px" src="img/09ae5e35e176df55907d645952dba8b3.png" srcset="https://javabeginnerstutorial.com/wp-content/uploads/2018/06/3_ScreenshotTaken.jpg 1033w, https://javabeginnerstutorial.com/wp-content/uploads/2018/06/3_ScreenshotTaken-300x170.jpg 300w, https://javabeginnerstutorial.com/wp-content/uploads/2018/06/3_ScreenshotTaken-1024x582.jpg 1024w, https://javabeginnerstutorial.com/wp-content/uploads/2018/06/3_ScreenshotTaken-768x436.jpg 768w" width="1033"/><p>现在是时候在您的测试过程中实现这一点并为自己可视化魔术了。</p><p>Happy photographing the screen 😉</p><p> </p><div class="sticky-nav" style="font-size: 15px;"><div class="sticky-nav-image"></div><div class="sticky-nav-holder"><div class="sticky-nav_item"><h6 class="heading-sm">下一篇文章</h6></div><h5 class="sticky-nav_heading " style="font-size: 15px;"><a href="https://javabeginnerstutorial.com/selenium/10g-advanced-webdriver-saving-screenshots-to-word-document/" title="10g. Advanced WebDriver – Saving screenshots to a word document"> 10 克。 高级 WebDriver –将屏幕截图保存到 Word 文档</a></h5></div></div> </body> </html></noscript>
\ No newline at end of file
<noscript><img alt="Eclipse output" class="alignnone size-full wp-image-13444" height="362" src="img/d9bba1da5599720cb4111735fe851a62.png" width="815"/><p>在 Eclipse IDE 中,“ JUnit”窗格清楚地显示了测试用例“ <strong> ScreenshotTest.java </strong>”已通过,并且控制台没有错误。</p><p>如代码中所指定,屏幕快照以上述格式的名称保存在“ <strong> E:/ Selenium / screenshots </strong>”路径中。</p><p><img alt="Saved Screenshot" class="alignnone size-full wp-image-13445" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2018/06/2_SavedScreenshot-1.jpg" height="257" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20669%20257'%3E%3C/svg%3E" width="669"/></p><noscript><img alt="Saved Screenshot" class="alignnone size-full wp-image-13445" height="257" src="img/a83607c72020b85243e2b2f56815046b.png" width="669"/><p>这是捕获的屏幕截图,</p><p><img alt="Captured Screenshot" class="alignnone size-full wp-image-13443" data-lazy-sizes="(max-width: 1033px) 100vw, 1033px" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2018/06/3_ScreenshotTaken.jpg" data-lazy-srcset="https://javabeginnerstutorial.com/wp-content/uploads/2018/06/3_ScreenshotTaken.jpg 1033w, https://javabeginnerstutorial.com/wp-content/uploads/2018/06/3_ScreenshotTaken-300x170.jpg 300w, https://javabeginnerstutorial.com/wp-content/uploads/2018/06/3_ScreenshotTaken-1024x582.jpg 1024w, https://javabeginnerstutorial.com/wp-content/uploads/2018/06/3_ScreenshotTaken-768x436.jpg 768w" height="587" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201033%20587'%3E%3C/svg%3E" width="1033"/></p><noscript><img alt="Captured Screenshot" class="alignnone size-full wp-image-13443" height="587" sizes="(max-width: 1033px) 100vw, 1033px" src="img/09ae5e35e176df55907d645952dba8b3.png" srcset="https://javabeginnerstutorial.com/wp-content/uploads/2018/06/3_ScreenshotTaken.jpg 1033w, https://javabeginnerstutorial.com/wp-content/uploads/2018/06/3_ScreenshotTaken-300x170.jpg 300w, https://javabeginnerstutorial.com/wp-content/uploads/2018/06/3_ScreenshotTaken-1024x582.jpg 1024w, https://javabeginnerstutorial.com/wp-content/uploads/2018/06/3_ScreenshotTaken-768x436.jpg 768w" width="1033"/><p>现在是时候在您的测试过程中实现这一点并为自己可视化魔术了。</p><p>Happy photographing the screen 😉</p><p> </p><div class="sticky-nav" style="font-size: 15px;"><div class="sticky-nav-image"></div><div class="sticky-nav-holder"><div class="sticky-nav_item"><h6 class="heading-sm">下一篇文章</h6></div><h5 class="sticky-nav_heading " style="font-size: 15px;"><a href="https://javabeginnerstutorial.com/selenium/10g-advanced-webdriver-saving-screenshots-to-word-document/" title="10g. Advanced WebDriver – Saving screenshots to a word document"> 10 克。 高级 WebDriver – 将屏幕截图保存到 Word 文档</a></h5></div></div> </body> </html></noscript>
\ No newline at end of file
# 10 克 高级 WebDriver –将屏幕截图保存到 Word 文档
# 10 克 高级 WebDriver – 将屏幕截图保存到 Word 文档
> 原文: [https://javabeginnerstutorial.com/selenium/10g-advanced-webdriver-saving-screenshots-to-word-document/](https://javabeginnerstutorial.com/selenium/10g-advanced-webdriver-saving-screenshots-to-word-document/)
......@@ -12,7 +12,7 @@
**java2word-3.3.jar** -帮助我们创建 Word 文档并以所需方式对其进行操作。
**xstream-1.3.1.jar** –处理图片
**xstream-1.3.1.jar** 处理图片
让我们继续从 [https://code.google.com/archive/p/java2word/downloads](https://code.google.com/archive/p/java2word/downloads) (在撰写本文时的下载位置)下载这两个 JAR 文件。 我还将这些 JAR 以及本文中处理的所有其他代码文件一起放在我们的 [GitHub 存储库](https://github.com/JBTAdmin/Selenium)中。
......@@ -241,4 +241,4 @@ public class WordDocWithScreenshotTest {
![Document Eclipse output](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20810%20377'%3E%3C/svg%3E)
<noscript><img alt="Document Eclipse output" class="alignnone size-full wp-image-13504" height="377" src="img/cfe92b1c436c1f2d0946c238a4c772f1.png" width="810"/><p>在 Eclipse IDE 中,“ JUnit”窗格清楚地显示了测试用例“ <strong> WordDocWithScreenshotTest.java </strong>”已通过,并且控制台没有错误。 按预期打印“ Word 文档创建成功”。</p><p>按照代码中的指定,屏幕快照将以上述格式的名称保存到“ <strong> E:/ Selenium / screenshots </strong>”路径中。</p><p><img alt="Saved screenshots" class="alignnone size-full wp-image-13505" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2018/06/5_WordSavedScreenshots-1.jpg" height="239" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20389%20239'%3E%3C/svg%3E" width="389"/></p><noscript><img alt="Saved screenshots" class="alignnone size-full wp-image-13505" height="239" src="img/5c56b0f1090d7f365f904ce1cb7bc6d6.png" width="389"/><p>还将创建单词文档并将其保存在指定的位置“ <strong> E:/ Selenium / </strong>”中。 该文件如下所示,</p><p><img alt="Created Word Document" class="alignnone size-full wp-image-13503" data-lazy-sizes="(max-width: 1005px) 100vw, 1005px" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2018/06/6_WordCreatedDoc-1.jpg" data-lazy-srcset="https://javabeginnerstutorial.com/wp-content/uploads/2018/06/6_WordCreatedDoc-1.jpg 1005w, https://javabeginnerstutorial.com/wp-content/uploads/2018/06/6_WordCreatedDoc-1-300x185.jpg 300w, https://javabeginnerstutorial.com/wp-content/uploads/2018/06/6_WordCreatedDoc-1-768x473.jpg 768w" height="619" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201005%20619'%3E%3C/svg%3E" width="1005"/></p><noscript><img alt="Created Word Document" class="alignnone size-full wp-image-13503" height="619" sizes="(max-width: 1005px) 100vw, 1005px" src="img/c0e8c6605f52e31de7ba508ce15d0086.png" srcset="https://javabeginnerstutorial.com/wp-content/uploads/2018/06/6_WordCreatedDoc-1.jpg 1005w, https://javabeginnerstutorial.com/wp-content/uploads/2018/06/6_WordCreatedDoc-1-300x185.jpg 300w, https://javabeginnerstutorial.com/wp-content/uploads/2018/06/6_WordCreatedDoc-1-768x473.jpg 768w" width="1005"/><p>创建的 Word 文档,所有代码文件和 JAR 文件都放置在<a href="https://github.com/JBTAdmin/Selenium"> GitHub 存储库</a>中,以便于访问。 您可以为存储库加注星标和分支以方便使用。 请仔细阅读“ README.md”文件以获取明确说明。</p><p>编码愉快! 祝你今天愉快!</p><div class="sticky-nav" style="font-size: 15px;"><div class="sticky-nav-image"></div><div class="sticky-nav-holder"><div class="sticky-nav_item"><h6 class="heading-sm">下一篇文章</h6></div><h5 class="sticky-nav_heading " style="font-size: 15px;"><a href="https://javabeginnerstutorial.com/selenium/10h-advanced-webdriver-sending-email-with-attachments/" title="10h. Advanced WebDriver – Sending email with attachments"> 10 小时。 高级 WebDriver –发送带有附件的电子邮件</a></h5></div></div> </body> </html></noscript>
\ No newline at end of file
<noscript><img alt="Document Eclipse output" class="alignnone size-full wp-image-13504" height="377" src="img/cfe92b1c436c1f2d0946c238a4c772f1.png" width="810"/><p>在 Eclipse IDE 中,“ JUnit”窗格清楚地显示了测试用例“ <strong> WordDocWithScreenshotTest.java </strong>”已通过,并且控制台没有错误。 按预期打印“ Word 文档创建成功”。</p><p>按照代码中的指定,屏幕快照将以上述格式的名称保存到“ <strong> E:/ Selenium / screenshots </strong>”路径中。</p><p><img alt="Saved screenshots" class="alignnone size-full wp-image-13505" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2018/06/5_WordSavedScreenshots-1.jpg" height="239" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20389%20239'%3E%3C/svg%3E" width="389"/></p><noscript><img alt="Saved screenshots" class="alignnone size-full wp-image-13505" height="239" src="img/5c56b0f1090d7f365f904ce1cb7bc6d6.png" width="389"/><p>还将创建单词文档并将其保存在指定的位置“ <strong> E:/ Selenium / </strong>”中。 该文件如下所示,</p><p><img alt="Created Word Document" class="alignnone size-full wp-image-13503" data-lazy-sizes="(max-width: 1005px) 100vw, 1005px" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2018/06/6_WordCreatedDoc-1.jpg" data-lazy-srcset="https://javabeginnerstutorial.com/wp-content/uploads/2018/06/6_WordCreatedDoc-1.jpg 1005w, https://javabeginnerstutorial.com/wp-content/uploads/2018/06/6_WordCreatedDoc-1-300x185.jpg 300w, https://javabeginnerstutorial.com/wp-content/uploads/2018/06/6_WordCreatedDoc-1-768x473.jpg 768w" height="619" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201005%20619'%3E%3C/svg%3E" width="1005"/></p><noscript><img alt="Created Word Document" class="alignnone size-full wp-image-13503" height="619" sizes="(max-width: 1005px) 100vw, 1005px" src="img/c0e8c6605f52e31de7ba508ce15d0086.png" srcset="https://javabeginnerstutorial.com/wp-content/uploads/2018/06/6_WordCreatedDoc-1.jpg 1005w, https://javabeginnerstutorial.com/wp-content/uploads/2018/06/6_WordCreatedDoc-1-300x185.jpg 300w, https://javabeginnerstutorial.com/wp-content/uploads/2018/06/6_WordCreatedDoc-1-768x473.jpg 768w" width="1005"/><p>创建的 Word 文档,所有代码文件和 JAR 文件都放置在<a href="https://github.com/JBTAdmin/Selenium"> GitHub 存储库</a>中,以便于访问。 您可以为存储库加注星标和分支以方便使用。 请仔细阅读“ README.md”文件以获取明确说明。</p><p>编码愉快! 祝你今天愉快!</p><div class="sticky-nav" style="font-size: 15px;"><div class="sticky-nav-image"></div><div class="sticky-nav-holder"><div class="sticky-nav_item"><h6 class="heading-sm">下一篇文章</h6></div><h5 class="sticky-nav_heading " style="font-size: 15px;"><a href="https://javabeginnerstutorial.com/selenium/10h-advanced-webdriver-sending-email-with-attachments/" title="10h. Advanced WebDriver – Sending email with attachments"> 10 小时。 高级 WebDriver – 发送带有附件的电子邮件</a></h5></div></div> </body> </html></noscript>
\ No newline at end of file
# 10 小时 高级 WebDriver –发送带有附件的电子邮件
# 10 小时 高级 WebDriver – 发送带有附件的电子邮件
> 原文: [https://javabeginnerstutorial.com/selenium/10h-advanced-webdriver-sending-email-with-attachments/](https://javabeginnerstutorial.com/selenium/10h-advanced-webdriver-sending-email-with-attachments/)
......@@ -6,8 +6,8 @@
我们将研究两个课程。
1. SendMail.java –此类包含用于发送电子邮件的所有代码。
2. InvokeMail.java –通过提供从地址到地址,主题行和一些文本来调用 SendMail.java。
1. SendMail.java – 此类包含用于发送电子邮件的所有代码。
2. InvokeMail.java – 通过提供从地址到地址,主题行和一些文本来调用 SendMail.java。
## **代码**
......@@ -241,4 +241,4 @@ SendMail.send("[[email protected]](/cdn-cgi/l/email-protection)", to, "JUnit Re
![Email eclipse console output](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20499%20131'%3E%3C/svg%3E)
<noscript><img alt="Email eclipse console output" class="alignnone size-full wp-image-13546" height="131" src="img/f86911f5f3e724f4f0f756b02cbb24e2.png" width="499"/><p>该电子邮件将在收件人的收件箱中接收。</p><p><img alt="Email received in Inbox" class="alignnone size-full wp-image-13545" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2018/06/1_EmailReceivedInbox-1.jpg" height="298" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201282%20298'%3E%3C/svg%3E" width="1282"/></p><noscript><img alt="Email received in Inbox" class="alignnone size-full wp-image-13545" height="298" src="img/dc54350168b4d2d375448a69dcdf1262.png" width="1282"/><p>显示生成的带有附件的电子邮件,以供您参考。</p><p><img alt="Generated email" class="alignnone size-full wp-image-13547" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2018/06/3_GeneratedEmail-1.jpg" height="525" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20917%20525'%3E%3C/svg%3E" width="917"/></p><noscript><img alt="Generated email" class="alignnone size-full wp-image-13547" height="525" src="img/ec66e3d16d437df63174e68a50e156cb.png" width="917"/><p><strong> <em>即时贴:</em> </strong> <em>当心! 您可能碰到“ <strong> javax.mail.AuthenticationFailedException </strong>”。 发生此异常的主要原因是 Google 提供的安全性和保护功能。 一种简单的解决方法是,通过单击链接<a href="https://www.google.com/settings/security/lesssecureapps"> https://www.google.com/settings/security/lesssecureapps </a>来打开“允许安全程度较低的应用程序”的访问以进行测试。 </em></p><p>试试看,让我知道在拍摄电子邮件时是否遇到任何问题。</p><p>实验愉快! 祝你今天愉快!</p><div class="sticky-nav" style="font-size: 15px;"><div class="sticky-nav-image"></div><div class="sticky-nav-holder"><div class="sticky-nav_item"><h6 class="heading-sm">下一篇文章</h6></div><h5 class="sticky-nav_heading " style="font-size: 15px;"><a href="https://javabeginnerstutorial.com/selenium/10i-advanced-webdriver-property-files/" title="10i. Advanced WebDriver – Using property files"> 10i。 高级 WebDriver –使用属性文件</a></h5></div></div> </body> </html></noscript>
\ No newline at end of file
<noscript><img alt="Email eclipse console output" class="alignnone size-full wp-image-13546" height="131" src="img/f86911f5f3e724f4f0f756b02cbb24e2.png" width="499"/><p>该电子邮件将在收件人的收件箱中接收。</p><p><img alt="Email received in Inbox" class="alignnone size-full wp-image-13545" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2018/06/1_EmailReceivedInbox-1.jpg" height="298" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201282%20298'%3E%3C/svg%3E" width="1282"/></p><noscript><img alt="Email received in Inbox" class="alignnone size-full wp-image-13545" height="298" src="img/dc54350168b4d2d375448a69dcdf1262.png" width="1282"/><p>显示生成的带有附件的电子邮件,以供您参考。</p><p><img alt="Generated email" class="alignnone size-full wp-image-13547" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2018/06/3_GeneratedEmail-1.jpg" height="525" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20917%20525'%3E%3C/svg%3E" width="917"/></p><noscript><img alt="Generated email" class="alignnone size-full wp-image-13547" height="525" src="img/ec66e3d16d437df63174e68a50e156cb.png" width="917"/><p><strong> <em>即时贴:</em> </strong> <em>当心! 您可能碰到“ <strong> javax.mail.AuthenticationFailedException </strong>”。 发生此异常的主要原因是 Google 提供的安全性和保护功能。 一种简单的解决方法是,通过单击链接<a href="https://www.google.com/settings/security/lesssecureapps"> https://www.google.com/settings/security/lesssecureapps </a>来打开“允许安全程度较低的应用程序”的访问以进行测试。 </em></p><p>试试看,让我知道在拍摄电子邮件时是否遇到任何问题。</p><p>实验愉快! 祝你今天愉快!</p><div class="sticky-nav" style="font-size: 15px;"><div class="sticky-nav-image"></div><div class="sticky-nav-holder"><div class="sticky-nav_item"><h6 class="heading-sm">下一篇文章</h6></div><h5 class="sticky-nav_heading " style="font-size: 15px;"><a href="https://javabeginnerstutorial.com/selenium/10i-advanced-webdriver-property-files/" title="10i. Advanced WebDriver – Using property files"> 10i。 高级 WebDriver – 使用属性文件</a></h5></div></div> </body> </html></noscript>
\ No newline at end of file
此差异已折叠。
# 10j。 高级 WebDriver –使用 POI 从 excel 读取数据
# 10j。 高级 WebDriver – 使用 POI 从 excel 读取数据
> 原文: [https://javabeginnerstutorial.com/selenium/10j-advanced-webdriver-reading-data-from-excel-using-poi/](https://javabeginnerstutorial.com/selenium/10j-advanced-webdriver-reading-data-from-excel-using-poi/)
......@@ -12,4 +12,4 @@
![POI download link](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20859%20433'%3E%3C/svg%3E)
<noscript><img alt="POI download link" class="alignnone size-full wp-image-13586" height="433" sizes="(max-width: 859px) 100vw, 859px" src="img/66dde6eb58d06604bfe3993478f8010c.png" srcset="https://javabeginnerstutorial.com/wp-content/uploads/2018/07/1_DownloadLink.jpg 859w, https://javabeginnerstutorial.com/wp-content/uploads/2018/07/1_DownloadLink-300x151.jpg 300w, https://javabeginnerstutorial.com/wp-content/uploads/2018/07/1_DownloadLink-768x387.jpg 768w" width="859"/><h2><strong>步骤 2:</strong></h2><p>将这些 JAR 添加到我们的项目构建路径中。 确保选择“ poi-x.xx”,“ ooxml-lib”和“ lib”文件夹下的所有 JAR。 我还将这些以及其他所有代码文件都放在了我们的<a href="https://github.com/JBTAdmin/Selenium/tree/master/AdvancedWebDriver/Reading%20data%20from%20excel"> GitHub 存储库</a>中。</p><p>我们之前已经多次看到这种添加 JAR 来构建路径过程的内容,因此我没有在重复它(有关详细说明,请参阅此<a href="https://javabeginnerstutorial.com/selenium/9b-webdriver-eclipse-setup/">文章</a>的步骤 3)。</p><h2><strong>步骤 3:</strong></h2><p>创建一个新类“ <strong> ExcelOperationsUsingPOI.java </strong>”。 在此类中,让我们有一种从特定位置读取 excel 文件的特定图纸的方法。</p><ul><li>通过传递您要打开的 excel 文件的完整文件路径来创建 File 类的对象-<code data-enlighter-language="java">File file = new File(filePath+"\\"+fileName); </code></li><li>下一步是创建一个<em> FileInputStream </em>对象,以获取 excel 文件的输入字节-<code data-enlighter-language="java">FileInputStream inputStream = new FileInputStream(file); </code></li><li>创建一个工作簿对象-<code data-enlighter-language="java">Workbook myWorkbook = null; </code></li><li>Excel 文件在大多数情况下可以具有两个扩展名。 “ .xls”或“ .xlsx”。 通过使用子字符串方法拆分文件名来找到扩展名,并相应地创建 Workbook 对象。</li></ul><pre><code class="language-java">//indexOf gives the index of . in the file name //substring method splits the string starting from index of . to the end String fileExtensionName = fileName.substring(fileName.indexOf(".")); //Check condition if the file is xlsx file if(fileExtensionName.equals(".xlsx")){ //If it is xlsx file then create object of XSSFWorkbook class myWorkbook = new XSSFWorkbook(inputStream); } //Check condition if the file is xls file else if(fileExtensionName.equals(".xls")){ //If it is xls file then create object of HSSFWorkbook class myWorkbook = new HSSFWorkbook(inputStream); }</code></pre><ul><li>使用传递的确切工作表名称,可以读取特定工作表-<code data-enlighter-language="java">Sheet mySheet = myWorkbook.getSheet(sheetName); </code></li></ul><p>现在,使用行和列很容易,它们的交点将为我们提供我们希望读取的单元格内容。</p><p>现在让我们来看一下实现到目前为止讨论的全部功能的代码,</p><h3><strong> ExcelOperationsUsingPOI.java </strong></h3><pre><code class="language-java">import java.io.File; import java.io.FileInputStream; import java.io.IOException; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook; public class ExcelOperationsUsingPOI { public static void readExcel(String filePath,String fileName,String sheetName) throws IOException{ //Create a object of File class to open xlsx file File file = new File(filePath+"\\"+fileName); //Create an object of FileInputStream class to read excel file FileInputStream inputStream = new FileInputStream(file); Workbook myWorkbook = null; //Find the file extension by spliting file name in substring and getting only extension name //indexOf gives the index of . in the file name //substring method splits the string starting from index of . to the end String fileExtensionName = fileName.substring(fileName.indexOf(".")); //Check condition if the file is xlsx file if(fileExtensionName.equals(".xlsx")){ //If it is xlsx file then create object of XSSFWorkbook class myWorkbook = new XSSFWorkbook(inputStream); } //Check condition if the file is xls file else if(fileExtensionName.equals(".xls")){ //If it is xls file then create object of HSSFWorkbook class myWorkbook = new HSSFWorkbook(inputStream); } //Read sheet inside the workbook by its name Sheet mySheet = myWorkbook.getSheet(sheetName); //Find number of rows in excel file int rowCount = mySheet.getLastRowNum()- mySheet.getFirstRowNum(); //Create a loop over all the rows of excel file to read it for (int i = 0; i &lt; rowCount+1; i++) { Row row = mySheet.getRow(i); //Create a loop to print cell values in a row for (int j = 0; j &lt; row.getLastCellNum(); j++) { //Print excel data in console System.out.print(row.getCell(j).getStringCellValue()+"|| "); } System.out.println(); } } }</code></pre><h3><strong> ReadExcelData.java </strong></h3><p>用于调用 readExcel 方法并传递必需的参数。</p><pre><code class="language-java">import java.io.IOException; import com.blog.utility.ExcelOperationsUsingPOI; public class ReadExcelData { public static void main(String[] args) { try { ExcelOperationsUsingPOI.readExcel("E:\\Selenium", "ReadUsingPOI.xlsx", "Demographics"); } catch (IOException e) { e.printStackTrace(); } } }</code></pre><p><span class="ezoic-adpicker-ad" id="ezoic-pub-ad-placeholder-124"> </span> <span class="ezoic-ad box-4 adtester-container adtester-container-124" data-ez-name="javabeginnerstutorial_com-box-4" style="display:block !important;float:none;margin-bottom:2px !important;margin-left:0px !important;margin-right:0px !important;margin-top:2px !important;min-height:110px;min-width:728px;text-align:center !important;"> <span class="ezoic-ad ezoic-adl" ezah="90" ezaw="728" id="div-gpt-ad-javabeginnerstutorial_com-box-4-0" style="position:relative;z-index:0;display:inline-block;min-height:90px;min-width:728px;"> </span> </span>注释使代码不言自明。 所考虑的 Excel 工作表中的数据如下所示,</p><p><img alt="Excel Sheet" class="alignnone size-full wp-image-13588" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2018/07/3_ExcelSheet.jpg" height="287" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20357%20287'%3E%3C/svg%3E" width="357"/></p><noscript><img alt="Excel Sheet" class="alignnone size-full wp-image-13588" height="287" src="img/86b09846221b07ad4f56bd5bde566b64.png" width="357"/><p>使用我们的代码访问此信息将按预期方式打印出所有用管道分隔的值,以便将其控制台。</p><p><img alt="excel console output" class="alignnone size-full wp-image-13587" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2018/07/2_ConsoleOutput.jpg" height="177" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20450%20177'%3E%3C/svg%3E" width="450"/></p><noscript><img alt="excel console output" class="alignnone size-full wp-image-13587" height="177" src="img/afeb40dbbf98d4b1f60208d231d21f9c.png" width="450"/><p>如果您想检索代码段,请在注释部分大声疾呼,</p><ol><li>给定条目的从零开始的行和列索引</li><li>使用给定的从零开始的行和列索引的值</li><li>基于给定条目的列表中的所有行值</li><li>基于给定条目的列表中的所有列值</li></ol><p>试用这些功能,让我知道您是否遇到颠簸。</p><p>祝你今天愉快!</p><div class="sticky-nav" style="font-size: 15px;"><div class="sticky-nav-image"></div><div class="sticky-nav-holder"><div class="sticky-nav_item"><h6 class="heading-sm">下一篇文章</h6></div><h5 class="sticky-nav_heading " style="font-size: 15px;"><a href="https://javabeginnerstutorial.com/selenium/10k-advanced-webdriver-using-log4j-part-1/" title="10k. Advanced WebDriver – Using Log4j Part 1"> 10k。 高级 WebDriver –使用 Log4j 第 1 部分</a></h5></div></div> </body> </html></noscript>
\ No newline at end of file
<noscript><img alt="POI download link" class="alignnone size-full wp-image-13586" height="433" sizes="(max-width: 859px) 100vw, 859px" src="img/66dde6eb58d06604bfe3993478f8010c.png" srcset="https://javabeginnerstutorial.com/wp-content/uploads/2018/07/1_DownloadLink.jpg 859w, https://javabeginnerstutorial.com/wp-content/uploads/2018/07/1_DownloadLink-300x151.jpg 300w, https://javabeginnerstutorial.com/wp-content/uploads/2018/07/1_DownloadLink-768x387.jpg 768w" width="859"/><h2><strong>步骤 2:</strong></h2><p>将这些 JAR 添加到我们的项目构建路径中。 确保选择“ poi-x.xx”,“ ooxml-lib”和“ lib”文件夹下的所有 JAR。 我还将这些以及其他所有代码文件都放在了我们的<a href="https://github.com/JBTAdmin/Selenium/tree/master/AdvancedWebDriver/Reading%20data%20from%20excel"> GitHub 存储库</a>中。</p><p>我们之前已经多次看到这种添加 JAR 来构建路径过程的内容,因此我没有在重复它(有关详细说明,请参阅此<a href="https://javabeginnerstutorial.com/selenium/9b-webdriver-eclipse-setup/">文章</a>的步骤 3)。</p><h2><strong>步骤 3:</strong></h2><p>创建一个新类“ <strong> ExcelOperationsUsingPOI.java </strong>”。 在此类中,让我们有一种从特定位置读取 excel 文件的特定图纸的方法。</p><ul><li>通过传递您要打开的 excel 文件的完整文件路径来创建 File 类的对象-<code data-enlighter-language="java">File file = new File(filePath+"\\"+fileName); </code></li><li>下一步是创建一个<em> FileInputStream </em>对象,以获取 excel 文件的输入字节-<code data-enlighter-language="java">FileInputStream inputStream = new FileInputStream(file); </code></li><li>创建一个工作簿对象-<code data-enlighter-language="java">Workbook myWorkbook = null; </code></li><li>Excel 文件在大多数情况下可以具有两个扩展名。 “ .xls”或“ .xlsx”。 通过使用子字符串方法拆分文件名来找到扩展名,并相应地创建 Workbook 对象。</li></ul><pre><code class="language-java">//indexOf gives the index of . in the file name //substring method splits the string starting from index of . to the end String fileExtensionName = fileName.substring(fileName.indexOf(".")); //Check condition if the file is xlsx file if(fileExtensionName.equals(".xlsx")){ //If it is xlsx file then create object of XSSFWorkbook class myWorkbook = new XSSFWorkbook(inputStream); } //Check condition if the file is xls file else if(fileExtensionName.equals(".xls")){ //If it is xls file then create object of HSSFWorkbook class myWorkbook = new HSSFWorkbook(inputStream); }</code></pre><ul><li>使用传递的确切工作表名称,可以读取特定工作表-<code data-enlighter-language="java">Sheet mySheet = myWorkbook.getSheet(sheetName); </code></li></ul><p>现在,使用行和列很容易,它们的交点将为我们提供我们希望读取的单元格内容。</p><p>现在让我们来看一下实现到目前为止讨论的全部功能的代码,</p><h3><strong> ExcelOperationsUsingPOI.java </strong></h3><pre><code class="language-java">import java.io.File; import java.io.FileInputStream; import java.io.IOException; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook; public class ExcelOperationsUsingPOI { public static void readExcel(String filePath,String fileName,String sheetName) throws IOException{ //Create a object of File class to open xlsx file File file = new File(filePath+"\\"+fileName); //Create an object of FileInputStream class to read excel file FileInputStream inputStream = new FileInputStream(file); Workbook myWorkbook = null; //Find the file extension by spliting file name in substring and getting only extension name //indexOf gives the index of . in the file name //substring method splits the string starting from index of . to the end String fileExtensionName = fileName.substring(fileName.indexOf(".")); //Check condition if the file is xlsx file if(fileExtensionName.equals(".xlsx")){ //If it is xlsx file then create object of XSSFWorkbook class myWorkbook = new XSSFWorkbook(inputStream); } //Check condition if the file is xls file else if(fileExtensionName.equals(".xls")){ //If it is xls file then create object of HSSFWorkbook class myWorkbook = new HSSFWorkbook(inputStream); } //Read sheet inside the workbook by its name Sheet mySheet = myWorkbook.getSheet(sheetName); //Find number of rows in excel file int rowCount = mySheet.getLastRowNum()- mySheet.getFirstRowNum(); //Create a loop over all the rows of excel file to read it for (int i = 0; i &lt; rowCount+1; i++) { Row row = mySheet.getRow(i); //Create a loop to print cell values in a row for (int j = 0; j &lt; row.getLastCellNum(); j++) { //Print excel data in console System.out.print(row.getCell(j).getStringCellValue()+"|| "); } System.out.println(); } } }</code></pre><h3><strong> ReadExcelData.java </strong></h3><p>用于调用 readExcel 方法并传递必需的参数。</p><pre><code class="language-java">import java.io.IOException; import com.blog.utility.ExcelOperationsUsingPOI; public class ReadExcelData { public static void main(String[] args) { try { ExcelOperationsUsingPOI.readExcel("E:\\Selenium", "ReadUsingPOI.xlsx", "Demographics"); } catch (IOException e) { e.printStackTrace(); } } }</code></pre><p><span class="ezoic-adpicker-ad" id="ezoic-pub-ad-placeholder-124"> </span> <span class="ezoic-ad box-4 adtester-container adtester-container-124" data-ez-name="javabeginnerstutorial_com-box-4" style="display:block !important;float:none;margin-bottom:2px !important;margin-left:0px !important;margin-right:0px !important;margin-top:2px !important;min-height:110px;min-width:728px;text-align:center !important;"> <span class="ezoic-ad ezoic-adl" ezah="90" ezaw="728" id="div-gpt-ad-javabeginnerstutorial_com-box-4-0" style="position:relative;z-index:0;display:inline-block;min-height:90px;min-width:728px;"> </span> </span>注释使代码不言自明。 所考虑的 Excel 工作表中的数据如下所示,</p><p><img alt="Excel Sheet" class="alignnone size-full wp-image-13588" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2018/07/3_ExcelSheet.jpg" height="287" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20357%20287'%3E%3C/svg%3E" width="357"/></p><noscript><img alt="Excel Sheet" class="alignnone size-full wp-image-13588" height="287" src="img/86b09846221b07ad4f56bd5bde566b64.png" width="357"/><p>使用我们的代码访问此信息将按预期方式打印出所有用管道分隔的值,以便将其控制台。</p><p><img alt="excel console output" class="alignnone size-full wp-image-13587" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2018/07/2_ConsoleOutput.jpg" height="177" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20450%20177'%3E%3C/svg%3E" width="450"/></p><noscript><img alt="excel console output" class="alignnone size-full wp-image-13587" height="177" src="img/afeb40dbbf98d4b1f60208d231d21f9c.png" width="450"/><p>如果您想检索代码段,请在注释部分大声疾呼,</p><ol><li>给定条目的从零开始的行和列索引</li><li>使用给定的从零开始的行和列索引的值</li><li>基于给定条目的列表中的所有行值</li><li>基于给定条目的列表中的所有列值</li></ol><p>试用这些功能,让我知道您是否遇到颠簸。</p><p>祝你今天愉快!</p><div class="sticky-nav" style="font-size: 15px;"><div class="sticky-nav-image"></div><div class="sticky-nav-holder"><div class="sticky-nav_item"><h6 class="heading-sm">下一篇文章</h6></div><h5 class="sticky-nav_heading " style="font-size: 15px;"><a href="https://javabeginnerstutorial.com/selenium/10k-advanced-webdriver-using-log4j-part-1/" title="10k. Advanced WebDriver – Using Log4j Part 1"> 10k。 高级 WebDriver – 使用 Log4j 第 1 部分</a></h5></div></div> </body> </html></noscript>
\ No newline at end of file
# 10k。 高级 WebDriver –使用 Log4j 第 1 部分
# 10k。 高级 WebDriver – 使用 Log4j 第 1 部分
> 原文: [https://javabeginnerstutorial.com/selenium/10k-advanced-webdriver-using-log4j-part-1/](https://javabeginnerstutorial.com/selenium/10k-advanced-webdriver-using-log4j-part-1/)
......@@ -20,19 +20,19 @@
1. 1996 年开发的基于 Java 的流行日志记录程序包
2. 根据 Apache Software License 分发,因此它是开源的
3. 具有各种级别的日志记录允许我们控制日志输出的数量
3. 具有各种级别的日志记录允许我们控制日志输出的数量
4. 一切都可以通过编辑简单的配置文件来控制-无需理会应用程序二进制文件
## Log4j 日志级别
以下是 Log4j 附带的内置日志级别。
1. **OFF** –关闭登录
2. **致命** –严重错误导致应用终止
3. **错误** –意外情况和运行时错误
4. **WARN** –警告消息
5. **信息** –提供有关一些有趣的运行时事件的信息
6. **DEBUG** –最常用的日志级别,提供有关系统流程的详细信息
1. **OFF** 关闭登录
2. **致命** 严重错误导致应用终止
3. **错误** 意外情况和运行时错误
4. **WARN** 警告消息
5. **信息** 提供有关一些有趣的运行时事件的信息
6. **DEBUG** 最常用的日志级别,提供有关系统流程的详细信息
7. **跟踪**-信息的详细程度最高
## Log4j 组件
......@@ -53,9 +53,9 @@
既然我们知道如何生成日志并将其保存到特定的目的地,那么我们可能需要将它们呈现为不同的格式。 每个 Appender 必须映射到特定布局。 一些常用的布局是
* **PatternLayout** –使用模式字符串的一次一行日志文件
* **HTMLLayout** –以 HTML 格式呈现日志
* **XMLLayout** –生成 XML 格式
* **PatternLayout** 使用模式字符串的一次一行日志文件
* **HTMLLayout** 以 HTML 格式呈现日志
* **XMLLayout** 生成 XML 格式
## Log4j 配置
......@@ -71,4 +71,4 @@
![download Apache Log4j](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20657%20634'%3E%3C/svg%3E)
<noscript><img alt="download Apache Log4j" class="alignnone size-full wp-image-14225" height="634" src="img/4d0bd0a2cc1db2cb7f03718ef5c12931.png" width="657"/><p>将下载文件夹的内容提取到特定位置。</p><h3>步骤 2:配置 Java 构建路径</h3><p>将 Log4j JAR 作为外部库添加到项目的构建路径。</p><p>让我们导航到本地计算机中提取下载的 JAR 的路径,并将其添加为外部 JAR。</p><p><img alt="JAR selection window" class="alignnone size-full wp-image-14226" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2019/05/2_JarSelection-1.jpg" height="318" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20502%20318'%3E%3C/svg%3E" width="502"/></p><noscript><img alt="JAR selection window" class="alignnone size-full wp-image-14226" height="318" src="img/c027190f02b422719b9633917ff29b9d.png" width="502"/><p>之前,我们已经多次看到此过程,因此,我不再重复(请参阅<a href="https://javabeginnerstutorial.com/selenium/9b-webdriver-eclipse-setup/">文章</a>的步骤 3)。</p><h3>步骤 3:建立必要的档案</h3><p>我们将创建 3 个文件。</p><p><strong> Log4j.properties </strong></p><ul><li>右键单击“ src”文件夹-&gt;新建-&gt;其他-&gt;常规-&gt;文件-&gt;下一页</li><li>提供“文件名”作为“ Log4j.properties”,然后点击“完成”</li></ul><p>结果看起来像这样,</p><p><img alt="Log4j.properties file creation" class="alignnone size-full wp-image-14227" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2019/05/3_property-file-creation.jpg" height="186" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20323%20186'%3E%3C/svg%3E" width="323"/></p><noscript><img alt="Log4j.properties file creation" class="alignnone size-full wp-image-14227" height="186" src="img/e27b7184646bb1e673729341bb77e0f8.png" width="323"/><p>我现在已经忽略了三个额外的程序包,因为我出于编码目的创建了它们。</p><p><strong>日志文件</strong></p><ul><li>右键单击“ src”文件夹-&gt;新建-&gt;其他-&gt;常规-&gt;文件夹-&gt;下一页</li><li>提供“文件夹名称”作为“资源”</li><li>右键点击“资源”文件夹并创建两个文件</li><li>将这些文件命名为“ system.log”和“ test.log”</li></ul><ol><li><strong> system.log </strong> –将具有系统生成的所有日志</li><li><strong> test.log </strong> –将包含由于用户提供的手动命令而生成的所有日志</li></ol><p><img alt="Log files created" class="alignnone size-full wp-image-14228" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2019/05/4_log-files.jpg" height="341" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20275%20341'%3E%3C/svg%3E" width="275"/></p><noscript><img alt="Log files created" class="alignnone size-full wp-image-14228" height="341" src="img/7dbb8f2542d3154b6359132207b4d7b9.png" width="275"/><p>现在,所有环境都已准备就绪,我们可以使用 Log4j 进行一些实验并生成日志。 与往常一样,将 JAR 放置在 GitHub <a href="https://github.com/JBTAdmin/Selenium/tree/master/AdvancedWebDriver">存储库</a>中。 让我们在即将发布的帖子中详细了解这一点。</p><div class="sticky-nav" style="font-size: 15px;"><div class="sticky-nav-image"></div><div class="sticky-nav-holder"><div class="sticky-nav_item"><h6 class="heading-sm">下一篇文章</h6></div><h5 class="sticky-nav_heading " style="font-size: 15px;"><a href="https://javabeginnerstutorial.com/selenium/10l-advanced-webdriver-using-log4j-part-2/" title="10l. Advanced WebDriver – Using Log4j Part 2"> 10 升。 高级 WebDriver –使用 Log4j 第 2 部分</a></h5></div></div> </body> </html></noscript>
\ No newline at end of file
<noscript><img alt="download Apache Log4j" class="alignnone size-full wp-image-14225" height="634" src="img/4d0bd0a2cc1db2cb7f03718ef5c12931.png" width="657"/><p>将下载文件夹的内容提取到特定位置。</p><h3>步骤 2:配置 Java 构建路径</h3><p>将 Log4j JAR 作为外部库添加到项目的构建路径。</p><p>让我们导航到本地计算机中提取下载的 JAR 的路径,并将其添加为外部 JAR。</p><p><img alt="JAR selection window" class="alignnone size-full wp-image-14226" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2019/05/2_JarSelection-1.jpg" height="318" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20502%20318'%3E%3C/svg%3E" width="502"/></p><noscript><img alt="JAR selection window" class="alignnone size-full wp-image-14226" height="318" src="img/c027190f02b422719b9633917ff29b9d.png" width="502"/><p>之前,我们已经多次看到此过程,因此,我不再重复(请参阅<a href="https://javabeginnerstutorial.com/selenium/9b-webdriver-eclipse-setup/">文章</a>的步骤 3)。</p><h3>步骤 3:建立必要的档案</h3><p>我们将创建 3 个文件。</p><p><strong> Log4j.properties </strong></p><ul><li>右键单击“ src”文件夹-&gt;新建-&gt;其他-&gt;常规-&gt;文件-&gt;下一页</li><li>提供“文件名”作为“ Log4j.properties”,然后点击“完成”</li></ul><p>结果看起来像这样,</p><p><img alt="Log4j.properties file creation" class="alignnone size-full wp-image-14227" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2019/05/3_property-file-creation.jpg" height="186" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20323%20186'%3E%3C/svg%3E" width="323"/></p><noscript><img alt="Log4j.properties file creation" class="alignnone size-full wp-image-14227" height="186" src="img/e27b7184646bb1e673729341bb77e0f8.png" width="323"/><p>我现在已经忽略了三个额外的程序包,因为我出于编码目的创建了它们。</p><p><strong>日志文件</strong></p><ul><li>右键单击“ src”文件夹-&gt;新建-&gt;其他-&gt;常规-&gt;文件夹-&gt;下一页</li><li>提供“文件夹名称”作为“资源”</li><li>右键点击“资源”文件夹并创建两个文件</li><li>将这些文件命名为“ system.log”和“ test.log”</li></ul><ol><li><strong> system.log </strong> – 将具有系统生成的所有日志</li><li><strong> test.log </strong> – 将包含由于用户提供的手动命令而生成的所有日志</li></ol><p><img alt="Log files created" class="alignnone size-full wp-image-14228" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2019/05/4_log-files.jpg" height="341" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20275%20341'%3E%3C/svg%3E" width="275"/></p><noscript><img alt="Log files created" class="alignnone size-full wp-image-14228" height="341" src="img/7dbb8f2542d3154b6359132207b4d7b9.png" width="275"/><p>现在,所有环境都已准备就绪,我们可以使用 Log4j 进行一些实验并生成日志。 与往常一样,将 JAR 放置在 GitHub <a href="https://github.com/JBTAdmin/Selenium/tree/master/AdvancedWebDriver">存储库</a>中。 让我们在即将发布的帖子中详细了解这一点。</p><div class="sticky-nav" style="font-size: 15px;"><div class="sticky-nav-image"></div><div class="sticky-nav-holder"><div class="sticky-nav_item"><h6 class="heading-sm">下一篇文章</h6></div><h5 class="sticky-nav_heading " style="font-size: 15px;"><a href="https://javabeginnerstutorial.com/selenium/10l-advanced-webdriver-using-log4j-part-2/" title="10l. Advanced WebDriver – Using Log4j Part 2"> 10 升。 高级 WebDriver – 使用 Log4j 第 2 部分</a></h5></div></div> </body> </html></noscript>
\ No newline at end of file
# 10 升 高级 WebDriver –使用 Log4j 第 2 部分
# 10 升 高级 WebDriver – 使用 Log4j 第 2 部分
> 原文: [https://javabeginnerstutorial.com/selenium/10l-advanced-webdriver-using-log4j-part-2/](https://javabeginnerstutorial.com/selenium/10l-advanced-webdriver-using-log4j-part-2/)
......@@ -7,10 +7,10 @@
**场景**
1. 配置 Log4j.properties 文件,
* 日志级别调试
* 记录器– rootLogger 和 SeleniumTestLogger
* 日志级别调试
* 记录器 – rootLogger 和 SeleniumTestLogger
* Appender – RollingFileAppender
* 布局– PatternLayout
* 布局 – PatternLayout
2. 编写一个 JUnit4 测试用例“ Log4jTest.java”,
* 开启 Chrome 浏览器。
* 导航到[演示站点](https://chandanachaitanya.github.io/selenium-practice-site/)
......@@ -57,39 +57,39 @@ log4j.appender.dest.Append=false
我们将有两个记录器,
1. **rootLogger** –处理系统生成的日志,并将它们输出到 **system.log** 文件,然后
2. **SeleniumTestLogger** –处理由于用户手动插入代码而生成的日志,并输出到 **test.log** 文件
1. **rootLogger** 处理系统生成的日志,并将它们输出到 **system.log** 文件,然后
2. **SeleniumTestLogger** 处理由于用户手动插入代码而生成的日志,并输出到 **test.log** 文件
这两个记录器都将具有 RollingFileAppender 和 PatterLayout。
`log4j.rootLogger=debug,file` –日志级别指定为`debug``file`用作引用此特定记录器的标识符。
`log4j.rootLogger=debug,file` 日志级别指定为`debug``file`用作引用此特定记录器的标识符。
`log4j.appender.file=org.apache.log4j.RollingFileAppender``RollingFileAppender`是使用的附加程序类型,它将指定的文件附加到最大大小。
`log4j.appender.file.File=E:\\Selenium\\resources\\system.log``File`用于指定要保存日志的文件的位置,即目的地。
`log4j.appender.file.maxFileSize=900KB` –一个文件最多可以存储 900KB 的数据,然后创建一个具有相同名称的新文件。 较旧的文件将作为索引添加到最新的文件。
`log4j.appender.file.maxFileSize=900KB` 一个文件最多可以存储 900KB 的数据,然后创建一个具有相同名称的新文件。 较旧的文件将作为索引添加到最新的文件。
`log4j.appender.file.maxBackupIndex=3` –最多将保存三个文件作为备份。
`log4j.appender.file.maxBackupIndex=3` 最多将保存三个文件作为备份。
`log4j.appender.file.layout=org.apache.log4j.PatternLayout``Pattern layout`用于格式化生成的日志。
`log4j.appender.dest.layout.ConversionPattern=%d{dd/MM/yyyy HH:mm:ss} %c %m%n` –这是用于生成布局的转换模式。
`log4j.appender.dest.layout.ConversionPattern=%d{dd/MM/yyyy HH:mm:ss} %c %m%n` 这是用于生成布局的转换模式。
生成的示例测试日志如下(片段),
`16/05/2019 22:18:17 SeleniumTestLogger Log4jTest executed successfully`
* `dd/MM/yyyy` –日期
* `HH:mm:ss` –执行时间
* `%c` –打印作为参数传递给 Logger 实例的名称
* `%m%n` –日志消息
* `dd/MM/yyyy` 日期
* `HH:mm:ss` 执行时间
* `%c` 打印作为参数传递给 Logger 实例的名称
* `%m%n` 日志消息
`log4j.appender.file.Append=false` –将此属性设置为 false 将创建一个新文件,而不是更新现有文件。
`log4j.appender.file.Append=false` 将此属性设置为 false 将创建一个新文件,而不是更新现有文件。
`log4j.logger.SeleniumTestLogger=DEBUG, dest` –日志级别为`debug``dest`是此处使用的标识符。
`log4j.logger.SeleniumTestLogger=DEBUG, dest` 日志级别为`debug``dest`是此处使用的标识符。
`log4j.appender.dest.File=E:\\Selenium\\resources\\test.log` –借助`File`来指定`dest`标识符的文件位置。
`log4j.appender.dest.File=E:\\Selenium\\resources\\test.log` 借助`File`来指定`dest`标识符的文件位置。
其他属性与我们已经讨论过的相似,因此不言自明。
......@@ -164,11 +164,11 @@ public class Log4jTest {
}
```
`import org.apache.log4j.Logger;` –记录程序包已导入。
`import org.apache.log4j.Logger;` 记录程序包已导入。
`log = Logger.getLogger("SeleniumTestLogger");` –创建一个名为的实例,记录 Logger 类并传递“ SeleniumTestLogger”作为参数。
`log = Logger.getLogger("SeleniumTestLogger");` 创建一个名为的实例,记录 Logger 类并传递“ SeleniumTestLogger”作为参数。
`log.debug("opening selenium-practice-site");` –此语句将记录在`DEBUG`级别中用双引号引起的消息。
`log.debug("opening selenium-practice-site");` 此语句将记录在`DEBUG`级别中用双引号引起的消息。
每行代码都给出了清晰的注释,使其易于遵循。 如您所见,调试级别的日志语句插入到测试用例的各个位置。
......@@ -181,4 +181,4 @@ Eclipse IDE 输出屏幕显示,
![JUnit Output](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20635%20318'%3E%3C/svg%3E)
<noscript><img alt="JUnit Output" class="alignnone size-full wp-image-14235" height="318" src="img/3d95ae1c1e99ed4e996edb2f746e0831.png" width="635"/><ul><li>system.log 和 test.log 文件都将按预期方式通过属性文件布局中指定的系统日志和带有时间戳的用户编码日志进行更新。</li></ul><p><img alt="Generated Test.log file" class="alignnone size-full wp-image-14236" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2019/05/6_Test.log-file-1.jpg" height="188" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20608%20188'%3E%3C/svg%3E" width="608"/></p><noscript><img alt="Generated Test.log file" class="alignnone size-full wp-image-14236" height="188" src="img/63ba29fc17dd09ce494e16026d76132f.png" width="608"/><p>代码文件,日志文件和相关的 JAR 一如既往地放置在<a href="https://github.com/JBTAdmin/Selenium/tree/master/AdvancedWebDriver"> GitHub 存储库</a>中。 我希望您现在已经了解了如何在 Selenium WebDriver 自动化的测试用例中利用流行的记录器之一。</p><p>祝你今天愉快!</p><div class="sticky-nav" style="font-size: 15px;"><div class="sticky-nav-image"></div><div class="sticky-nav-holder"><div class="sticky-nav_item"><h6 class="heading-sm">下一篇文章</h6></div><h5 class="sticky-nav_heading " style="font-size: 15px;"><a href="https://javabeginnerstutorial.com/selenium/10m-advanced-webdriver-running-tests-in-headless-mode/" title="10m. Advanced WebDriver – Running tests in headless mode"> 10m。 Advanced WebDriver –以无头模式运行测试</a></h5></div></div> </body> </html></noscript>
\ No newline at end of file
<noscript><img alt="JUnit Output" class="alignnone size-full wp-image-14235" height="318" src="img/3d95ae1c1e99ed4e996edb2f746e0831.png" width="635"/><ul><li>system.log 和 test.log 文件都将按预期方式通过属性文件布局中指定的系统日志和带有时间戳的用户编码日志进行更新。</li></ul><p><img alt="Generated Test.log file" class="alignnone size-full wp-image-14236" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2019/05/6_Test.log-file-1.jpg" height="188" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20608%20188'%3E%3C/svg%3E" width="608"/></p><noscript><img alt="Generated Test.log file" class="alignnone size-full wp-image-14236" height="188" src="img/63ba29fc17dd09ce494e16026d76132f.png" width="608"/><p>代码文件,日志文件和相关的 JAR 一如既往地放置在<a href="https://github.com/JBTAdmin/Selenium/tree/master/AdvancedWebDriver"> GitHub 存储库</a>中。 我希望您现在已经了解了如何在 Selenium WebDriver 自动化的测试用例中利用流行的记录器之一。</p><p>祝你今天愉快!</p><div class="sticky-nav" style="font-size: 15px;"><div class="sticky-nav-image"></div><div class="sticky-nav-holder"><div class="sticky-nav_item"><h6 class="heading-sm">下一篇文章</h6></div><h5 class="sticky-nav_heading " style="font-size: 15px;"><a href="https://javabeginnerstutorial.com/selenium/10m-advanced-webdriver-running-tests-in-headless-mode/" title="10m. Advanced WebDriver – Running tests in headless mode"> 10m。 Advanced WebDriver – 以无头模式运行测试</a></h5></div></div> </body> </html></noscript>
\ No newline at end of file
# 10m。 Advanced WebDriver –以无头模式运行测试
# 10m。 Advanced WebDriver – 以无头模式运行测试
> 原文: [https://javabeginnerstutorial.com/selenium/10m-advanced-webdriver-running-tests-in-headless-mode/](https://javabeginnerstutorial.com/selenium/10m-advanced-webdriver-running-tests-in-headless-mode/)
......@@ -10,7 +10,7 @@ I am sure you would have heard of headless by now because Google introduced head
2. 通常,在 **CI(连续集成)管道**中,它需要在没有实际 GUI 的服务器或 Linux OS 等系统上运行。 无头模式节省了一天!
3. 如果您所有的测试都运行了几个小时怎么办? 在这种情况下,用户必须从字面上看屏幕,让系统执行其工作,直到所有测试占据整个屏幕为止。 相反,如果以无头模式执行,则用户可以在后台运行测试时继续执行其他任务。
4. 当脚本被开发并且稳定时,并不需要真正看到它们正在运行。 以更快的方式在无头模式下运行它们似乎很有意义。 借助日志,可以执行所需的调试。
5. 并行执行无头可阻止打开多个浏览器,并让您执行多任务。
5. 并行执行无头可阻止打开多个浏览器,并让您执行多任务。
6. 无头模式也可以拍摄**截图**。 因此,一旦发生故障,便始终可以以所需的任何方式获取并存储快照。
但是,瞧! 有时候无头可能不是很有用。 例如,
......
......@@ -2,7 +2,7 @@
> 原文: [https://javabeginnerstutorial.com/vue-js/7-conditional-rendering-part-1/](https://javabeginnerstutorial.com/vue-js/7-conditional-rendering-part-1/)
我们并不总是希望将所有内容呈现到我们的网页上。 根据特定条件或特定表达式的值,我们可能希望隐藏/显示/附加或分离元素。 这只不过是条件渲染– *基于条件*渲染元素。 这可以使用简单的`if-else`语句来实现。 但是,我们将如何使用 Vue? 现在就纠正一下吧!
我们并不总是希望将所有内容呈现到我们的网页上。 根据特定条件或特定表达式的值,我们可能希望隐藏/显示/附加或分离元素。 这只不过是条件渲染 *基于条件*渲染元素。 这可以使用简单的`if-else`语句来实现。 但是,我们将如何使用 Vue? 现在就纠正一下吧!
Vue **指令**再来一次! 在这方面,我们有`v-if``v-else``v-else-if`来帮助我们。 让我们逐一查看示例,以进行深入了解。 我将撒很多视觉效果以简化此过程。
......
......@@ -26,17 +26,17 @@ data: {
我们为`v-for`指令使用的*特殊语法*是“ `greeting in greetings`”。
* 首先, ***问候语*** –建议在我们的情况下使用单数名词,问候语,作为数组元素的 ***别名*** 反复进行。 这可以是您选择的任何名称,然后可以在我们的代码中使用该名称来寻址每个数组项。
* 首先, ***问候语*** – 建议在我们的情况下使用单数名词,问候语,作为数组元素的 ***别名*** 反复进行。 这可以是您选择的任何名称,然后可以在我们的代码中使用该名称来寻址每个数组项。
* 其次,作为语法一部分的 – ***定界符*** 中的 ***。 如果您具有 JavaScript 背景,那么所有这些看起来都应该很熟悉,因为在这里我们将`for in`和`for of`用于迭代目的。 即使使用 Vue,我们也可以使用`of`作为分隔符而不是`in`。***
```java
<li v-for="greeting of greetings">{{ greeting }}</li>
```
* 最后, ***问候*** –必须与 Vue 实例的`data`对象中的 ***阵列名称*** 完全相同。
* 最后, ***问候*** – 必须与 Vue 实例的`data`对象中的 ***阵列名称*** 完全相同。
在这里,为简单起见,我们在简单插值中使用变量`greeting`。 但它可以像其他任何属性一样使用,例如将其作为值传递给函数或将其绑定到链接的引用等。输出如下,
![v-for iterating over array](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20688%20448'%3E%3C/svg%3E)
<noscript><img alt="v-for iterating over array" class="alignnone size-full wp-image-14104" height="448" sizes="(max-width: 688px) 100vw, 688px" src="img/af9854cb19e36518d9d7c5b0266dc44b.png" srcset="https://javabeginnerstutorial.com/wp-content/uploads/2018/11/1_v-for-array.jpg 688w, https://javabeginnerstutorial.com/wp-content/uploads/2018/11/1_v-for-array-300x195.jpg 300w" width="688"/><p>使用小胡子语法的另一种方法是使用<code>v-text</code>指令。 它将<code>greeting</code>设置为文本内容。</p><pre><code class="language-html">&lt;ul&gt; &lt;li v-for="greeting in greetings" v-text=greeting&gt;&lt;/li&gt; &lt;/ul&gt;</code></pre><p>将呈现相同的结果。</p><h2><strong> Vue 是反应性的! </strong></h2><p><span class="ezoic-adpicker-ad" id="ezoic-pub-ad-placeholder-124"> </span> <span class="ezoic-ad box-4 adtester-container adtester-container-124" data-ez-name="javabeginnerstutorial_com-box-4" style="display:block !important;float:none;margin-bottom:2px !important;margin-left:0px !important;margin-right:0px !important;margin-top:2px !important;min-height:110px;min-width:728px;text-align:center !important;"> <span class="ezoic-ad ezoic-adl" ezah="90" ezaw="728" id="div-gpt-ad-javabeginnerstutorial_com-box-4-0" style="position:relative;z-index:0;display:inline-block;min-height:90px;min-width:728px;"> </span> </span>让我们沿着存储通道走一下。 我们了解到 Vue 的美丽在于其<a href="https://javabeginnerstutorial.com/js/vue-js/2-template-syntax-reactivity/">反应性</a></p><p><strong> <em>快速回顾:</em> </strong>使状态和视图保持同步。 换句话说,Vue 不仅在引用的 DOM 中将<strong>呈现为</strong>数据,而且无论何时在数据对象中更改其值,<strong>都会更新</strong></p><p>让我们再来看一次这种情况。</p><p>使用快捷方式<strong> F12 </strong>打开<em> Chrome DevTools </em>,然后点击“ <strong> Vue </strong>”。 仅当您已遵循我们的教程系列并安装了<a href="https://javabeginnerstutorial.com/vue-js/4-vue-devtools-setup/"> <strong> <em> Vue Devtools </em> </strong> Chrome 扩展</a>后,此面板才会出现。</p><p>由于我们没有使用任何全局变量来引用<code>index.js</code>文件中的 Vue 实例,因此默认情况下会将其保存到<code>$vm0</code>。 如下图所示,单击<code>&lt;Root&gt;</code>即可看到。 因此,让我们使用<code>$vm0</code>从开发者工具控制台访问 Vue 模型。</p><p><img alt="reactivity in vue" class="alignnone size-full wp-image-14105" data-lazy-sizes="(max-width: 372px) 100vw, 372px" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2018/11/2_vm0.jpg" data-lazy-srcset="https://javabeginnerstutorial.com/wp-content/uploads/2018/11/2_vm0.jpg 372w, https://javabeginnerstutorial.com/wp-content/uploads/2018/11/2_vm0-217x300.jpg 217w" height="514" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20372%20514'%3E%3C/svg%3E" width="372"/></p><noscript><img alt="reactivity in vue" class="alignnone size-full wp-image-14105" height="514" sizes="(max-width: 372px) 100vw, 372px" src="img/7de386b6e2a340c69e8afaf8d06fdc41.png" srcset="https://javabeginnerstutorial.com/wp-content/uploads/2018/11/2_vm0.jpg 372w, https://javabeginnerstutorial.com/wp-content/uploads/2018/11/2_vm0-217x300.jpg 217w" width="372"/><p>让我们转到控制台,使用<code>push</code>方法向<code>greetings</code>数组添加一个问候,然后查看视图是否进行了动态更新(<em>神奇地</em>!)。</p><pre><code class="language-javascript">$vm0.greetings.push("namaste")</code></pre><p><img alt="v-for reactivity" class="alignnone size-full wp-image-14106" data-lazy-sizes="(max-width: 509px) 100vw, 509px" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2018/11/3_reactivity.jpg" data-lazy-srcset="https://javabeginnerstutorial.com/wp-content/uploads/2018/11/3_reactivity.jpg 509w, https://javabeginnerstutorial.com/wp-content/uploads/2018/11/3_reactivity-300x242.jpg 300w" height="411" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20509%20411'%3E%3C/svg%3E" width="509"/></p><noscript><img alt="v-for reactivity" class="alignnone size-full wp-image-14106" height="411" sizes="(max-width: 509px) 100vw, 509px" src="img/fbdfc17ee75fab781a7335c339414c87.png" srcset="https://javabeginnerstutorial.com/wp-content/uploads/2018/11/3_reactivity.jpg 509w, https://javabeginnerstutorial.com/wp-content/uploads/2018/11/3_reactivity-300x242.jpg 300w" width="509"/><p>这不是魔术吗?</p><h2><strong>访问当前数组项的索引</strong></h2><p>开发者的生活没有暂停按钮! 我们期望完成意外的事情,例如访问数组项的索引及其内容。 我们知道如何使用 Vue 渲染数组元素,但是否也可以获得其索引? 好吧,答案是肯定的!</p><p>语法与我们之前看到的非常相似,</p><pre><code class="language-html">&lt;div v-for="(greeting, index) in greetings"&gt;{{ index }}. {{ greeting}}&lt;/div&gt;</code></pre><p>我们必须引入一个括号并指定两个用逗号分隔的参数,可以选择它们的名称。 <strong>第一个</strong>参数是指数组元素–在我们的例子中是<code>greeting</code><strong>第二个</strong>参数是可选的,它引用当前正在循环的项目的索引–在我们的示例中为<code>index</code>。 此<strong>订单</strong>是最重要的注意事项。 无论您使用什么名称,第一个始终是数组元素,第二个始终是 v-for 语法中的索引。 然后可以根据需要将其与代码中的这些名称一起使用。</p><p><img alt="v-for with index" class="alignnone size-full wp-image-14107" data-lazy-sizes="(max-width: 786px) 100vw, 786px" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2018/11/4_v-for-with-index.jpg" data-lazy-srcset="https://javabeginnerstutorial.com/wp-content/uploads/2018/11/4_v-for-with-index.jpg 786w, https://javabeginnerstutorial.com/wp-content/uploads/2018/11/4_v-for-with-index-300x161.jpg 300w, https://javabeginnerstutorial.com/wp-content/uploads/2018/11/4_v-for-with-index-768x413.jpg 768w" height="423" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20786%20423'%3E%3C/svg%3E" width="786"/></p><noscript><img alt="v-for with index" class="alignnone size-full wp-image-14107" height="423" sizes="(max-width: 786px) 100vw, 786px" src="img/e2131f026f63f0feaafc6fd692278f3c.png" srcset="https://javabeginnerstutorial.com/wp-content/uploads/2018/11/4_v-for-with-index.jpg 786w, https://javabeginnerstutorial.com/wp-content/uploads/2018/11/4_v-for-with-index-300x161.jpg 300w, https://javabeginnerstutorial.com/wp-content/uploads/2018/11/4_v-for-with-index-768x413.jpg 768w" width="786"/><p>让我们看一下最终代码。</p><h3>Index.html</h3><pre><code class="language-html">&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;Hello Vue!&lt;/title&gt; &lt;!-- including Vue with development version CDN --&gt; &lt;script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="app"&gt; &lt;h2&gt;Greetings&lt;/h2&gt; &lt;!-- Iterating through array elements--&gt; &lt;ul&gt; &lt;li v-for="greeting in greetings" v-text=greeting&gt;&lt;/li&gt; &lt;/ul&gt; &lt;!-- Accessing array elements along with thier index --&gt; &lt;h2&gt;Greetings with Index&lt;/h2&gt; &lt;div v-for="(greeting, index) in greetings"&gt; {{ index }}. {{ greeting}} &lt;/div&gt; &lt;/div&gt; &lt;!-- including index.js file --&gt; &lt;script src="index.js"&gt;&lt;/script&gt; &lt;/body&gt; &lt;/html&gt;</code></pre><h3>Index.js</h3><pre><code class="language-javascript">var app = new Vue({ el: "#app", data: { greetings: ["hi", "bonjour", "hola", "ciao"] } });</code></pre><p><a href="https://github.com/JBTAdmin/vuejs"> GitHub 存储库</a>中也提供了上面讨论的所有代码。 随意分叉存储库并进行一些实验。</p><p>在下一篇文章中,我们将研究如何使用 v-for 遍历对象。 在此之前,请继续练习!</p><div class="sticky-nav" style="font-size: 15px;"><div class="sticky-nav-image"></div><div class="sticky-nav-holder"><div class="sticky-nav_item"><h6 class="heading-sm">下一篇文章</h6></div><h5 class="sticky-nav_heading " style="font-size: 15px;"><a href="https://javabeginnerstutorial.com/vue-js/10-rendering-lists-part-2/" title="10\. Rendering Lists Part 2 (Iterating over objects)"> 10.渲染列表第 2 部分(遍历对象)</a></h5></div></div> </body> </html></noscript>
\ No newline at end of file
<noscript><img alt="v-for iterating over array" class="alignnone size-full wp-image-14104" height="448" sizes="(max-width: 688px) 100vw, 688px" src="img/af9854cb19e36518d9d7c5b0266dc44b.png" srcset="https://javabeginnerstutorial.com/wp-content/uploads/2018/11/1_v-for-array.jpg 688w, https://javabeginnerstutorial.com/wp-content/uploads/2018/11/1_v-for-array-300x195.jpg 300w" width="688"/><p>使用小胡子语法的另一种方法是使用<code>v-text</code>指令。 它将<code>greeting</code>设置为文本内容。</p><pre><code class="language-html">&lt;ul&gt; &lt;li v-for="greeting in greetings" v-text=greeting&gt;&lt;/li&gt; &lt;/ul&gt;</code></pre><p>将呈现相同的结果。</p><h2><strong> Vue 是反应性的! </strong></h2><p><span class="ezoic-adpicker-ad" id="ezoic-pub-ad-placeholder-124"> </span> <span class="ezoic-ad box-4 adtester-container adtester-container-124" data-ez-name="javabeginnerstutorial_com-box-4" style="display:block !important;float:none;margin-bottom:2px !important;margin-left:0px !important;margin-right:0px !important;margin-top:2px !important;min-height:110px;min-width:728px;text-align:center !important;"> <span class="ezoic-ad ezoic-adl" ezah="90" ezaw="728" id="div-gpt-ad-javabeginnerstutorial_com-box-4-0" style="position:relative;z-index:0;display:inline-block;min-height:90px;min-width:728px;"> </span> </span>让我们沿着存储通道走一下。 我们了解到 Vue 的美丽在于其<a href="https://javabeginnerstutorial.com/js/vue-js/2-template-syntax-reactivity/">反应性</a></p><p><strong> <em>快速回顾:</em> </strong>使状态和视图保持同步。 换句话说,Vue 不仅在引用的 DOM 中将<strong>呈现为</strong>数据,而且无论何时在数据对象中更改其值,<strong>都会更新</strong></p><p>让我们再来看一次这种情况。</p><p>使用快捷方式<strong> F12 </strong>打开<em> Chrome DevTools </em>,然后点击“ <strong> Vue </strong>”。 仅当您已遵循我们的教程系列并安装了<a href="https://javabeginnerstutorial.com/vue-js/4-vue-devtools-setup/"> <strong> <em> Vue Devtools </em> </strong> Chrome 扩展</a>后,此面板才会出现。</p><p>由于我们没有使用任何全局变量来引用<code>index.js</code>文件中的 Vue 实例,因此默认情况下会将其保存到<code>$vm0</code>。 如下图所示,单击<code>&lt;Root&gt;</code>即可看到。 因此,让我们使用<code>$vm0</code>从开发者工具控制台访问 Vue 模型。</p><p><img alt="reactivity in vue" class="alignnone size-full wp-image-14105" data-lazy-sizes="(max-width: 372px) 100vw, 372px" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2018/11/2_vm0.jpg" data-lazy-srcset="https://javabeginnerstutorial.com/wp-content/uploads/2018/11/2_vm0.jpg 372w, https://javabeginnerstutorial.com/wp-content/uploads/2018/11/2_vm0-217x300.jpg 217w" height="514" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20372%20514'%3E%3C/svg%3E" width="372"/></p><noscript><img alt="reactivity in vue" class="alignnone size-full wp-image-14105" height="514" sizes="(max-width: 372px) 100vw, 372px" src="img/7de386b6e2a340c69e8afaf8d06fdc41.png" srcset="https://javabeginnerstutorial.com/wp-content/uploads/2018/11/2_vm0.jpg 372w, https://javabeginnerstutorial.com/wp-content/uploads/2018/11/2_vm0-217x300.jpg 217w" width="372"/><p>让我们转到控制台,使用<code>push</code>方法向<code>greetings</code>数组添加一个问候,然后查看视图是否进行了动态更新(<em>神奇地</em>!)。</p><pre><code class="language-javascript">$vm0.greetings.push("namaste")</code></pre><p><img alt="v-for reactivity" class="alignnone size-full wp-image-14106" data-lazy-sizes="(max-width: 509px) 100vw, 509px" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2018/11/3_reactivity.jpg" data-lazy-srcset="https://javabeginnerstutorial.com/wp-content/uploads/2018/11/3_reactivity.jpg 509w, https://javabeginnerstutorial.com/wp-content/uploads/2018/11/3_reactivity-300x242.jpg 300w" height="411" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20509%20411'%3E%3C/svg%3E" width="509"/></p><noscript><img alt="v-for reactivity" class="alignnone size-full wp-image-14106" height="411" sizes="(max-width: 509px) 100vw, 509px" src="img/fbdfc17ee75fab781a7335c339414c87.png" srcset="https://javabeginnerstutorial.com/wp-content/uploads/2018/11/3_reactivity.jpg 509w, https://javabeginnerstutorial.com/wp-content/uploads/2018/11/3_reactivity-300x242.jpg 300w" width="509"/><p>这不是魔术吗?</p><h2><strong>访问当前数组项的索引</strong></h2><p>开发者的生活没有暂停按钮! 我们期望完成意外的事情,例如访问数组项的索引及其内容。 我们知道如何使用 Vue 渲染数组元素,但是否也可以获得其索引? 好吧,答案是肯定的!</p><p>语法与我们之前看到的非常相似,</p><pre><code class="language-html">&lt;div v-for="(greeting, index) in greetings"&gt;{{ index }}. {{ greeting}}&lt;/div&gt;</code></pre><p>我们必须引入一个括号并指定两个用逗号分隔的参数,可以选择它们的名称。 <strong>第一个</strong>参数是指数组元素 – 在我们的例子中是<code>greeting</code><strong>第二个</strong>参数是可选的,它引用当前正在循环的项目的索引 – 在我们的示例中为<code>index</code>。 此<strong>订单</strong>是最重要的注意事项。 无论您使用什么名称,第一个始终是数组元素,第二个始终是 v-for 语法中的索引。 然后可以根据需要将其与代码中的这些名称一起使用。</p><p><img alt="v-for with index" class="alignnone size-full wp-image-14107" data-lazy-sizes="(max-width: 786px) 100vw, 786px" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2018/11/4_v-for-with-index.jpg" data-lazy-srcset="https://javabeginnerstutorial.com/wp-content/uploads/2018/11/4_v-for-with-index.jpg 786w, https://javabeginnerstutorial.com/wp-content/uploads/2018/11/4_v-for-with-index-300x161.jpg 300w, https://javabeginnerstutorial.com/wp-content/uploads/2018/11/4_v-for-with-index-768x413.jpg 768w" height="423" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20786%20423'%3E%3C/svg%3E" width="786"/></p><noscript><img alt="v-for with index" class="alignnone size-full wp-image-14107" height="423" sizes="(max-width: 786px) 100vw, 786px" src="img/e2131f026f63f0feaafc6fd692278f3c.png" srcset="https://javabeginnerstutorial.com/wp-content/uploads/2018/11/4_v-for-with-index.jpg 786w, https://javabeginnerstutorial.com/wp-content/uploads/2018/11/4_v-for-with-index-300x161.jpg 300w, https://javabeginnerstutorial.com/wp-content/uploads/2018/11/4_v-for-with-index-768x413.jpg 768w" width="786"/><p>让我们看一下最终代码。</p><h3>Index.html</h3><pre><code class="language-html">&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;Hello Vue!&lt;/title&gt; &lt;!-- including Vue with development version CDN --&gt; &lt;script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="app"&gt; &lt;h2&gt;Greetings&lt;/h2&gt; &lt;!-- Iterating through array elements--&gt; &lt;ul&gt; &lt;li v-for="greeting in greetings" v-text=greeting&gt;&lt;/li&gt; &lt;/ul&gt; &lt;!-- Accessing array elements along with thier index --&gt; &lt;h2&gt;Greetings with Index&lt;/h2&gt; &lt;div v-for="(greeting, index) in greetings"&gt; {{ index }}. {{ greeting}} &lt;/div&gt; &lt;/div&gt; &lt;!-- including index.js file --&gt; &lt;script src="index.js"&gt;&lt;/script&gt; &lt;/body&gt; &lt;/html&gt;</code></pre><h3>Index.js</h3><pre><code class="language-javascript">var app = new Vue({ el: "#app", data: { greetings: ["hi", "bonjour", "hola", "ciao"] } });</code></pre><p><a href="https://github.com/JBTAdmin/vuejs"> GitHub 存储库</a>中也提供了上面讨论的所有代码。 随意分叉存储库并进行一些实验。</p><p>在下一篇文章中,我们将研究如何使用 v-for 遍历对象。 在此之前,请继续练习!</p><div class="sticky-nav" style="font-size: 15px;"><div class="sticky-nav-image"></div><div class="sticky-nav-holder"><div class="sticky-nav_item"><h6 class="heading-sm">下一篇文章</h6></div><h5 class="sticky-nav_heading " style="font-size: 15px;"><a href="https://javabeginnerstutorial.com/vue-js/10-rendering-lists-part-2/" title="10\. Rendering Lists Part 2 (Iterating over objects)"> 10.渲染列表第 2 部分(遍历对象)</a></h5></div></div> </body> </html></noscript>
\ No newline at end of file
此差异已折叠。
此差异已折叠。
......@@ -79,4 +79,4 @@ new Vue({
![v-model initial output](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20467%20384'%3E%3C/svg%3E)
<noscript><img alt="v-model initial output" class="alignnone size-full wp-image-14163" height="384" src="img/1fbc5015295fc979e5e228f95c136712.png" width="467"/><span class="ezoic-adpicker-ad" id="ezoic-pub-ad-placeholder-124"></span><span class="ezoic-ad box-4 adtester-container adtester-container-124" data-ez-name="javabeginnerstutorial_com-box-4" style="display:block !important;float:none;margin-bottom:2px !important;margin-left:0px !important;margin-right:0px !important;margin-top:2px !important;min-height:110px;min-width:728px;text-align:center !important;"><span class="ezoic-ad ezoic-adl" ezah="90" ezaw="728" id="div-gpt-ad-javabeginnerstutorial_com-box-4-0" style="position:relative;z-index:0;display:inline-block;min-height:90px;min-width:728px;"></span></span><p>图像的右半部分显示<a href="https://javabeginnerstutorial.com/vue-js/4-vue-devtools-setup/"> Vue DevTools </a>窗格。 也可以看到具有<code>message</code>属性及其值的<code>data</code>对象。</p><p>当我们将文本字段中的消息从“ hi”更改为“ hello”时,我们键入的每个字符都将在基础数据模型(如 Vue Devtools 中所示)上进行反应性更新,并在输出结果的视图中进行更新 在<code>&lt;p&gt;</code>标签中使用小胡子语法。</p><p><img alt="reactivity with v-model" class="alignnone size-full wp-image-14164" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2018/12/2_reactivity-1.jpg" height="379" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20470%20379'%3E%3C/svg%3E" width="470"/></p><noscript><img alt="reactivity with v-model" class="alignnone size-full wp-image-14164" height="379" src="img/39c5c156976147d4e25ea3115a06f7e9.png" width="470"/><p>我强烈建议您如图所示打开 Vue Devtools 并更改文本字段中的值,以查看此更改是被动发生的。 这将是您的盛宴! 我可以保证。</p><h2>修饰符</h2><p>v 模型带有三个修饰符。 如果您错过了修饰符部分,请将检出<a href="https://javabeginnerstutorial.com/vue-js/11-listening-to-dom-events-and-event-modifiers/"></a></p><p><strong>用法:</strong>遵循<code>v-model</code>指令,添加一个点并指定修饰符。</p><ul><li><code>.lazy</code> –在更改事件(而非输入事件)之后将输入与数据同步</li></ul><pre><code class="language-html">&lt;input v-model.lazy="message"&gt;</code></pre><ul><li><code>.number</code> –用于将有效的输入字符串转换为数字</li></ul><pre><code class="language-html">&lt;input v-model.number="age"&gt;</code></pre><ul><li><code>.trim</code> –自动修剪用户输入</li></ul><pre><code class="language-html">&lt;input v-model.trim="message"&gt;</code></pre><p>该代码一如既往在<a href="https://github.com/JBTAdmin/vuejs"> GitHub 存储库</a>中可用。</p><p>试一试,并注意 Vue 如何根据输入类型是否为文本字段,复选框,单选按钮,选择,多选,文本区域元素等来正确更新元素……它看起来和听起来很神奇,因为所有语法 您需要完成一个简单的指令<code>v-model</code>来完成这项艰巨的任务。 如果遇到任何问题,请随时在评论部分大声疾呼。</p><p>祝您有美好的一天!</p><div class="sticky-nav" style="font-size: 15px;"><div class="sticky-nav-image"></div><div class="sticky-nav-holder"><div class="sticky-nav_item"><h6 class="heading-sm">下一篇文章</h6></div><h5 class="sticky-nav_heading " style="font-size: 15px;"><a href="https://javabeginnerstutorial.com/vue-js/15-form-input-bindings/" title="15\. Form input bindings"> 15.表单输入绑定</a></h5></div></div> </body> </html></noscript>
\ No newline at end of file
<noscript><img alt="v-model initial output" class="alignnone size-full wp-image-14163" height="384" src="img/1fbc5015295fc979e5e228f95c136712.png" width="467"/><span class="ezoic-adpicker-ad" id="ezoic-pub-ad-placeholder-124"></span><span class="ezoic-ad box-4 adtester-container adtester-container-124" data-ez-name="javabeginnerstutorial_com-box-4" style="display:block !important;float:none;margin-bottom:2px !important;margin-left:0px !important;margin-right:0px !important;margin-top:2px !important;min-height:110px;min-width:728px;text-align:center !important;"><span class="ezoic-ad ezoic-adl" ezah="90" ezaw="728" id="div-gpt-ad-javabeginnerstutorial_com-box-4-0" style="position:relative;z-index:0;display:inline-block;min-height:90px;min-width:728px;"></span></span><p>图像的右半部分显示<a href="https://javabeginnerstutorial.com/vue-js/4-vue-devtools-setup/"> Vue DevTools </a>窗格。 也可以看到具有<code>message</code>属性及其值的<code>data</code>对象。</p><p>当我们将文本字段中的消息从“ hi”更改为“ hello”时,我们键入的每个字符都将在基础数据模型(如 Vue Devtools 中所示)上进行反应性更新,并在输出结果的视图中进行更新 在<code>&lt;p&gt;</code>标签中使用小胡子语法。</p><p><img alt="reactivity with v-model" class="alignnone size-full wp-image-14164" data-lazy-src="https://javabeginnerstutorial.com/wp-content/uploads/2018/12/2_reactivity-1.jpg" height="379" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20470%20379'%3E%3C/svg%3E" width="470"/></p><noscript><img alt="reactivity with v-model" class="alignnone size-full wp-image-14164" height="379" src="img/39c5c156976147d4e25ea3115a06f7e9.png" width="470"/><p>我强烈建议您如图所示打开 Vue Devtools 并更改文本字段中的值,以查看此更改是被动发生的。 这将是您的盛宴! 我可以保证。</p><h2>修饰符</h2><p>v 模型带有三个修饰符。 如果您错过了修饰符部分,请将检出<a href="https://javabeginnerstutorial.com/vue-js/11-listening-to-dom-events-and-event-modifiers/"></a></p><p><strong>用法:</strong>遵循<code>v-model</code>指令,添加一个点并指定修饰符。</p><ul><li><code>.lazy</code> – 在更改事件(而非输入事件)之后将输入与数据同步</li></ul><pre><code class="language-html">&lt;input v-model.lazy="message"&gt;</code></pre><ul><li><code>.number</code> – 用于将有效的输入字符串转换为数字</li></ul><pre><code class="language-html">&lt;input v-model.number="age"&gt;</code></pre><ul><li><code>.trim</code> – 自动修剪用户输入</li></ul><pre><code class="language-html">&lt;input v-model.trim="message"&gt;</code></pre><p>该代码一如既往在<a href="https://github.com/JBTAdmin/vuejs"> GitHub 存储库</a>中可用。</p><p>试一试,并注意 Vue 如何根据输入类型是否为文本字段,复选框,单选按钮,选择,多选,文本区域元素等来正确更新元素……它看起来和听起来很神奇,因为所有语法 您需要完成一个简单的指令<code>v-model</code>来完成这项艰巨的任务。 如果遇到任何问题,请随时在评论部分大声疾呼。</p><p>祝您有美好的一天!</p><div class="sticky-nav" style="font-size: 15px;"><div class="sticky-nav-image"></div><div class="sticky-nav-holder"><div class="sticky-nav_item"><h6 class="heading-sm">下一篇文章</h6></div><h5 class="sticky-nav_heading " style="font-size: 15px;"><a href="https://javabeginnerstutorial.com/vue-js/15-form-input-bindings/" title="15\. Form input bindings"> 15.表单输入绑定</a></h5></div></div> </body> </html></noscript>
\ No newline at end of file
......@@ -25,7 +25,7 @@
## 条件执行的类型
* If 语句
* 如果其他语句
* 如果其他语句
* If- Else-if 陈述
* 切换语句
......@@ -191,7 +191,7 @@ String is neither Hello nor Hi
* 用于循环
* While 循环
* 执行– While 循环
* 执行 – While 循环
* * *
......
......@@ -340,4 +340,4 @@ s 是任何字符串,lst 是可选的列表类型参数。 如果未提供 lst
###### 下一篇文章
##### [Python 3:猜数字–返回](https://javabeginnerstutorial.com/python-tutorial/python-3-guess-the-number-the-return/ "Python 3: Guess the number –The return")
\ No newline at end of file
##### [Python 3:猜数字 – 返回](https://javabeginnerstutorial.com/python-tutorial/python-3-guess-the-number-the-return/ "Python 3: Guess the number –The return")
\ No newline at end of file
# Python 3:猜数字返回
# Python 3:猜数字返回
> 原文: [https://javabeginnerstutorial.com/python-tutorial/python-3-guess-the-number-the-return/](https://javabeginnerstutorial.com/python-tutorial/python-3-guess-the-number-the-return/)
......
......@@ -595,13 +595,13 @@ pipeline_demo.py
## 参考书目/进一步阅读
标题:Python Wiki –生成器
标题:Python Wiki – 生成器
作者:多个
来源: [Python Wiki](https://wiki.python.org/moin/Generators)
标题:Python Wiki –迭代器
标题:Python Wiki – 迭代器
Authors: Multiple
......@@ -613,13 +613,13 @@ Authors: Multiple
资料来源:[滥用堆栈网站](http://stackabuse.com/python-generators/)
标题:Python 实践手册第 5 章。迭代器&生成器
标题:Python 实践手册第 5 章。迭代器&生成器
作者:Anand Chitipothu
资料来源: [Python 实践书网站](https://anandology.com/python-practice-book/iterators.html)
标题:系统程序员的生成器技巧版本 2.0
标题:系统程序员的生成器技巧版本 2.0
作者:David M. Beazley
......
......@@ -16,7 +16,7 @@
### 在哪里改变
更改将在 *src / main / resources /* 下的 *hibernate.cfg.xml* 文件中进行。 在这里,您必须在<!–数据库连接设置 >注释下的块中设置字段。
更改将在 *src / main / resources /* 下的 *hibernate.cfg.xml* 文件中进行。 在这里,您必须在<!– 数据库连接设置 >注释下的块中设置字段。
这意味着以下参数:
......
......@@ -28,7 +28,7 @@ c3p0 连接池的最重要的配置属性如下:
* c3p0.max_size:池中最大 JDBC 连接数。 休眠默认值:100
* c3p0.timeout:从池中删除空闲连接时(秒)。 休眠默认值:0,永不过期。
* c3p0.max_statements:将缓存准备好的语句数。 提高性能。 休眠默认值:0,禁用缓存。
* c3p0.idle_test_period –自动验证连接之前的空闲时间(以秒为单位)。 休眠默认值:0
* c3p0.idle_test_period – 自动验证连接之前的空闲时间(以秒为单位)。 休眠默认值:0
### C3P0 的配置
......
# Java 教程–变量
\ No newline at end of file
# Java 教程 – 变量
\ No newline at end of file
# Java 教程–循环
\ No newline at end of file
# Java 教程 – 循环
\ No newline at end of file
# Java 教程–入门
\ No newline at end of file
# Java 教程 – 入门
\ No newline at end of file
# Java 教程–异常
\ No newline at end of file
# Java 教程 – 异常
\ No newline at end of file
......@@ -86,4 +86,4 @@ ArrayIndexOutOfBounds 异常。
###### 下一篇文章
##### [异常处理– try-with-resources 语句](https://javabeginnerstutorial.com/core-java-tutorial/exception-handling-try-resources/ "Exception Handling – The try-with-resources statement")
\ No newline at end of file
##### [异常处理 – try-with-resources 语句](https://javabeginnerstutorial.com/core-java-tutorial/exception-handling-try-resources/ "Exception Handling – The try-with-resources statement")
\ No newline at end of file
# 异常处理– try-with-resources 语句
# 异常处理 – try-with-resources 语句
> 原文: [https://javabeginnerstutorial.com/core-java-tutorial/exception-handling-try-resources/](https://javabeginnerstutorial.com/core-java-tutorial/exception-handling-try-resources/)
......@@ -197,4 +197,4 @@ In finally...
###### 下一篇文章
##### [异常处理–尝试捕获 Java 块](https://javabeginnerstutorial.com/core-java-tutorial/exception-handling-try-catch-java/ "Exception Handling – try catch Java blocks")
\ No newline at end of file
##### [异常处理 – 尝试捕获 Java 块](https://javabeginnerstutorial.com/core-java-tutorial/exception-handling-try-catch-java/ "Exception Handling – try catch Java blocks")
\ No newline at end of file
# 异常处理尝试捕获 Java 块
# 异常处理尝试捕获 Java 块
> 原文: [https://javabeginnerstutorial.com/core-java-tutorial/exception-handling-try-catch-java/](https://javabeginnerstutorial.com/core-java-tutorial/exception-handling-try-catch-java/)
......
# Java 教程– OOPS 概念
\ No newline at end of file
# Java 教程 – OOPS 概念
\ No newline at end of file
# Java 教程–关键字
\ No newline at end of file
# Java 教程 – 关键字
\ No newline at end of file
......@@ -90,11 +90,11 @@ Inside Static method
**注*:**静态关键字可以与变量和方法一起使用。 它是 ***不适用于*** 类。
## 类变量静态字段
## 类变量静态字段
类变量(也称为静态字段)在类中的所有对象之间共享特征。 当您声明字段为静态字段时,只会创建关联变量的单个实例,该实例对于该类的所有对象都是通用的。 因此,当一个对象更改类变量的值时,它将影响该类的所有对象。 我们可以通过使用类的名称来访问类变量,而不必使用对类内单个对象的引用。 即使不存在该类的对象,也可以访问静态变量。 类变量使用 static 关键字声明。
## 类方法静态方法
## 类方法静态方法
可以在没有类实例的情况下调用类似于类变量的类方法。 类方法通常用于为 Java 程序提供全局功能。 例如,java.lang.Math 包中的 Methods 是 Class 方法。 您不能从静态方法内部调用非静态方法。
......
# Java 教程–集合
\ No newline at end of file
# Java 教程 – 集合
\ No newline at end of file
......@@ -78,7 +78,7 @@ Collection API 提供了一组接口供您选择,但同时也为您提供了
3. 哈希表
4. 数组列表
### 2 –无序集合
### 2 – 无序集合
1. 哈希集
......
......@@ -196,7 +196,7 @@ Iterator iterator = Arrays.asList(1, 4, 223, 56, 23, 88, 346, 78, 45, 33).iterat
## 结论
如果您有一个元素集合并且想要浏览它们并从该集合中删除元素,则 Iterator 接口是基本的解决方案。
如果您有一个元素集合并且想要浏览它们并从该集合中删除元素,则 Iterator 接口是基本的解决方案。
这里的方法是有限的:您不能向该集合中添加元素,也不能向后导航...并且使用 Java **1.5** ,引入了新的 Collection 接口,这使我们的开发人员的生活更加轻松。
......
# Java 教程–序列化
\ No newline at end of file
# Java 教程 – 序列化
\ No newline at end of file
# Java 教程–枚举
\ No newline at end of file
# Java 教程 – 枚举
\ No newline at end of file
# 核心 Java 教程–线程
\ No newline at end of file
# 核心 Java 教程 – 线程
\ No newline at end of file
# 核心 Java 教程–高级主题
\ No newline at end of file
# 核心 Java 教程 – 高级主题
\ No newline at end of file
......@@ -12,17 +12,17 @@
**何时**变得有利?
1. **回归测试** –想象一下,系统中已经创建了功能,并且已经过测试。 在稍后的某个时间点,有一些更改会影响现有代码或引入新功能。 因此,现有的已经测试过的零件可能无法按预期工作,或者更糟,发生故障。 如果这种情况在生产环境中发生,并且您的客户之一对此表示抱怨,那是什么条件? 您甚至可以想象发生这样的事情吗? 听起来令人恐惧吧? 为了您的急救,我们这里有硒。 我们可以使用 Selenium 创建一个自动化测试的回归套件,并且每次引入更改或新功能时,都可以运行该套件,而无需进行任何额外的工作(在敏捷过程中,每个 sprint 结束时) 确保没有任何损坏。
2. **高级测试** –单元测试可用于测试单个组件(类级别),集成测试可用于测试事物在类间级别上的工作方式。 对于 Web 应用程序,最后的座右铭是找出浏览器是否按照客户希望的方式正常工作。 使用 Selenium,我们可以像用户/客户一样执行测试!
3. **组合测试** –让我们以一个包含三组,每组具有三个单选按钮的网页为例。 手动测试所有组合可能会花费大量时间,但是以编程方式可以轻松完成,并且无需人工干预即可在一夜之间进行测试。
4. **确切要求** –手动编写的测试步骤可能不明确。 一个测试人员可能会测试并声明它已通过,但另一个测试人员可能会说失败了。 自动化测试具有非常确定的结果。 因此,无论开发人员是谁,都对开发人员和您的应用程序提出了确切的要求。 它要么通过要么失败。 而已!
1. **回归测试** 想象一下,系统中已经创建了功能,并且已经过测试。 在稍后的某个时间点,有一些更改会影响现有代码或引入新功能。 因此,现有的已经测试过的零件可能无法按预期工作,或者更糟,发生故障。 如果这种情况在生产环境中发生,并且您的客户之一对此表示抱怨,那是什么条件? 您甚至可以想象发生这样的事情吗? 听起来令人恐惧吧? 为了您的急救,我们这里有硒。 我们可以使用 Selenium 创建一个自动化测试的回归套件,并且每次引入更改或新功能时,都可以运行该套件,而无需进行任何额外的工作(在敏捷过程中,每个 sprint 结束时) 确保没有任何损坏。
2. **高级测试** 单元测试可用于测试单个组件(类级别),集成测试可用于测试事物在类间级别上的工作方式。 对于 Web 应用程序,最后的座右铭是找出浏览器是否按照客户希望的方式正常工作。 使用 Selenium,我们可以像用户/客户一样执行测试!
3. **组合测试** 让我们以一个包含三组,每组具有三个单选按钮的网页为例。 手动测试所有组合可能会花费大量时间,但是以编程方式可以轻松完成,并且无需人工干预即可在一夜之间进行测试。
4. **确切要求** 手动编写的测试步骤可能不明确。 一个测试人员可能会测试并声明它已通过,但另一个测试人员可能会说失败了。 自动化测试具有非常确定的结果。 因此,无论开发人员是谁,都对开发人员和您的应用程序提出了确切的要求。 它要么通过要么失败。 而已!
5. **可以在某些测试框架的帮助下生成自定义报告**和屏幕截图,当开发人员或其他项目涉众期望快速反馈时,这将非常有用。
6. 一旦安装了测试脚本并设置了测试环境,就可以执行任意数量的测试执行**迭代**
7. 可以执行这些自动测试的**速度**非常高。 因此,在频繁发布的情况下,自动化成为一个很好的解决方案。
8. 当需要并行执行时,自动化是可取的。
9. 由于避免了人为错误(可能随着时间的推移而使重复任务变得无聊而导致的错误),因此**准确性**和质量得以提高。
**哪个**可能是基于 Web 的自动化中使用最广泛的开源解决方案? –拜托,显然是**硒!**
**哪个**可能是基于 Web 的自动化中使用最广泛的开源解决方案? – 拜托,显然是**硒!**
有了这些知识,在另一篇文章中再见,以了解硒的历史。
......
......@@ -27,7 +27,7 @@
* 与 Selenium RC 一样,支持跨浏览器和跨平台。
* 与浏览器进行本地交互,因此它比 Selenium IDE 和 Selenium RC 更快。
* 简洁的 API –使我们的生活更轻松。
* 简洁的 API – 使我们的生活更轻松。
* 还支持不可见的浏览器 HtmlUnit。
* 还支持对 iPhone 和 Android 应用程序的测试。
......@@ -48,4 +48,4 @@
###### 下一篇文章
##### [7a。 Selenium IDE –简介,优点和局限性](https://javabeginnerstutorial.com/selenium/7a-ide-benefits-limitations/ "7a. Selenium IDE – Introduction, benefits and limitations")
\ No newline at end of file
##### [7a。 Selenium IDE – 简介,优点和局限性](https://javabeginnerstutorial.com/selenium/7a-ide-benefits-limitations/ "7a. Selenium IDE – Introduction, benefits and limitations")
\ No newline at end of file
# 7a。 Selenium IDE –简介,优点和局限性
# 7a。 Selenium IDE – 简介,优点和局限性
> 原文: [https://javabeginnerstutorial.com/selenium/7a-ide-benefits-limitations/](https://javabeginnerstutorial.com/selenium/7a-ide-benefits-limitations/)
硒将我们带到了新的地方,现在是时候让我们进一步了解我们将生活的世界– **硒世界**。 它有四个主要部分,即
硒将我们带到了新的地方,现在是时候让我们进一步了解我们将生活的世界 **硒世界**。 它有四个主要部分,即
* Selenium IDE 的 **Magic Meadows** 通常被称为“ *Selenium 初学者的历史领袖*
* 硒 RC 的**多样性增量**以“ *系列超人”* 而闻名
......
......@@ -83,4 +83,4 @@ Firebug 通常会在 Firefox 窗口底部启动,这就是它的外观,
###### 下一篇文章
##### [7c。 Selenium IDE –突破表面:初探](https://javabeginnerstutorial.com/selenium/7c-selenium-ide-first-look/ "7c. Selenium IDE – Breaking the Surface: A First Look")
\ No newline at end of file
##### [7c。 Selenium IDE – 突破表面:初探](https://javabeginnerstutorial.com/selenium/7c-selenium-ide-first-look/ "7c. Selenium IDE – Breaking the Surface: A First Look")
\ No newline at end of file
# 7c。 Selenium IDE –突破表面:初探
# 7c。 Selenium IDE – 突破表面:初探
> 原文: [https://javabeginnerstutorial.com/selenium/7c-selenium-ide-first-look/](https://javabeginnerstutorial.com/selenium/7c-selenium-ide-first-look/)
......@@ -18,4 +18,4 @@
###### 下一篇文章
##### [7d。 Selenium IDE –了解您的 IDE 功能](https://javabeginnerstutorial.com/selenium/7d-know-ide-features/ "7d. Selenium IDE – Know your IDE features")
\ No newline at end of file
##### [7d。 Selenium IDE – 了解您的 IDE 功能](https://javabeginnerstutorial.com/selenium/7d-know-ide-features/ "7d. Selenium IDE – Know your IDE features")
\ No newline at end of file
# 7d。 Selenium IDE –了解您的 IDE 功能
# 7d。 Selenium IDE – 了解您的 IDE 功能
> 原文: [https://javabeginnerstutorial.com/selenium/7d-know-ide-features/](https://javabeginnerstutorial.com/selenium/7d-know-ide-features/)
......@@ -32,7 +32,7 @@
这是为您提供的“编辑”菜单,
![Edit Menu](img/bca40d632ffeab3c1eea07bbae13700a.png)
是时候换另一个 ***BrainBell*** 了– *相关! 使用我们已经知道的东西来关联我们正在学习的内容,可以帮助大脑更轻松地记住。 就像在大脑上贴笔记一样。*
是时候换另一个 ***BrainBell*** 了 – *相关! 使用我们已经知道的东西来关联我们正在学习的内容,可以帮助大脑更轻松地记住。 就像在大脑上贴笔记一样。*
因此,这里是我们著名的诗,但稍作修改,
......@@ -65,10 +65,10 @@
![Options Tab](img/623b4cf4e5686cd55858863954e6a1fd.png)
**常规**标签中:
* ***默认超时值*** –这表示 Selenium IDE 在产生错误之前宁愿等待测试步骤执行的时间(以毫秒为单位)。 默认值设置为 30000ms,即 30s。 可以根据 Web 元素出现或可访问的速度适当增加或减少此值。
* ***默认超时值*** 这表示 Selenium IDE 在产生错误之前宁愿等待测试步骤执行的时间(以毫秒为单位)。 默认值设置为 30000ms,即 30s。 可以根据 Web 元素出现或可访问的速度适当增加或减少此值。
* ***扩展*** – Selenium IDE 扩展增强了该工具的功能,可以通过从[下载所需的扩展来实现此功能 https://addons.mozilla.org/en-US/firefox /](https://addons.mozilla.org/en-US/firefox/) 链接,在页面右上角的搜索框中使用“硒”作为关键字。 除了作为基准 IDE 扩展的一部分定义的扩展之外,这些还将是其他扩展。
* ***记住基本 URL*** –选中此选项将确保 Selenium IDE 每次启动时都会记住该 URL 或将其加载到该工具的基本 URL 文本框中。 取消选中此选项后,IDE 将在基本 URL 栏中以空白值启动。
* ***启用实验性功能*** –首次使用活动的互联网连接检查此字段将导入可用的格式,我们将在稍后看到。
* ***记住基本 URL*** 选中此选项将确保 Selenium IDE 每次启动时都会记住该 URL 或将其加载到该工具的基本 URL 文本框中。 取消选中此选项后,IDE 将在基本 URL 栏中以空白值启动。
* ***启用实验性功能*** 首次使用活动的互联网连接检查此字段将导入可用的格式,我们将在稍后看到。
**格式**选项卡:
![Options_FormatsTab](img/b91c63027b049273e73b7783b205df00.png)
......@@ -76,8 +76,8 @@
![Options_Plugins](img/ea86a0c33f4595b96ebf8389efba551c.png)
“插件”选项卡显示该工具可用的默认插件。 提供了许多插件,可以轻松下载和安装。 有几个这样的例子,
1. “ Selenium IDE:PHP 格式化程序” –用于将 HTML 测试用例转换为 PHP 格式
2. “文件日志” –将生成的日志保存到文件
1. “ Selenium IDE:PHP 格式化程序” – 用于将 HTML 测试用例转换为 PHP 格式
2. “文件日志” – 将生成的日志保存到文件
**定位器构建器**选项卡,
![Options_LocatorBuilders](img/970e1bb1d3fd6e74193fcd41c704bcce.png)
......@@ -111,4 +111,4 @@
###### 下一篇文章
##### [7e。 Selenium IDE –了解您的 IDE 功能(续)。](https://javabeginnerstutorial.com/selenium/ide-know-ide-features-contd/ "7e. Selenium IDE – Know your IDE features Contd.")
\ No newline at end of file
##### [7e。 Selenium IDE – 了解您的 IDE 功能(续)。](https://javabeginnerstutorial.com/selenium/ide-know-ide-features-contd/ "7e. Selenium IDE – Know your IDE features Contd.")
\ No newline at end of file
# 7e。 Selenium IDE –了解您的 IDE 功能(续)。
# 7e。 Selenium IDE – 了解您的 IDE 功能(续)。
> 原文: [https://javabeginnerstutorial.com/selenium/ide-know-ide-features-contd/](https://javabeginnerstutorial.com/selenium/ide-know-ide-features-contd/)
......@@ -112,4 +112,4 @@ Selenium IDE 工具的左侧有一个测试用例窗格,如下所示,
###### 下一篇文章
##### [7f。 Selenium IDE –命令,目标和值](https://javabeginnerstutorial.com/selenium/7f-ide-command-target-value/ "7f. Selenium IDE – Command, target and value")
\ No newline at end of file
##### [7f。 Selenium IDE – 命令,目标和值](https://javabeginnerstutorial.com/selenium/7f-ide-command-target-value/ "7f. Selenium IDE – Command, target and value")
\ No newline at end of file
# 7 楼 Selenium IDE –命令,目标和值
# 7 楼 Selenium IDE – 命令,目标和值
> 原文: [https://javabeginnerstutorial.com/selenium/7f-ide-command-target-value/](https://javabeginnerstutorial.com/selenium/7f-ide-command-target-value/)
......@@ -41,4 +41,4 @@ ew! 记住整个命令列表以及它们的语法,必需的参数及其描
###### 下一篇文章
##### [7 克。 Selenium IDE –记录和运行测试用例](https://javabeginnerstutorial.com/selenium/7g-ide-recording-test-case/ "7g. Selenium IDE – Recording and running a test case")
\ No newline at end of file
##### [7 克。 Selenium IDE – 记录和运行测试用例](https://javabeginnerstutorial.com/selenium/7g-ide-recording-test-case/ "7g. Selenium IDE – Recording and running a test case")
\ No newline at end of file
# 7 克 Selenium IDE –记录和运行测试用例
# 7 克 Selenium IDE – 记录和运行测试用例
> 原文: [https://javabeginnerstutorial.com/selenium/7g-ide-recording-test-case/](https://javabeginnerstutorial.com/selenium/7g-ide-recording-test-case/)
......
......@@ -6,13 +6,13 @@
![Test Script](img/5e6a31e752f4393906936f5e686f5d93.png)
大字警报! **Selenese** –就是一组硒命令。 这些命令的序列构成一个*测试脚本。* 每行是一个 Selenium 命令,具有三个部分,即 Command,Target 和 Value。
大字警报! **Selenese** 就是一组硒命令。 这些命令的序列构成一个*测试脚本。* 每行是一个 Selenium 命令,具有三个部分,即 Command,Target 和 Value。
*命令*-做什么/需要执行什么动作
*目标* –必须在何处(网络元素)进行操作
*目标* 必须在何处(网络元素)进行操作
*值* –必须将哪些数据传递给目标
*值* 必须将哪些数据传递给目标
一些命令并不总是需要目标和值。 例如,“ close”命令用于关闭窗口。 而“点击”命令需要一个目标,而“类型”命令则需要目标和价值。
......@@ -45,11 +45,11 @@ Selenium 命令具有三种不同的样式:*操作,访问器*和*断言。*
断言有三种模式,
*置位*” –当“声明”失败时,将立即停止测试执行。 测试脚本的其余部分未执行。
*置位*” – 当“声明”失败时,将立即停止测试执行。 测试脚本的其余部分未执行。
*验证*” –当“验证”失败时,Selenium IDE 用红色记录失败,然后继续执行。
*验证*” – 当“验证”失败时,Selenium IDE 用红色记录失败,然后继续执行。
*waitFor* ” –等待特定条件变为真,然后继续执行下一个命令。 默认情况下,超时值设置为 30 秒。 可以将其更改为所需的值。 失败时,测试执行将继续进行下一步。 Selenium IDE 日志窗格中记录了失败。
*waitFor* ” – 等待特定条件变为真,然后继续执行下一个命令。 默认情况下,超时值设置为 30 秒。 可以将其更改为所需的值。 失败时,测试执行将继续进行下一步。 Selenium IDE 日志窗格中记录了失败。
| **命令** | **说明** |
| verifyTitle / assertTitle | 验证预期的页面标题 |
......@@ -65,4 +65,4 @@ Selenium 命令具有三种不同的样式:*操作,访问器*和*断言。*
###### 下一篇文章
##### [7i。 Selenium IDE –设置超时,断点,起点](https://javabeginnerstutorial.com/selenium/7i-ide-timeouts-breakpoints-startpoints/ "7i. Selenium IDE – Setting timeouts, breakpoints, start points")
\ No newline at end of file
##### [7i。 Selenium IDE – 设置超时,断点,起点](https://javabeginnerstutorial.com/selenium/7i-ide-timeouts-breakpoints-startpoints/ "7i. Selenium IDE – Setting timeouts, breakpoints, start points")
\ No newline at end of file
# 7i。 Selenium IDE –设置超时,断点,起点
# 7i。 Selenium IDE – 设置超时,断点,起点
> 原文: [https://javabeginnerstutorial.com/selenium/7i-ide-timeouts-breakpoints-startpoints/](https://javabeginnerstutorial.com/selenium/7i-ide-timeouts-breakpoints-startpoints/)
生活不仅要在 *Magic Meadows* 的土地上玩耍,暂停和停止,还应有更多! 欢迎回到 Selenium IDE 上的另一篇有趣的文章!
自定义默认超时值这有什么用? 嗯,让我们看看...
自定义默认超时值这有什么用? 嗯,让我们看看...
并非网络上的所有事情都如我们所愿发生(如果这样,生活会好得多)。 有时,网页上的特定 Web 元素显示的速度比预期的慢,即以较慢的速度可访问。 这可能会导致在回放我们的自动化测试用例并完全停止执行时出错。 这不是我们所希望的!
......@@ -16,7 +16,7 @@
上图突出显示的该值表示 Selenium IDE 在生成错误之前希望等待测试步骤执行的时间(以毫秒为单位)。 变得硬核,该请求已发送到服务器,但由于默认值设置为 30000ms(即 30s),因此在 30 秒内没有任何响应。 该值可以适当地增加或减少以适合我们的需求。 这样就克服了超时错误! 欢呼!!!
***BrainBell*** *–练习!* 是的,这一点很重要。 不要只盯着屏幕。 输入并执行一些测试方案。 如果我为您做一切,那么您的大脑健康就不会长久。 因此,准备好前进,走在那些坎 bump 的道路上吧!
***BrainBell*** * 练习!* 是的,这一点很重要。 不要只盯着屏幕。 输入并执行一些测试方案。 如果我为您做一切,那么您的大脑健康就不会长久。 因此,准备好前进,走在那些坎 bump 的道路上吧!
**下一步:** *断点如何工作?* 询问者可能希望知道……
......@@ -64,4 +64,4 @@
###### 下一篇文章
##### [7j。 Selenium IDE –调试](https://javabeginnerstutorial.com/selenium/7j-ide-debugging/ "7j. Selenium IDE – Debugging")
\ No newline at end of file
##### [7j。 Selenium IDE – 调试](https://javabeginnerstutorial.com/selenium/7j-ide-debugging/ "7j. Selenium IDE – Debugging")
\ No newline at end of file
# 7j。 Selenium IDE –调试
# 7j。 Selenium IDE – 调试
> 原文: [https://javabeginnerstutorial.com/selenium/7j-ide-debugging/](https://javabeginnerstutorial.com/selenium/7j-ide-debugging/)
......@@ -12,7 +12,7 @@ Hiya 测试人员! 欢迎回到我们针对硒初学者的全职领导者的
***<u>断点和起点</u>***
(有关详细说明,请参阅我以前的博客“ [7i。Selenium IDE –设置超时,断点,起点](https://javabeginnerstutorial.com/selenium/7i-ide-timeouts-breakpoints-startpoints/)”)
(有关详细说明,请参阅我以前的博客“ [7i。Selenium IDE – 设置超时,断点,起点](https://javabeginnerstutorial.com/selenium/7i-ide-timeouts-breakpoints-startpoints/)”)
* **断点**使我们能够运行测试用例中的特定命令,并在该点停止检查行为。
* 确保在要检查的命令之前在命令上设置一个断点。
......@@ -78,4 +78,4 @@ Hiya 测试人员! 欢迎回到我们针对硒初学者的全职领导者的
###### 下一篇文章
##### [7k。 Selenium IDE –定位元素(按 ID,名称,链接文本)](https://javabeginnerstutorial.com/selenium/7k-ide-locating-elements/ "7k. Selenium IDE – Locating Elements (by Id, Name, Link Text)")
\ No newline at end of file
##### [7k。 Selenium IDE – 定位元素(按 ID,名称,链接文本)](https://javabeginnerstutorial.com/selenium/7k-ide-locating-elements/ "7k. Selenium IDE – Locating Elements (by Id, Name, Link Text)")
\ No newline at end of file
# 7k。 Selenium IDE –定位元素(按 ID,名称,链接文本)
# 7k。 Selenium IDE – 定位元素(按 ID,名称,链接文本)
> 原文: [https://javabeginnerstutorial.com/selenium/7k-ide-locating-elements/](https://javabeginnerstutorial.com/selenium/7k-ide-locating-elements/)
......@@ -81,4 +81,4 @@
###### 下一篇文章
##### [7l。 Selenium IDE –定位元素(续)。](https://javabeginnerstutorial.com/selenium/7l-ide-locating-elements-contd/ "7l. Selenium IDE – Locating Elements Contd.")
\ No newline at end of file
##### [7l。 Selenium IDE – 定位元素(续)。](https://javabeginnerstutorial.com/selenium/7l-ide-locating-elements-contd/ "7l. Selenium IDE – Locating Elements Contd.")
\ No newline at end of file
# 7 升 Selenium IDE –定位元素(续)。
# 7 升 Selenium IDE – 定位元素(续)。
> 原文: [https://javabeginnerstutorial.com/selenium/7l-ide-locating-elements-contd/](https://javabeginnerstutorial.com/selenium/7l-ide-locating-elements-contd/)
......@@ -112,17 +112,17 @@ HTML 标记和元素的 ID 与井号(#)一起使用。
![By DOM code](img/4451e94cea0e0ce7ff2ee5d23b3bbb79.png)
*方法 1* :document.getElementById(“ testForm”)–使用元素的 ID。
*方法 1* :document.getElementById(“ testForm”)– 使用元素的 ID。
*方法 2* :document.forms [0] –“表单”将返回文档中使用的所有表单的集合。 因此,使用索引以唯一的方式指定被测元素。
*方法 3* :document.forms [0] .user1 –第一种形式,访问 user1 元素。
*方法 3* :document.forms [0] .user1 – 第一种形式,访问 user1 元素。
*方法 4* :document.getElementsByName(“ seatingClass”)[1] –“ getElementsByName”也将返回括号内指定名称相同的元素集合。 因此,索引返回所需的元素。 在这种情况下,可以访问业务单选按钮。 如果使用索引[0],则可以访问经济单选按钮。
*方法 5* :访问 document.forms [“ testForm”]。elements [“ user2”] –名为“ testForm”的表单的 user2。
*方法 5* :访问 document.forms [“ testForm”]。elements [“ user2”] – 名为“ testForm”的表单的 user2。
*方法 6* :document.forms [1] .elements [2] –这将返回“ seatingClassForm”中的“第一个”单选按钮。
*方法 6* :document.forms [1] .elements [2] – 这将返回“ seatingClassForm”中的“第一个”单选按钮。
现在是时候使用 Selenium IDE 探索 Web 应用程序的 DOM 了。
......@@ -130,7 +130,7 @@ HTML 标记和元素的 ID 与井号(#)一起使用。
XPath 是一种语法,用于在 XML 文档中导航和定位节点。 由于 HTML 只是 XML 的实现,因此可以使用 XPath 策略来查找所需的元素。
如果找不到合适的 Id,名称或类等来查找元素,则可以使用 XPath。 使用 XPath 定位元素有两种。 一个是绝对路径(不建议使用),因为它会在对现有 HTML 代码进行最小改动的情况下中断。 另一个选项是相对路径使用 ID 或名称查找附近的元素,并使用两者之间的关系使用 XPath 查找所需的元素。 因此,几乎可以使用 XPath 策略定位网页上的任何元素。
如果找不到合适的 Id,名称或类等来查找元素,则可以使用 XPath。 使用 XPath 定位元素有两种。 一个是绝对路径(不建议使用),因为它会在对现有 HTML 代码进行最小改动的情况下中断。 另一个选项是相对路径使用 ID 或名称查找附近的元素,并使用两者之间的关系使用 XPath 查找所需的元素。 因此,几乎可以使用 XPath 策略定位网页上的任何元素。
这种定位策略非常复杂,通常是高级硒用户首选的定位策略。 但是不用担心! 为了使整个 XPath 查找方法变得容易,我们将“ Firebug”作为 Firefox 浏览器的附加组件。 很快您就会遇到一篇博客文章,该文章完全致力于 Firebug 的安装和使用! 欢呼!!
......@@ -160,4 +160,4 @@ XPath 是一种语法,用于在 XML 文档中导航和定位节点。 由于 H
###### 下一篇文章
##### [7m。 Selenium IDE –声明和验证](https://javabeginnerstutorial.com/selenium/7m-ide-assert-verify/ "7m. Selenium IDE – Assert and Verify")
\ No newline at end of file
##### [7m。 Selenium IDE – 声明和验证](https://javabeginnerstutorial.com/selenium/7m-ide-assert-verify/ "7m. Selenium IDE – Assert and Verify")
\ No newline at end of file
# 7m。 Selenium IDE –声明和验证
# 7m。 Selenium IDE – 声明和验证
> 原文: [https://javabeginnerstutorial.com/selenium/7m-ide-assert-verify/](https://javabeginnerstutorial.com/selenium/7m-ide-assert-verify/)
......@@ -44,4 +44,4 @@ Hiya 测试人员! 凝视水晶球,我发现在日常测试过程中非常
###### 下一篇文章
##### [7n。 Selenium IDE –将 Firebug 用作优势](https://javabeginnerstutorial.com/selenium/7n-ide-using-firebug/ "7n. Selenium IDE – Using firebug as an advantage")
\ No newline at end of file
##### [7n。 Selenium IDE – 将 Firebug 用作优势](https://javabeginnerstutorial.com/selenium/7n-ide-using-firebug/ "7n. Selenium IDE – Using firebug as an advantage")
\ No newline at end of file
# 7n。 Selenium IDE –利用 Firebug 的优势
# 7n。 Selenium IDE – 利用 Firebug 的优势
> 原文: [https://javabeginnerstutorial.com/selenium/7n-ide-using-firebug/](https://javabeginnerstutorial.com/selenium/7n-ide-using-firebug/)
......@@ -40,4 +40,4 @@ Firebug 图标也会自动添加到浏览器的工具栏中。
###### 下一篇文章
##### [7o。 Selenium IDE –以所需的语言导出测试用例](https://javabeginnerstutorial.com/selenium/7o-ide-export-testcase/ "7o. Selenium IDE – Export test cases in desired language")
\ No newline at end of file
##### [7o。 Selenium IDE – 以所需的语言导出测试用例](https://javabeginnerstutorial.com/selenium/7o-ide-export-testcase/ "7o. Selenium IDE – Export test cases in desired language")
\ No newline at end of file
# 7 点 Selenium IDE –以所需的语言导出测试用例
# 7 点 Selenium IDE – 以所需的语言导出测试用例
> 原文: [https://javabeginnerstutorial.com/selenium/7o-ide-export-testcase/](https://javabeginnerstutorial.com/selenium/7o-ide-export-testcase/)
......@@ -46,4 +46,4 @@
###### 下一篇文章
##### [7 分。 Selenium IDE –其他功能](https://javabeginnerstutorial.com/selenium/7p-ide-features/ "7p. Selenium IDE – Other Features")
\ No newline at end of file
##### [7 分。 Selenium IDE – 其他功能](https://javabeginnerstutorial.com/selenium/7p-ide-features/ "7p. Selenium IDE – Other Features")
\ No newline at end of file
# 7 便士 Selenium IDE –其他功能
# 7 便士 Selenium IDE – 其他功能
> 原文: [https://javabeginnerstutorial.com/selenium/7p-ide-features/](https://javabeginnerstutorial.com/selenium/7p-ide-features/)
......@@ -55,4 +55,4 @@ Selenium 涉及的一项主要活动是使用不同的定位器来识别 Web 元
###### 下一篇文章
##### [7q。 Selenium IDE –快速浏览插件](https://javabeginnerstutorial.com/selenium/7q-ide-plugins/ "7q. Selenium IDE – A quick peek at Plugins")
\ No newline at end of file
##### [7q。 Selenium IDE – 快速浏览插件](https://javabeginnerstutorial.com/selenium/7q-ide-plugins/ "7q. Selenium IDE – A quick peek at Plugins")
\ No newline at end of file
# 7q。 Selenium IDE –快速浏览插件
# 7q。 Selenium IDE – 快速浏览插件
> 原文: [https://javabeginnerstutorial.com/selenium/7q-ide-plugins/](https://javabeginnerstutorial.com/selenium/7q-ide-plugins/)
......@@ -102,4 +102,4 @@
###### 下一篇文章
##### [7r。 Selenium IDE –暂停和反射](https://javabeginnerstutorial.com/selenium/7r-ide-pause-reflect/ "7r. Selenium IDE – Pause and Reflect")
\ No newline at end of file
##### [7r。 Selenium IDE – 暂停和反射](https://javabeginnerstutorial.com/selenium/7r-ide-pause-reflect/ "7r. Selenium IDE – Pause and Reflect")
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册