Selenium测试在Internet Explorer上运行得非常慢

时间:2016-11-07 07:17:57

标签: python selenium internet-explorer-11

我正在为我的应用编写自动化测试。谷歌浏览器上的测试运行正常。但是当我在Internet Explorer 11上运行它们时,它们的运行速度非常慢。当我在chrome上运行它们时,一个测试用例在将近5分钟内完成。但是在IE11上,我已经运行了一个测试案例近3个小时,测试只是第2步。我试过跟随它来加快速度

  1. 我使用了32位Internet Explorer驱动程序(我使用的是64位窗口)。与64位驱动程序相比,它运行速度很快,但仍然非常慢。
  2. 与CSS定位器相比,XPATH很慢,所以我用CSS定位器替换了所有XPATH定位器。它提高了Chrome的速度,但对于Internet Explorer,速度与以前相比没有太大差异。
  3. 我尝试在Internet Explorer的其他网站上运行一些简单的脚本,但它们运行正常。但是当我为myapp编写类似的脚本时,我只是打开一些页面并点击一个按钮,而在Chrome上花了不到10分钟,花了不到1分钟。
  4. 我没有使用任何隐式等待(硬编码等待,比如告诉代码停止执行5秒)。相反,在所有代码中,我使用等待基于某些元素的可见性。这改善了Chrome和Firefox的时间,但对于Internet Explorer,速度并没有提高。
  5. 我还修改了我的代码,以减少对DOM的冗余访问,但这也不会减少测试时间。
  6. 任何人都可以指导我如何更快地使我的测试用例?我的应用程序是用AngularJS编写的,我没有任何访问App代码的权限。我只能在测试方面做得更快。

2 个答案:

答案 0 :(得分:0)

请参阅此github评论: https://github.com/SeleniumHQ/selenium-google-code-issue-archive/issues/5116#issuecomment-192106534

*我认为这可能是个问题,或者

可能是javascript正在创建问题,尝试在测试期间禁用它并查看是否有帮助

并尝试此代码,

import UIKit
import Charts

class SecondViewController: UIViewController, ChartViewDelegate{

var controllerName:String?

@IBOutlet weak var pChartViewA: PieChartView!

@IBOutlet weak var pChartViewB: PieChartView!

@IBOutlet weak var pChartViewC: PieChartView!

@IBOutlet weak var pChartViewD: PieChartView!

override func viewDidLoad() {
    super.viewDidLoad()

    self.pChartViewA.delegate = self
   // self.pChartViewB.delegate = self
    //self.pChartViewC.delegate = self
   // self.pChartViewD.delegate = self

    self.pChartViewA.alpha = 1

    //self.pChartView.delegate = self



    // Pie Chart
    pChartViewA.noDataText = "You need to provide data for the chart."

    let pys1 = Array(1..<10).map { x in return sin(Double(x) / 2.0 / 3.141 * 1.5) * 100.0 }

    let pyse1 = pys1.enumerated().map { x, y in return PieChartDataEntry(value: y, label: String(x)) }

    let pdata = PieChartData()
    let pds1  = PieChartDataSet(values: pyse1, label: "Hello")

    pds1.colors = ChartColorTemplates.vordiplom()

    pdata.addDataSet(pds1)

    let paragraphStyle: NSMutableParagraphStyle = NSParagraphStyle.default.mutableCopy() as! NSMutableParagraphStyle
    paragraphStyle.lineBreakMode = .byTruncatingTail
    paragraphStyle.alignment = .center
    let centerText: NSMutableAttributedString = NSMutableAttributedString(string: "Sample Screening Pie")

    self.pChartViewA.centerAttributedText = centerText

    self.pChartViewA.data = pdata

    self.pChartViewA.chartDescription?.text = "Piechart Demo"



}

@IBAction func ChangeComponent(_ sender: AnyObject) {
    if sender.selectedSegmentIndex == 0 {
        UIView.animate(withDuration: 0.5, animations: {
            self.pChartViewA.alpha = 1
            self.pChartViewB.alpha = 0
            self.pChartViewC.alpha = 0
            self.pChartViewD.alpha = 0

            // Pie Chart
            self.pChartViewA.noDataText = "You need to provide data for the chart."

            let pys1 = Array(1..<10).map { x in return sin(Double(x) / 2.0 / 3.141 * 1.5) * 100.0 }

            let pyse1 = pys1.enumerated().map { x, y in return PieChartDataEntry(value: y, label: String(x)) }

            let pdata = PieChartData()
            let pds1  = PieChartDataSet(values: pyse1, label: "Hello")

            pds1.colors = ChartColorTemplates.vordiplom()

            pdata.addDataSet(pds1)

            let paragraphStyle: NSMutableParagraphStyle = NSParagraphStyle.default.mutableCopy() as! NSMutableParagraphStyle
            paragraphStyle.lineBreakMode = .byTruncatingTail
            paragraphStyle.alignment = .center
            let centerText: NSMutableAttributedString = NSMutableAttributedString(string: "Sample Screening Pie")

            self.pChartViewA.centerAttributedText = centerText

            self.pChartViewA.data = pdata

            self.pChartViewA.chartDescription?.text = "Piechart Demo"              
        })


    } else if sender.selectedSegmentIndex == 1 {
        UIView.animate(withDuration: 0.5, animations: {
            self.pChartViewA.alpha = 0
            self.pChartViewB.alpha = 1
            self.pChartViewC.alpha = 0
            self.pChartViewD.alpha = 0
        })
    }
    else if sender.selectedSegmentIndex == 2 {
        UIView.animate(withDuration: 0.5, animations: {
            self.pChartViewA.alpha = 0
            self.pChartViewB.alpha = 0
            self.pChartViewC.alpha = 1
            self.pChartViewD.alpha = 0
        })
    }
    else if sender.selectedSegmentIndex == 3 {
        UIView.animate(withDuration: 0.5, animations: {
            self.pChartViewA.alpha = 0
            self.pChartViewB.alpha = 0
            self.pChartViewC.alpha = 0
            self.pChartViewD.alpha = 1
        })
    }


}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}



} 
抱歉,我不熟悉python,请转换代码并尝试..

答案 1 :(得分:0)

我发现调用FindElements花了很长时间,只需在下方设置 InternetExplorerOptions 就可以加快速度。

var ieOptions = new InternetExplorerOptions();
ieOptions.EnablePersistentHover = false;