WebdriverIO - 常用浏览器命令



下面列出了一些 WebdriverIO 中使用的通用浏览器命令:

browser.url(URL)

此命令用于启动一个应用程序,其 URL 作为参数传递。

语法

语法如下:

browser.url('https://the-internet.herokuapp.com/redirector')

首先,按照标题为“使用 WebdriverIO 的成功路径流程”章节中的步骤 1 到 5 进行操作,步骤如下:

步骤 1 - 安装 NodeJS。有关如何执行此安装的详细信息在标题为“使用 NodeJS 入门”的章节中详细介绍。

步骤 2 - 安装 NPM。有关如何执行此安装的详细信息在标题为“NPM 安装”的章节中详细介绍。

步骤 3 - 安装 VS Code。有关如何执行此安装的详细信息在标题为“VS Code 安装”的章节中详细介绍。

步骤 4 - 创建配置文件。有关如何执行此安装的详细信息在标题为“配置文件生成”的章节中详细介绍。

步骤 5 - 创建一个规范文件。有关如何执行此安装的详细信息在标题为“Mocha 安装”的章节中给出。

步骤 6 - 将以下代码添加到创建的 Mocha 规范文件中。

// test suite name
describe('Tutorialspoint application', function(){
   //test case
   it('Identify element with Id', function(){
      // launch url
      browser.url('https://the-internet.herokuapp.com/redirector')
      //identify element with id then click
      $("#redirect").click()
      //obtain page title
      console.log('Page title after click: ' + browser.getTitle())
   });
});

browser.getTitle()

此命令用于获取当前在浏览器中启动的页面的标题。该值以字符串的形式返回。此命令不接受任何参数。如果页面没有标题,则返回空字符串。

语法

语法如下:

browser.getTitle()

首先,按照标题为“使用 WebdriverIO 的成功路径流程”章节中的步骤 1 到 5 进行操作,步骤如下:

步骤 1 - 安装 NodeJS。有关如何执行此安装的详细信息在标题为“使用 NodeJS 入门”的章节中详细介绍。

步骤 2 - 安装 NPM。有关如何执行此安装的详细信息在标题为“NPM 安装”的章节中详细介绍。

步骤 3 - 安装 VS Code。有关如何执行此安装的详细信息在标题为“VS Code 安装”的章节中详细介绍。

步骤 4 - 创建配置文件。有关如何执行此安装的详细信息在标题为“配置文件生成”的章节中详细介绍。

步骤 5 - 创建一个规范文件。有关如何执行此安装的详细信息在标题为“Mocha 安装”的章节中给出。

步骤 6 - 将以下代码添加到创建的 Mocha 规范文件中。

// test suite name
describe('Tutorialspoint Application', function () {
   // test case name
   it('Get Page Title', function (){
      // URL launching
      browser.url("https://tutorialspoint.com/about/about_careers.htm")
      //print page title in console
      console.log(browser.getTitle())
   });    
});

browser.getUrl()

此命令用于获取当前在浏览器中启动的页面的 URL。该值以字符串的形式返回。此命令不接受任何参数。

语法

语法如下:

browser.getUrl()

首先,按照标题为“使用 WebdriverIO 的成功路径流程”章节中的步骤 1 到 5 进行操作,步骤如下:

步骤 1 - 安装 NodeJS。有关如何执行此安装的详细信息在标题为“使用 NodeJS 入门”的章节中详细介绍。

步骤 2 - 安装 NPM。有关如何执行此安装的详细信息在标题为“NPM 安装”的章节中详细介绍。

步骤 3 - 安装 VS Code。有关如何执行此安装的详细信息在标题为“VS Code 安装”的章节中详细介绍。

步骤 4 - 创建配置文件。有关如何执行此安装的详细信息在标题为“配置文件生成”的章节中详细介绍。

步骤 5 - 创建一个规范文件。有关如何执行此安装的详细信息在标题为“Mocha 安装”的章节中给出。

步骤 6 - 将以下代码添加到创建的 Mocha 规范文件中。

// test suite name
describe('Tutorialspoint Application', function () {
   // test case name
   it('Get Url', function (){
      // URL launching
      browser.url("https://tutorialspoint.com/index.htm")
      //print URL in console
      console.log(browser.getUrl())
   });    
});

browser.getPageSource()

此命令用于获取当前在浏览器中启动的页面的页面源代码。该值以字符串的形式返回。此命令不接受任何参数。

语法

语法如下:

browser.getPageSource()

首先,按照标题为“使用 WebdriverIO 的成功路径流程”章节中的步骤 1 到 5 进行操作,步骤如下:

步骤 1 - 安装 NodeJS。有关如何执行此安装的详细信息在标题为“使用 NodeJS 入门”的章节中详细介绍。

步骤 2 - 安装 NPM。有关如何执行此安装的详细信息在标题为“NPM 安装”的章节中详细介绍。

步骤 3 - 安装 VS Code。有关如何执行此安装的详细信息在标题为“VS Code 安装”的章节中详细介绍。

步骤 4 - 创建配置文件。有关如何执行此安装的详细信息在标题为“配置文件生成”的章节中详细介绍。

步骤 5 - 创建一个规范文件。有关如何执行此安装的详细信息在标题为“Mocha 安装”的章节中给出。

步骤 6 - 将以下代码添加到创建的 Mocha 规范文件中。

// test suite name
describe('Tutorialspoint Application', function () {
   // test case name
   it('Get Page Source', function (){
      // URL launching
      browser.url("https://tutorialspoint.com/index.htm")
      //print URL in console
      console.log(browser.getPageSource())
   });    
});

browser.maximizeWindow()

此命令用于最大化当前浏览器窗口。

语法

语法如下:

browser.maximizeWindow()

首先,按照标题为“使用 WebdriverIO 的成功路径流程”章节中的步骤 1 到 5 进行操作,步骤如下:

步骤 1 - 安装 NodeJS。有关如何执行此安装的详细信息在标题为“使用 NodeJS 入门”的章节中详细介绍。

步骤 2 - 安装 NPM。有关如何执行此安装的详细信息在标题为“NPM 安装”的章节中详细介绍。

步骤 3 - 安装 VS Code。有关如何执行此安装的详细信息在标题为“VS Code 安装”的章节中详细介绍。

步骤 4 - 创建配置文件。有关如何执行此安装的详细信息在标题为“配置文件生成”的章节中详细介绍。

步骤 5 - 创建一个规范文件。有关如何执行此安装的详细信息在标题为“Mocha 安装”的章节中给出。

步骤 6 - 将以下代码添加到创建的 Mocha 规范文件中。

// test suite name
describe('Tutorialspoint Application', function () {
   // test case name
   it('Maximise Browser', function (){
      // URL launching
      browser.url("https://tutorialspoint.com/questions/index.php")
      //maximize browser
      browser.maximizeWindow()
   });    
});
广告

© . All rights reserved.