首页 \ 问答 \ 如何防止jQuery UI使用`draggable`属性更改HTML元素?(How to prevent jQuery UI change HTML elements with `draggable` attribute?)

如何防止jQuery UI使用`draggable`属性更改HTML元素?(How to prevent jQuery UI change HTML elements with `draggable` attribute?)

示例: http//codepen.io/anon/pen/wMGbYv 。 如您所见,jQuery UI丢弃draggable属性并添加它自己的类。 如何防止这种顽皮并创建具有draggable属性的元素而不丢弃jQuery UI(最好使用jQuery)?


Example: http://codepen.io/anon/pen/wMGbYv. As you can see, jQuery UI discards draggable attribute and adds it's own classes. How to prevent this naughtiness and create element with draggable attribute without discarding jQuery UI (preferably using jQuery)?


原文:https://stackoverflow.com/questions/34377555
更新时间:2023-03-04 15:03

最满意答案

我尝试确保我的specflow场景不共享任何数据,如果我可以在每次测试之间显式重新生成整个数据库架构。

这可确保只有您在测试中安排的数据才在数据库中

因此,我创建了一个单独的Given步骤,要么运行所有步骤来创建一个帐户(您可以以编程方式调用这些步骤),或者有一个单独的Given步骤,它会使所有使用您需要的信息的数据发生短路。

我还注意到您在测试中明确关闭了浏览器。 我为启动/停止Selenium的Web创建了BeforeScenario / AfterScenario标记。 因此,您的测试只需要测试实际功能,而不是测试Selenium的启动/停止。

public class SeleniumController
{
    public static readonly SeleniumController Instance = new SeleniumController();
    public static readonly TimeSpan DefaultTimeout = TimeSpan.FromSeconds(10);

    public IWebDriver Selenium { get; private set; }

    private void Trace(string message) { Console.WriteLine("-> {0}", message); }

    public void Start()
    {
        if (Selenium != null)
            return;

        string appUrl = ConfigurationManager.AppSettings["AppUrl"];

        var options = new ChromeOptions();
        options.AddArgument("test-type");
        Selenium = new ChromeDriver(options);
        Selenium.Manage().Timeouts().ImplicitlyWait(DefaultTimeout);

        Trace("Selenium started");
    }

    public void Stop()
    {
        if (Selenium == null) return;

        try
        {
            Selenium.Quit();
            Selenium.Dispose();
        }
        catch (Exception ex)
        {
            Debug.WriteLine(ex, "Selenium stop error");
        }
        Selenium = null;
        Trace("Selenium stopped");
    }
}

场景标签

public static class SeleniumSupport
{
    private static bool ReuseWebSession
    {
        get { return ConfigurationManager.AppSettings["ReuseWebSession"] == "true"; }
    }

    [BeforeScenario("web")]
    public static void BeforeWebScenario()
    {
        SeleniumController.Instance.Start();
    }

    [AfterScenario("web")]
    public static void AfterWebScenario()
    {
        if (!ReuseWebSession)
            SeleniumController.Instance.Stop();
    }
}

抽象步骤基类访问selenium webdriver

public abstract class SeleniumStepsBase
{
    protected IWebDriver Selenium { get { return SeleniumController.Instance.Selenium; } }
}

I try to make sure that my specflow scenarios don't share any data, and if i can explicitly regenerate the whole database schema when possible between each test.

This ensures that only data that you have arranged in the test is in the database

So I'd create a separate Given step that either runs through all the steps to create an account (you can call those steps programatically) or have a separate Given step that short circuits all that seeds the db with the information you need.

I also notice that you explicitly close your browser in your tests. I create a BeforeScenario/AfterScenario tag for the web that starts/stops Selenium. So that your tests only need to test the actual functionality and not the starting/stopping of Selenium.

public class SeleniumController
{
    public static readonly SeleniumController Instance = new SeleniumController();
    public static readonly TimeSpan DefaultTimeout = TimeSpan.FromSeconds(10);

    public IWebDriver Selenium { get; private set; }

    private void Trace(string message) { Console.WriteLine("-> {0}", message); }

    public void Start()
    {
        if (Selenium != null)
            return;

        string appUrl = ConfigurationManager.AppSettings["AppUrl"];

        var options = new ChromeOptions();
        options.AddArgument("test-type");
        Selenium = new ChromeDriver(options);
        Selenium.Manage().Timeouts().ImplicitlyWait(DefaultTimeout);

        Trace("Selenium started");
    }

    public void Stop()
    {
        if (Selenium == null) return;

        try
        {
            Selenium.Quit();
            Selenium.Dispose();
        }
        catch (Exception ex)
        {
            Debug.WriteLine(ex, "Selenium stop error");
        }
        Selenium = null;
        Trace("Selenium stopped");
    }
}

scenario tags

public static class SeleniumSupport
{
    private static bool ReuseWebSession
    {
        get { return ConfigurationManager.AppSettings["ReuseWebSession"] == "true"; }
    }

