Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用iFrame打开新窗口后,测试用例运行非常慢_Java_Eclipse_Performance_Selenium_Iframe - Fatal编程技术网

Java 使用iFrame打开新窗口后,测试用例运行非常慢

Java 使用iFrame打开新窗口后,测试用例运行非常慢,java,eclipse,performance,selenium,iframe,Java,Eclipse,Performance,Selenium,Iframe,还有更多新信息:我现在官方不明白为什么这个测试很慢。如下文所述,我已经消除了对javascript的需求,并且添加了报告来确定延迟的位置。这些是以“logger”开头的行。我在这些行后面添加了时间戳,以便您可以看到延迟的位置。这段代码看起来很混乱/需要很长时间(每次10分钟): 奇怪的是,如果您按照测试过程进行操作,那么当打开一个新窗口时,最后一步(单击)会立即显示出来。这不是10分钟后。这一步之后,似乎内置了10个延迟。但是在我的代码中没有这样的东西。上述代码后面是: Set <Stri

还有更多新信息:我现在官方不明白为什么这个测试很慢。如下文所述,我已经消除了对javascript的需求,并且添加了报告来确定延迟的位置。这些是以“logger”开头的行。我在这些行后面添加了时间戳,以便您可以看到延迟的位置。这段代码看起来很混乱/需要很长时间(每次10分钟):

奇怪的是,如果您按照测试过程进行操作,那么当打开一个新窗口时,最后一步(单击)会立即显示出来。这不是10分钟后。这一步之后,似乎内置了10个延迟。但是在我的代码中没有这样的东西。上述代码后面是:

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 */
原创帖子: 我有一个测试用例,我点击一个链接打开一个弹出窗口。在这个弹出窗口中是一个iFrame,其中包含我想要断言和填充的字段。然而,运行这个案例大约需要10分钟,我不知道为什么。这是我的密码:

//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");
//这是我单击的打开新窗口的链接
findElement(By.xpath(“//*[@class='value'和text()='text']))。单击();
//我插入此部分是为了切换到正确的窗口(弹出窗口)。如果我不包含此内容,则焦点将保留在我单击打开弹出窗口的链接的窗口上。
Set handles=driver.getWindowHandles();
迭代器it=handles.Iterator();
//遍历你的窗口
while(it.hasNext()){
字符串parent=it.next();
字符串newwin=it.next();
driver.switchTo()窗口(newwin);
//在这里,我切换到新窗口中的iFrame,以达到所需的元素
WebElement testframe=driver.findelelement(By.xpath(“/html/body/iframe”);
driver.switchTo().frame(testframe);/**此部分可能需要10-15分钟*/
assertEquals(“此处为pagetitle”,driver.getTitle());
assertEquals(“value”,driver.findElement(By.id(“id”)).getText());
driver.findElement(By.id(“id”)).clear();
driver.findElement(By.id(“id”)).sendKeys(“编号”);
这段代码确实可以运行,所以代码中没有错误(我可以找到),但它只需要很长时间,我不知道为什么

我知道通过Xpath访问iFrame不是最好的方法,但它是一种商业产品,没有iFrame的id或名称,因此我无法以这种方式导航到它


我正在将Eclipse与Selenium webdriver和Java一起使用。

很抱歉,没有答案,而是建议(我会将此作为评论发布,但stackoverflow不允许我):

通常,当某件事情进展缓慢时,我会检查三件事:

  • Selenium版本:他们确实周期性地有一些缓慢的bug,也许你们只是幸运地拥有了有这个问题的版本
  • Selenium版本与浏览器类型和版本。可能对浏览器版本的支持在您使用的Selenium版本上不是最佳的
  • 如果可能的话,尝试使用精简/禁用的javascript运行浏览器。可能是某些javascript在selenium中无法正常运行

如果不是上面提到的,我也会对你怀疑的每一条语句计时,看看哪条语句实际上慢,或者它们是否都同样慢(例如,有一个很长的bug,selenium的sendKeys在IE上有时慢)。并在此基础上启用调试日志,如前所述。这将有望为您提供更多关于正在发生的事情的信息。

对不起,没有答案,而是建议(我将此作为评论发布,但stackoverflow不允许我):

通常,当某件事情进展缓慢时,我会检查三件事:

  • Selenium版本:他们确实周期性地有一些缓慢的bug,也许你们只是幸运地拥有了有这个问题的版本
  • Selenium版本与浏览器类型和版本。可能对浏览器版本的支持在您使用的Selenium版本上不是最佳的
  • 如果可能的话,尝试使用精简/禁用的javascript运行浏览器。可能是某些javascript在selenium中无法正常运行

如果不是上面提到的,我也会对你怀疑的每一条语句计时,看看哪条语句实际上慢,或者它们是否都同样慢(例如,有一个很长的bug,selenium的sendKeys在IE上有时慢)。并在此基础上启用调试日志,如前所述。这将有望为您提供更多有关正在发生的事情的信息。

想到的一件事是您的第二个xpath:

//*[@class='CLASS' and text()='TEXT']
“/*”部分可能非常慢。能否尝试指定元素名称或路径,例如

//div[@class='CLASS' and text()='TEXT']


要限制搜索?

我想到的是第二个xpath:

//*[@class='CLASS' and text()='TEXT']
“/*”部分可能非常慢。能否尝试指定元素名称或路径,例如

//div[@class='CLASS' and text()='TEXT']


要限制搜索?

页面上有多少帧?您可以使用
driver.switchTo().frame(0)在帧中使用索引;
。不过,我认为这不会解决您的性能问题。这只是一个框架,我尝试了您的代码,但没有起作用/提高性能。谢谢。页面上有多少个框架?您可以使用
driver.switchTo().frame(0)在框架中使用索引;
。不过,我认为这不会解决您的性能问题。这只是一个框架,我尝试了您的代码,但没有起作用/提高了性能。谢谢。
/select/sub/tree/to/search//*[@class='CLASS' and text()='TEXT']