小编Ser*_*kov的帖子

量角器开关

我有一个angularjs应用程序包含一个iframe,显示允许登录到另一个网站的页面.我试图在iframe中包含的字段中放置一些值,但我找不到使用任何定位器的元素.

这是我的测试:

describe("Harvest", function() {

  beforeEach(function () {

browser.get('http://localhost:8110/');

expect(browser.getCurrentUrl()).toMatch('_*#/login$');

element(by.model('user.username')).sendKeys('sam');
element(by.model('user.password')).sendKeys('pass');

element(by.id('bt_signin')).click();

  });

  afterEach(function () {
    browser.executeScript('window.sessionStorage.clear();');
  });

  describe('A user', function () {

beforeEach(function () {
  browser.get('http://localhost:8110/');
});

it('should be able to obtain an access token from harvest', function () {
  expect(browser.getCurrentUrl()).toMatch('_*#/home$');

  //Display and close the window
  element(by.id('btHarvest')).click();

  expect(element(by.id('modalHarvest')).isPresent()).toBe(true);

  element(by.id('btCloseModal')).click();

  expect(element(by.id('modalHarvest')).isPresent()).toBe(false);

  //Authenticate into harvest
  element(by.id('btHarvest')).click();

  expect(element(by.id('modalHarvest')).isPresent()).toBe(true);

  browser.switchTo().frame('iframeHarvest');

  //It fails here with a null exceptions, guess it can't find it
  element(by.id('email')).sendKeys(browser.params.harvestLogins.user);
  element(by.id('user_password')).sendKeys(browser.params.harvestLogins.password);
  element(by.id('sign-in-button')).click();

  expect(element(by.name('commit')).isPresent()).toBe(true);

  browser.driver.switchTo().defaultContent();



});

});

});
Run Code Online (Sandbox Code Playgroud)

这是生成的异常

1) …
Run Code Online (Sandbox Code Playgroud)

webdriver angularjs protractor

5
推荐指数
1
解决办法
7993
查看次数

Jasmine 'expect(...).withContext 不是函数'错误

我正在寻找一种在 Jasmine 中使失败消息更具描述性的方法,并发现此功能https://jasmine.github.io/api/edge/matchers.html#withContext

所以我在我的量角器框架中尝试这样

expect(true).withContext("something else").toBe(false);

运行测试并得到错误 - Failed: expect(...).withContext is not a function

这个特性是从 Jasmine 3.3.0 开始实现的,所以我检查了我的 package.json 并看到了"jasmine": "^3.3.1",并且 package-lock.json 有

