【问题标题】:Test Automation - Validate text rendering测试自动化 - 验证文本渲染
【发布时间】:2014-09-13 17:43:39
【问题描述】:

我们主要使用 Selenium 和 Java 为 Web 应用程序进行测试自动化,并且有一个关于如何验证渲染或文本的问题。 有没有一种方法可以使用任何自动化工具找出文本是否被截断或显示在容器(div、按钮、跨度等)之外? 有时,当我们对内容进行本地化时,我们会发现标签不适合它们的容器,因为字符的大小因语言而异。

【问题讨论】:

    标签: selenium localization automation html-rendering


    【解决方案1】:

    我会推荐以下内容:

    查看http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/Dimension.html 库; 文本分析算法我建议如下:

    1) 您正在选择网页的边框并将页面的边框初始化为 webElements;

    Stirng cssBorder="abracadabra";
    WebElement border=driver.findElement(By.cssSelector(cssBorder));
    

    2) 然后你会发现所有代表文本的 webElements:

       String cssText1="...";
       String cssText2="....";
    ......
       WebElement text1=driver.findElement(By.cssSelector(cssText1));
       WebElement text2=driver.findElement(By.cssSelector(cssText2));
    

    3) 在上述步骤之后,将getSize(); getLocation(); 函数应用于找到的 webElements:

    text1.getSize();
    text1.getLocation();
    

    根据这些函数将返回的结果: 例如:

    {'y': 202, 'x': 165}
    {'width': 77, 'height': 22}
    

    您将能够比较返回的结果并分析 webElements 的相对位置;

    这里也提示您的问题:Selenium: get coordinates or dimensions of element with Python

    希望对你有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-12-31
      • 1970-01-01
      • 1970-01-01
      • 2010-11-27
      • 2020-12-16
      • 2012-03-22
      • 1970-01-01
      相关资源
      最近更新 更多