当前位置: 首页 > 知识库问答 >
问题:

当我看不到浏览器进行任何交互时,看到量角器cucumber测试通过是正确的吗?

解宏扬
2023-03-14

我是量角器cucumber的新手。我已经写了下面的功能。当我启动量角器protractor.conf.js时,浏览器立即打开然后关闭,然后显示我的测试通过。这是正确的测试功能吗?我想我需要看到登录过程的浏览器交互。

Scenario: Open the browser and login
    Given I am on the login page
    When I should be able to login with my credentials
    When I logout
    Then I should be able to see login page

场景:打开浏览器并登录

√ 鉴于我在登录页面
√ 我何时可以使用我的凭据登录
√ 当我退出
√ 然后我应该可以看到登录页面

登录页面

1个场景(1个通过)4个步骤(4个通过)0m00.005s

this.Given('I am on the login page', function() {

   browser.driver.get(browser.baseUrl);
});

this.When('I should be able to login with my credentials',  function() {
    let inputUsernameField = element(by.css(USERNAME_NAME));
    inputUsernameField.sendKeys(username);
    let inputPasswordField = element(by.css(PASSWORD_NAME));
    inputPasswordField.sendKeys(password);
    element(by.id(LOGIN_BUTTON_ID)).click();
});

this.When('I logout',  function() {

    element(by.className(HAMBERBURGER_MENU_ICON_CLASS)).click();
    element(by.className(LOGOUT_BUTTON_CLASS)).click();
});

this.Then('I should be able to see login page', {timeout:120*1000},function() {

    browser.driver.wait(protractor.ExpectedConditions.presenceOf($('#login_button')), 5000);
});

下面是量角器.conf js

exports.config = {
  seleniumAddress: 'http://localhost:4444/wd/hub',
  getPageTimeout: 600000,
  allScriptsTimeout: 500000,
  defaultTimeoutInterval: 30000,
  framework: 'custom',
  // path relative to the current config file
  frameworkPath: require.resolve('protractor-cucumber-framework'),
  multiCapabilities:
  [
  {
    'browserName': 'chrome'
  },
  {
    'browserName': 'firefox'
  }],

  // Spec patterns are relative to this directory.
  specs: [
    'features/*.feature'
  ],
  baseURL: 'http://localhost:8080/',
  ignoreSynchronization: true,
  cucumberOpts: {
    strict: true,
    require: [
              'hooks/reporter/js',
              'specs/*Spec.js'
            ],
    tags: false,
    profile: false,
    format: 'json:e2e/reports/cucumber-report.json',
    resultJsonOutputFile: 'e2e/reports/cucumber-report.json'
  },

  onPrepare: function() {

    var chai = require('chai');
    chai.use(require('chai-as-promised'));
    global.expect = chai.expect;
    global.baseURL = this.baseURL;
    browser.ignoreSynchronization = true;
    browser.driver.manage().window().maximize();
    browser.waitForAngular();           
    browser.driver.manage().timeouts().implicitlyWait(30000);  
  },

  onComplete: function() {

    const report = require('multiple-cucumber-html-reporter');

    report.generate({
        jsonDir: 'e2e/reports/',
        reportPath: 'e2e/reports/',

    });
  }
}

共有1个答案

邹野
2023-03-14

所以事实证明,如果我没有在函数中传递任何内容作为回调,我需要使用async并等待。这是Javascript语法,而不是Typecript

this.Given('I am on the login page', function() {

   browser.driver.get(browser.baseUrl);
});

    this.Then('I should be able to see login page', {timeout:120*1000},function() {

    browser.driver.wait(protractor.ExpectedConditions.presenceOf($('#login_button')), 5000);
});

更改为带有异步/等待

this.Given('I am on the login page', async() => {

   await browser.driver.get(browser.baseUrl);
});

this.Then('I should be able to see login page', {timeout:120*1000}, async() => {

    await browser.driver.wait(protractor.ExpectedConditions.presenceOf($('#login_button')), 5000);
});
 类似资料:
  • 问题内容: 使用量角器,如何设置/添加并行浏览器进行测试。 示例: 不仅对,还对?还有针对移动设备的简单测试方法吗?说ios8野生动物园还是移动Chrome? 题: 如何编写exports.config对象以支持并行套件测试? 问题答案: 使用量角器,如何设置/添加并行浏览器进行测试。 您需要在以下位置列出浏览器: 还有针对移动设备的简单测试方法吗?说ios8野生动物园还是移动Chrome? 一种

  • 问题内容: 我们使用“grandor”测试内部AngularJS应用程序。 除了功能测试之外,我们还可以在 是什么 基于nodejs 图书馆。“因为是表演 功能“. 使用“detactor perf”,我们可以测量和断言不同的性能 进行浏览器操作时的特征,针对 示例: 现在,对于另一个内部应用程序,我们有一组基于硒的测试 用Python编写。 是否可以使用selenium python检查性能回归

  • 我目前正在运行mvn测试时收到此日志 我的pom.xml是这样的: 我的IssueTest.java如下所示: 我不知道为什么IssueTest.Java没有被正确读取,尽管我在maven surefire插件的构建配置中添加了它。 请告知。

  • 我为我的角度应用程序创建了一个简单的量角器测试。当我单击按钮时,输入值会被设置: e2e 测试期望输入填充“hoera”: 当我用“量角器配置”运行测试时,我得到: 我希望这样的东西:预期的“hoera”等于“hoera”?我如何让它通过,也许在角度设置值之前有一个延迟?这是代码的链接:https://github.com/dimitri-a/protractor_new

  • 问题内容: 运行Angular Protractor测试后是否可以将测试浏览器窗口保持打开状态?我在FireFox中失败了一个艰难的测试,访问网页状态以查看发生了什么非常有用。 问题答案: 您可以使用量角器调试/暂停功能来暂停e2e运行,这最终将使浏览器保持打开状态:此处有更多信息 为此,请在失败的量角器测试上添加此行 还有一个非常有用的工具,称为elementor,您稍后可能需要看看。

  • 上下文: SBT 0.13.0,Scala 2.10.4 由于外部约束,我需要一个自定义目录结构,所以我在test中使用 获取所有测试源并成功编译它们(我可以添加语法错误并导致构建失败) 报告有0个套件、0个测试,并且全部成功 该目录中有几个JUnit风格的scalatest测试 你知道为什么它不接受任何测试吗?我是不是错过了一个场景?还显示空列表。