"jasmine-core": {
      "version": "3.3.0",
Run Code Online (Sandbox Code Playgroud)

任何想法有什么问题?

jasmine protractor

5
推荐指数
1
解决办法
1059
查看次数

在子任务完成后让 grunt 运行任务

问题

我有一项艰巨的任务来启动自动化测试。逻辑如下:

清理.tmp文件夹 -> 以 .xlx 格式查找所需的数据文件 -> 在文件.tmp夹下以 JSON 格式转换文件 -> 开始对转换后的文件进行测试

它工作正常,直到数据文件变得非常大,并且测试在转换文件的子任务完成之前开始

我如何让咕噜声等到子任务完成,不多/不少?

到目前为止我尝试过的

我已经尝试了几种使convert-data-sheet任务异步但没有任何运气的方法。

1.显然我尝试的第一件事是这个

// register task for converting data sheet
grunt.registerTask('convert-data-sheet', 'task for converting xslx file into json', function(product, tenant, environment, codeBase) {
    
   let done = this.async();
   /*
    Some code here, not essential to the question
    */
    // run conversion for each sheet
    for (let i = 0; i < sheetTabs.length; i++) {
        dst = path.resolve(__dirname, './protractor/.tmp_files/test_data', …
Run Code Online (Sandbox Code Playgroud)

javascript gruntjs protractor

5
推荐指数
0
解决办法
160
查看次数

如何使量角器中的自动化测试脚本等待,直到页面完全加载

不,但是真的!我知道这个通用问题已被问过数千次,但有一些更具体的问题对我来说看起来可行,因此我想知道如何实现它

问题

我正在使用Protractor测试一个角度应用程序。在应用程序内部,我想验证当我单击链接时,我是否被重定向到正确的页面(非角度)。问题是,在我到达我正在验证的页面之前,url 会更改 3 次左右(发生多次重定向),因此我无法让等待函数等到页面完全加载

我尝试过的/什么对我不起作用

  1. 我反对browser.sleep()超过1000毫秒!
  2. browser.waitForAngular()因为这不是一个有角度的页面
  3. ExpectedConditions.urlIs()url 是我断言的变量
  4. ExpectedConditions.presenseOf()页面可能会发生变化,所以我不能依赖里面的元素
  5. browser.executeScript("return window.document.readyState")立即返回compete,尽管页面仍在加载(我确定这就是我需要的,但这也不起作用)
  6. 我什至尝试添加一个等待innerHtml整个页面至少 3 秒不发生变化的函数,但它失败了,因为有时重定向之间会出现超过 3 秒的暂停。任何超过 3 秒的超时都不是合理的超时

问题

我注意到,当浏览器加载页面时,Reload this page按钮将其状态更改为Stop loading this page(X 图标),直到我重定向到最终页面(下面的屏幕截图)。那么问题是有没有办法让量角器指向与chrome用来选择显示哪个图标相同的条件?

在此输入图像描述

在此输入图像描述

如果不完全相同,但如何使量角器挂起直到页面完全加载

需要考虑的重要事项

显然,我可以做很多肮脏的解决方案,例如显式等待。但我每隔一段时间就会回到这个问题,所以我对这些肮脏的解决方案不感兴趣,这些解决方案在 70% 的时间内针对特定原因起作用

document.load() PS 我认为该按钮会更改event上的图标。但我不知道应该在控制台中写什么,以便该脚本在刷新页面时记录消息

javascript google-chrome webdriver selenium-chromedriver protractor

5
推荐指数
1
解决办法
779
查看次数

Python 不按顺序打印消息

如果我有这个代码

def soft_assert(condition):
    if not condition:
        print('start')
        traceback.print_stack()
        print('finish')

soft_assert(False)
soft_assert(False)
Run Code Online (Sandbox Code Playgroud)

每次运行时输出都不同:

  File "/Users/spleshakov/Documents/api-testing-with-pytest/tenants/test_uc.py", line 38, in <module>
    soft_assert(False, 'message 1')
  File "/Users/spleshakov/Documents/api-testing-with-pytest/tenants/test_uc.py", line 30, in soft_assert
    traceback.print_stack()
  File "/Users/spleshakov/Documents/api-testing-with-pytest/tenants/test_uc.py", line 41, in <module>
    soft_assert(False, 'message 4')
  File "/Users/spleshakov/Documents/api-testing-with-pytest/tenants/test_uc.py", line 30, in soft_assert
    traceback.print_stack()
start
finish
start
finish
Run Code Online (Sandbox Code Playgroud)

或者

start
finish
start
finish
  File "/Users/spleshakov/Documents/api-testing-with-pytest/tenants/test_uc.py", line 38, in <module>
    soft_assert(False)
  File "/Users/spleshakov/Documents/api-testing-with-pytest/tenants/test_uc.py", line 30, in soft_assert
    traceback.print_stack()
  File "/Users/spleshakov/Documents/api-testing-with-pytest/tenants/test_uc.py", line 41, in <module>
    soft_assert(False)
  File "/Users/spleshakov/Documents/api-testing-with-pytest/tenants/test_uc.py", line 30, in soft_assert …
Run Code Online (Sandbox Code Playgroud)

python stdout stderr python-3.x python-3.7

3
推荐指数
1
解决办法
63
查看次数

量角器中的 SEELENIUM_PROMISE_MANAGER、browser.ignoreSynchronization 和 browser.waitForAngularEnabled() 有什么区别?

有人可以向我解释SELENIUM_PROMISE_MANAGER,browser.ignoreSynchronizationbrowser.waitForAngularEnabled()Protractor之间的区别吗?

谢谢

automation protractor

2
推荐指数
1
解决办法
1996
查看次数

console.log(myFunction()) 返回未定义

我是 JavaScript 的新手,我尝试使用它来理解所有的进进出出。我写的

function greet() {
    console.log("Hi");
};

console.log(greet());
Run Code Online (Sandbox Code Playgroud)

它在控制台中的结果是

> Hi app.js:2 
> undefined app.js:4
Run Code Online (Sandbox Code Playgroud)

我认为这是因为greet()insideconsole.log首先调用函数,该函数打印出"Hi". 我们得到第一行日志。但是第二行是从哪里来的呢?

然后我想,因为Hi是 的总体结果greet(),然后console.log基本上调用了变量Hi,但在这种情况下,结果将是is not defined,不是undefined

javascript undefined console.log

1
推荐指数
1
解决办法
3029
查看次数

量角器中所有可用的钩子

是否有任何链接提供有关量角器中所有可用挂钩的信息。例如,在 webdriverIO 中,我们有以下内容:

    onPrepare: function (config, capabilities) {},

    beforeSession: function (config, capabilities, specs) {},

    before: function (capabilities, specs) {},

    beforeSuite: function (suite) {},

    beforeHook: function () {},

    afterHook: function () {},

    beforeTest: function (test) {},

    beforeCommand: function (commandName, args) {},

    afterCommand: function (commandName, args, result, error) {},

    afterTest: function (test) {},

    afterSuite: function (suite) {},

    after: function (result, capabilities, specs) {},

    afterSession: function (config, capabilities, specs) {},

    onComplete: function (exitCode, config, capabilities, results) {},

    onReload: function(oldSessionId, newSessionId) {},
Run Code Online (Sandbox Code Playgroud)

我正在量角器中寻找类似的钩子。

protractor

1
推荐指数
1
解决办法
3201
查看次数

不断收到 TypeError: config.suite.split is not a function 在运行回归测试时

运行示例回归测试时出现以下错误:

    TypeError: config.suite.split is not a function
Run Code Online (Sandbox Code Playgroud)

这是配置文件。看起来不错,但我一定错过了一些东西,但我无法诚实地找到它可能是什么。

Configuration.js 文件(这是几天前工作)

var Jasmine2HtmlReporter = require('protractor-jasmine2-html-reporter');

exports.config = {
  seleniumAddress: 'http://localhost:4444/wd/hub',
  specs: ['PageObjectLocator2.js'],
  capabilities: {
    browserName: 'chrome'
  },
  
  onPrepare: function() {
      browser.driver.manage().window().maximize(); 
     
      jasmine.getEnv().addReporter(
                new Jasmine2HtmlReporter({
                  savePath: 'target/screenshots'
                })
              );
          
     
     
      
  },// end of onPrepare
  
  suite:
      {
      Smoke  : ['ChainLocator.js','dropDowns.js'],
      Regression : 'nonAnuglarSpec.js'
  
      },
  
  

//Options to be passed to Jasmine-node.
  jasmineNodeOpts: {
    showColors: true, // Use colors in the command line report.
  }
  
}
Run Code Online (Sandbox Code Playgroud)

这是 package.json 文件。可能是这里的问题,但老实说不知道

{
  "name": "LocatorTraining",

  "dependencies": { …
Run Code Online (Sandbox Code Playgroud)

javascript automated-tests protractor

0
推荐指数
1
解决办法
596
查看次数