小编Nic*_*ick的帖子

Selenium WebDriver:等待加载JavaScript的复杂页面

我有一个用Selenium测试的Web应用程序.页面加载时会运行很多JavaScript.
这段JavaScript代码编写得不是很好,但我无法改变任何东西.所以等待元素出现在DOM中的findElement()方法不是一种选择.
我想在Java中创建一个通用函数来等待页面加载,可能的解决方案是:

  • 从WebDriver运行JavaScript脚本并将结果存储document.body.innerHTML在字符串变量中body.
  • body变量与之前版本进行比较body.如果它们相同则设置增量计数器,notChangedCount否则设置notChangedCount为零.
  • 等待一个小时(例如50毫秒).
  • 如果页面没有改变一段时间(例如500毫秒),notChangedCount >= 10那么退出循环,否则循环到第一步.

你认为这是一个有效的解决方案吗?

c# java selenium webdriver selenium-webdriver

95
推荐指数
6
解决办法
14万
查看次数

Cucumber-jvm线程安全吗?

我想在多个线程中运行相同的Cucumber测试.更具体地说,我有一组功能,在一个线程中运行这些功能可以正常工作.我使用JSON格式化程序来记录每个步骤的运行时间.现在我想做负载测试.我更关心多线程环境中每个功能/步骤的运行时间.所以我创建了多个线程,每个线程都运行在同一个功能集上.每个线程都有自己的JSON报告.理论上这可能吗?

对于某些项目设置原因,我无法使用JUnit运行程序.所以我不得不采用CLI方式:

        long threadId = Thread.currentThread().getId();
        String jsonFilename = String.format("json:run/cucumber%d.json", threadId);

            String argv[] = new String[]{
                "--glue",
                "com.some.package",
                "--format",
                jsonFilename,
                "d:\\features"};

        // Do not call Main.run() directly. It has a System.exit() call at the end.             
        // Main.run(argv, Thread.currentThread().getContextClassLoader());

        // Copied the same code from Main.run(). 
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        RuntimeOptions runtimeOptions = new RuntimeOptions(new Env("cucumber-jvm"), argv);
        ResourceLoader resourceLoader = new MultiLoader(classLoader);
        ClassFinder classFinder = new ResourceLoaderClassFinder(resourceLoader, classLoader);
        Runtime runtime = new Runtime(resourceLoader, classFinder, classLoader, runtimeOptions);
        runtime.writeStepdefsJson();
        runtime.run();      
Run Code Online (Sandbox Code Playgroud)

我试图为每个Cucumber运行创建一个单独的线程.问题是,只有一个线程有一个有效的JSON报告.所有其他线程只创建空JSON文件.这是黄瓜的设计还是我错过了什么?

java multithreading gradle gpars cucumber-jvm

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

将YAML反序列化为自定义类型

我目前正在尝试使用YamlDotNet库将YAML文档反序列化为标准.NET对象,例如string用于标量值和Dictionary<string, object>映射。

我猜Deserializer该类是最好的选择,但其输出是objectDictionary<object>。我试过实现这样的自定义INodeTypeResolver

class MyNodeTypeResolver : INodeTypeResolver
{
    bool INodeTypeResolver.Resolve(NodeEvent nodeEvent, ref Type currentType)
    {
        if (currentType == typeof(object))
        {
            if (nodeEvent is SequenceStart)
                currentType = typeof(List<object>);
            else if (nodeEvent is MappingStart)
                currentType = typeof(Dictionary<string, object>);
            else if (nodeEvent is Scalar)
                currentType = typeof(string);

            return true;
        }

        return false;
    }
}
Run Code Online (Sandbox Code Playgroud)

并像这样使用它:

Deserializer deserializer = new Deserializer();
deserializer.TypeResolvers.Add(new MyNodeTypeResolver());
var res = deserializer.Deserialize(input);
Run Code Online (Sandbox Code Playgroud)

但这似乎没有任何效果。有什么方法可以改变产生的对象的类型Deserializer吗?

c# yamldotnet

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

Python脚本未在Windows中删除Git文件

我正在使用以下代码删除包含git repo的目录:

import errno
import os
import stat
import shutil


def clear_dir(path):
    shutil.rmtree(path, ignore_errors=False, onerror=handle_remove_readonly)


def handle_remove_readonly(func, path, exc):
  excvalue = exc[1]
  if func in (os.rmdir, os.remove) and excvalue.errno == errno.EACCES:
      os.chmod(path, stat.S_IRWXU| stat.S_IRWXG| stat.S_IRWXO) # 0777
      func(path)
  else:
      raise
Run Code Online (Sandbox Code Playgroud)

此代码应能很好地处理只读文件。我可以从Windows资源管理器中删除目录/文件夹,但是当我运行以下代码时:

if __name__ == '__main__':
    clear_dir(r'c:\path\to\ci-monitor')
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

  File "C:\Users\m45914\code\ci-monitor\utils\filehandling.py", line 8, in clear_dir                              
    shutil.rmtree(path, ignore_errors=False, onerror=handle_remove_readonly)                                      
  File "C:\Users\m45914\AppData\Local\Programs\Python\Python35\lib\shutil.py", line 488, in rmtree                
    return _rmtree_unsafe(path, onerror)                                                                          
  File "C:\Users\m45914\AppData\Local\Programs\Python\Python35\lib\shutil.py", line 378, in _rmtree_unsafe        
    _rmtree_unsafe(fullname, onerror)                                                                             
  File "C:\Users\m45914\AppData\Local\Programs\Python\Python35\lib\shutil.py", line 378, in _rmtree_unsafe        
    _rmtree_unsafe(fullname, …
Run Code Online (Sandbox Code Playgroud)

python windows git delete-file

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