使用iFrame打开新窗口后,测试用例的运行速度非常慢 [英] Testcase running very slow after opening new window with iFrame

查看:104
本文介绍了使用iFrame打开新窗口后,测试用例的运行速度非常慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更多新信息:我现在对为什么测试速度慢感到困惑.我消除了下面描述的对javascript的需求,并且添加了报告来确定发生延迟的地方.这些是以"logger"开头的行.我在这些行后面添加了时间戳,以便您可以看到延迟在哪里.这是一段代码,看起来像是弄乱​​了/花了很长时间(每次10分钟):

EVEN MORE NEW INFORMATOIN: I'm now officialy confused as to why this test is slow. I've eliminated the need for javascript as descripbed below and I've added reporting to determine where things are being delayed. these are the lines that start with "logger". I've added the timestamps behind these lines so you can see where the delay is. This is the section of code where it looks like it messes up/takes pretty long (10min every time):

wait.until(ExpectedConditions.elementToBeClickable(By.id("ID")));
logger.log(LogStatus.INFO, "Waituntill is done and element is clickable"); /** logged as successfull at 17:45:51 */
driver.findElement(By.xpath("//div[@class='CLASS']")).click();
logger.log(LogStatus.INFO, "menu visible"); /** logged as successfull at 17:45:52 */
driver.findElement(By.xpath("//*[@class='CLASS' and text()='TEXT']")).click();
logger.log(LogStatus.INFO, "menu item is available and clickable."); /** logged as successfull at 17:55:47 */

奇怪的是,如果您遵循测试过程,则最后一步(单击)将立即显示,因为这将打开一个新窗口.这不是10分钟后.似乎在此步骤之后会建立10个延迟.但是我的代码中没有这样的东西.上面的代码后面是:

Strange thing is that if you follow the process of the test the final step (click) shows right away as this opens a new window. This is not 10 minutes later. It seems as after this step a 10 delay is built in. But there is no such thing in my code. The code above is followed by:

Set <String> handles =driver.getWindowHandles();
Iterator<String> it = handles.iterator();
//iterate through your windows
while (it.hasNext()){
String parent = it.next();
String newwin = it.next();
driver.switchTo().window(newwin);

driver.switchTo().defaultContent();
logger.log(LogStatus.INFO, "timestamp1 defaultcontent"); /** logged as successfull at 17:55:47 */
WebElement frame=driver.findElement(By.xpath("/html/body/iframe"));
logger.log(LogStatus.INFO, "timestamp2 find xpath for iframe"); /** logged as successfull at 17:55:47 */
driver.switchTo().frame(frame); 
logger.log(LogStatus.INFO, "timestamp3 switch to iframe"); /** logged as successfull at 17:55:47 */
assertEquals("PageTitle", driver.getTitle());
logger.log(LogStatus.INFO, "timestamp4 confirm switch to iframe succesfull"); /** logged as successfull at 17:55:47 */

新信息:我已经研究了我的代码,看来我对延迟发生的位置不正确.现在看起来好像发生在我更改元素的样式以使其显示并可以单击另一个元素的情况.我现在正在使用以下代码来更改样式,但这可能是问题所在.有没有更简单或更有效的方法来更改元素的样式?

NEW INFORMATION: I've studied my code and it looks like I'm not correct on where the delay occurs. it now looks like it occurs where I change the style of an element so that it shows and another element becomes clickable. I am now using the following code to change the style but this may be the problem. Is there an easier or better way to change the style of an element?

JavascriptExecutor js = (JavascriptExecutor) driver;
WebElement element = driver.findElement(By.xpath("//div[@class='button_ribbon_dropdownsection']"));
js.executeScript("arguments[0].setAttribute('style', 'left: 1520px; top: 40px; display: block;')",element);

原始帖子: 我有一个测试用例,在其中单击打开弹出窗口的链接.在此弹出窗口中是一个iFrame,其中包含我要声明和填充的字段.但是,运行此案例大约需要10分钟,我不知道为什么.这是我的代码:

ORIGINAL POST: I have a testcase where I click on a link that opens a pop-up. In this pop-up is an iFrame that contains fields I want to assert and fill. However, running this case takes about 10 minutes and I don't know why. Here is my code:

//this is the link I click that opens the new window
driver.findElement(By.xpath("//*[@class='value' and text()='text']")).click();

//I have inserted this section to switch to the correct window (the popup). If I don't inlcude this the focus remains on the window where I clicked the link that opens the pop-up.
Set <String> handles =driver.getWindowHandles();
Iterator<String> it = handles.iterator();
//iterate through your windows
while (it.hasNext()){
String parent = it.next();
String newwin = it.next();
driver.switchTo().window(newwin);

//this is where I switch to the iFrame in the new window in order to reach the desired elements
WebElement testframe=driver.findElement(By.xpath("/html/body/iframe"));            
driver.switchTo().frame(testframe); /** this section may take up to 10-15 minutes */
assertEquals("pagetitle here", driver.getTitle());

assertEquals("value", driver.findElement(By.id("id")).getText());
driver.findElement(By.id("id")).clear();
driver.findElement(By.id("id")).sendKeys("number");

此代码确实可以运行,因此代码中没有错误(我可以找到),但是这花了很长时间,我不知道为什么.

This code does run so there is no fault in the code (that I can find) but it just takes VERY long and I can't figure out why.

我知道通过Xpath进入iFrame并不是最好的方法,但这是一种商业产品,iframe没有ID或名称,因此我无法以这种方式导航.

I know going to the iFrame via an Xpath is not the best method but it is a commercial product and there is no id or name for the iframe so I can't navigate to it that way.

我正在将Eclipse与Selenium Webdriver和Java结合使用.

I'm using Eclipse with Selenium webdriver and Java.

推荐答案

感谢基里尔的建议.我将其发布为答案,因为评论字段不足以容纳此回复.

Thanks for the suggestions Kiril. I'm posting this as an answer as a comment field is not big enought for this reply.

我正在尝试实现您的建议,但是我刚才尝试的两件事似乎没有用.我已经使用完整的xpath找到了该项目:

I'm trying to implement what you're suggesting but the two things I've tried just now dont seem to work. I've located the item using the complete xpath:

/html/body/form/div[4]/div[2]/span[6]/div[2]/div[2]/table/tbody/tr[3]/td[2]

如我所想,在此特定表中查找对于我尝试进行的搜索将是足够的限制:

As I figured looking in this particular table would be enough limitation for the search I tried:

driver.findElement(By.xpath("/html/body/form/div[4]/div[2]/span[6]/div[2]/div[2]/table/tbody//*[@class='value' and text()='text']")).click();

但是,这会导致NoSuchElementExcepttion

However, this results in a NoSuchElementExcepttion

然后我尝试根据您的第一个建议更加具体,并尝试:

I then tried to be more specific per your first suggestion and tried:

driver.findElement(By.xpath("//td[@class='value' and text()='text']")).click();

这确实有效,但是对于测试速度却没有任何作用,仍然需要10分钟才能继续.

This did work but did nothing for the speed of the test, it still takes 10 minutes for it to continue.

这篇关于使用iFrame打开新窗口后,测试用例的运行速度非常慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