    [BeforeScenario("web")]
    public static void BeforeWebScenario()
    {
        SeleniumController.Instance.Start();
    }

    [AfterScenario("web")]
    public static void AfterWebScenario()
    {
        if (!ReuseWebSession)
            SeleniumController.Instance.Stop();
    }
}

abstract steps base class to access selenium webdriver

public abstract class SeleniumStepsBase
{
    protected IWebDriver Selenium { get { return SeleniumController.Instance.Selenium; } }
}

相关问答

更多
  • 在现场,specflow测试只是普通的mstest单元测试。 所以你应该可以用类似的方法来运行它们: 运行特定场景: mstest /testcontainer:tests.dll /test:GivenMyScenarioWhenIDoSomeStuff 要运行多个特定场景,您可以多次使用/ test标志: mstest /testcontainer:tests.dll /test:GivenMyScenarioWhenIDoSomeStuff /test:GivenMyScenarioWhenIDoS ...
  • 场景大纲和场景模板只是同义词。 没有区别。 两者都定义了scenario_outline步骤。 英语SpecFlow关键词中有几个同义词。 例如, 示例和场景或功能和业务需求 。 为不同的语言定义了不同的同义词,并在国际化文件中指定。 例如英语: "en": { "name": "English", "native": "English", "feature": "Feature|Business Need|Ability", "background": "Background", "s ...
  • 场景: Given a name "test" When I click on the SEARCH button Then the result will be | name | last name | test | fulano | test | siclano 码: [Then("The result will be")] public void ThenTheResultWillBe(Table table) { //check that the result contains all ...
  • 我会选择选项2 - 您正在测试一些用例,您不应该涉及另一个测试测试的用例。 测试包括一些驱动测试的代码和用于执行测试的数据。 因此,如果您需要测试的特殊数据,您应该预先准备它们,而不是通过应用程序逻辑创建它们。 I would go with option 2 - you are testing some use case and you should not involve use cases tested by another tests. Test consists of some code driv ...
  • 每个功能的多个方案都可以,只要它们在逻辑上位于同一区域。 如果您试图解决不同的用例,我可能会建议将其作为新功能。 在您的情况下,看起来两个场景在同一功能下可以很好地适应。 场景大纲类似于NUnit中的TestCase ,如果相同的场景结构只需要采用不同的参数,则只能使用它。 SpecFlow github站点在 此处有关于场景概述的良好文档。 我将总结下面的代码示例。 给定一个特征中的两个场景: Scenario: eat 5 out of 12 Given there are 12 cucumbers ...
  • 我尝试确保我的specflow场景不共享任何数据,如果我可以在每次测试之间显式重新生成整个数据库架构。 这可确保只有您在测试中安排的数据才在数据库中 因此,我创建了一个单独的Given步骤,要么运行所有步骤来创建一个帐户(您可以以编程方式调用这些步骤),或者有一个单独的Given步骤,它会使所有使用您需要的信息的数据发生短路。 我还注意到您在测试中明确关闭了浏览器。 我为启动/停止Selenium的Web创建了BeforeScenario / AfterScenario标记。 因此,您的测试只需要测试实际功 ...
  • 看看你是如何编写这个问题的,看起来你是Specflow的新手。 问题是Specflow不是一种编程语言。 实际上,当您第一次开始查看它时,它的一些语言组件可能会受到妨碍。 如果您正确地遵循BDD方法,那么程序员不应该编写功能文件。 应该是商务人士,这就是语言如此开放的原因。 只需要几个占位符来提供功能和方案名称,然后在每行的开头添加一个简单的单词来表示它是设置操作(给定),还是操作(When)或测试(Then)。 例如,作为开发人员,我可能会提出以下内容作为示例。 Feature: Waking kids ...
  • 我的同事给了我们一个很好的解决方案:情景大纲: Scenario Outline: Channels on different protocols Given The test server is up and running And The previously obtained channel list is reset When I request a list of radio channels for the and Then the resulting ...
  • 我认为这对你选择的跑步者来说更是一个问题。 SpecFlow从测试文件为您生成测试,但不会运行它们。 您可能能够指导您的测试跑步者按照您要求的顺序运行场景。 不过,我的建议是,你不要试图订购你的测试。 每个场景应该完全独立于其他场景,以便运行测试的顺序对结果没有影响。 我想这取决于你的意思是“好”,如果他们按照特定的顺序运行。 :) I think that's more of a question for your test runner of choice. SpecFlow generates the ...
  • 第一:SpecFlow中不支持Pairwise属性。 您必须自己创建每个可能的组合并填写示例表。 第二:你的例子中有一个场景。 这将是一个测试。 你想要的是一个带有示例表的场景大纲。 在这里查看相关信息: http : //specflow.org/documentation/Using-Gherkin-Language-in-SpecFlow/ 完全披露:我是SpecFlow开发人员之一。 First: There is no support of the Pairwise attribute in Sp ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)