Python 使用Robot框架降低测试运行速度的好方法?
所以我对Robot框架还比较陌生,并且已经多次遇到了这个问题的各种形式。基本上,我创建了一套测试,这些测试最终通过并检查我期望的东西,然后通过CI/CD管道,在专用的测试运行程序上,我遇到了一些失败。本质上,这似乎是因为测试运行者做事情的速度稍微快一点,无论是硬件还是速度,这都不重要 为了避免这些失败,我最终在测试中添加了一些东西,以在某些点上“减慢”它们以确保成功,基本上是让它们膨胀,或者只是更具保护性。那么对于那些更有经验的人,你如何处理这种情况呢?我希望尽可能坚持最佳实践,也就是说,我不只是到处使用睡眠,而是使用隐式等待,但我仍然不知道最好的方法是什么 以下是我最近遇到的一个问题的片段:Python 使用Robot框架降低测试运行速度的好方法?,python,selenium,robotframework,Python,Selenium,Robotframework,所以我对Robot框架还比较陌生,并且已经多次遇到了这个问题的各种形式。基本上,我创建了一套测试,这些测试最终通过并检查我期望的东西,然后通过CI/CD管道,在专用的测试运行程序上,我遇到了一些失败。本质上,这似乎是因为测试运行者做事情的速度稍微快一点,无论是硬件还是速度,这都不重要 为了避免这些失败,我最终在测试中添加了一些东西,以在某些点上“减慢”它们以确保成功,基本上是让它们膨胀,或者只是更具保护性。那么对于那些更有经验的人,你如何处理这种情况呢?我希望尽可能坚持最佳实践,也就是说,我不只
Wait Until Page Contains Element ${STATIC_TABLE_XPATH}/somepath 10
${image_text} = Selenium2Library.Get Element Attribute ${STATIC_TABLE_XPATH}/somepath
${second_paragraph_text} = Selenium2Library.Get Text ${STATIC_TABLE_XPATH}/somepath
因此,基本上,尽管这些功能是正确的,但在测试跑步者身上运行时,它们有时不会后退。我想这是因为事情发生得太快了,所以我添加了一个等待页面包含元素,不幸的是,同样的问题仍然存在。有没有一种最好的方法来处理这种情况,使它始终通过
我认为在期望的变量值上添加一个wait-until关键字会非常糟糕,但很高兴被证明是错误的 尽量避免睡觉 隐式等待也不是可扩展的解决方案。例如,如果您正在检查元素的“不存在”,它们可能会让您耽误很多时间 我建议你好好利用WebDriverWaits 我经常需要等待某些元素或页面的显示,因此我编写了一些类似以下的方法:
public void waitUntilDisplayed(By elementLocator, int timeoutInSeconds) {
WebDriverWait wait = (WebDriverWait)new WebDriverWait(driver, timeoutInSeconds).ignoring(StaleElementReferenceException.class);
wait.until(new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver driver) {
return elementIsDisplayed(elementLocator);
}
});
}
public boolean elementIsDisplayed(By elementLocator) {
if(elementExists(elementLocator)) {
WebElement element = driver.findElement(elementLocator);
return element.isDisplayed();
}
return false;
}
public boolean elementExists(By elementLocator) {
List<WebElement> elements = driver.findElements(elementLocator);
if (elements.size() < 1) {
return false;
}
return true;
}
public void waitUntilDisplayed(按elementLocator,int timeoutingseconds){
WebDriverWait wait=(WebDriverWait)新建WebDriverWait(驱动程序,timeoutInSeconds)。忽略(StaleElementReferenceException.class);
等待.直到(新的ExpectedCondition(){
公共布尔应用(WebDriver驱动程序){
显示返回元素(元素定位器);
}
});
}
显示公共布尔元素(按元素定位器){
if(elementExists(elementLocator)){
WebElement=driver.findElement(elementLocator);
返回元素.isDisplayed();
}
返回false;
}
公共布尔元素exists(按elementLocator){
列表元素=driver.findElements(elementLocator);
if(elements.size()<1){
返回false;
}
返回true;
}
尽可能避免睡眠
隐式等待也不是可扩展的解决方案。例如,如果您正在检查元素的“不存在”,它们可能会让您耽误很多时间
我建议你好好利用WebDriverWaits
我经常需要等待某些元素或页面的显示,因此我编写了一些类似以下的方法:
public void waitUntilDisplayed(By elementLocator, int timeoutInSeconds) {
WebDriverWait wait = (WebDriverWait)new WebDriverWait(driver, timeoutInSeconds).ignoring(StaleElementReferenceException.class);
wait.until(new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver driver) {
return elementIsDisplayed(elementLocator);
}
});
}
public boolean elementIsDisplayed(By elementLocator) {
if(elementExists(elementLocator)) {
WebElement element = driver.findElement(elementLocator);
return element.isDisplayed();
}
return false;
}
public boolean elementExists(By elementLocator) {
List<WebElement> elements = driver.findElements(elementLocator);
if (elements.size() < 1) {
return false;
}
return true;
}
public void waitUntilDisplayed(按elementLocator,int timeoutingseconds){
WebDriverWait wait=(WebDriverWait)新建WebDriverWait(驱动程序,timeoutInSeconds)。忽略(StaleElementReferenceException.class);
等待.直到(新的ExpectedCondition(){
公共布尔应用(WebDriver驱动程序){
显示返回元素(元素定位器);
}
});
}
显示公共布尔元素(按元素定位器){
if(elementExists(elementLocator)){
WebElement=driver.findElement(elementLocator);
返回元素.isDisplayed();
}
返回false;
}
公共布尔元素exists(按elementLocator){
列表元素=driver.findElements(elementLocator);
if(elements.size()<1){
返回false;
}
返回true;
}
尽可能避免睡眠
隐式等待也不是可扩展的解决方案。例如,如果您正在检查元素的“不存在”,它们可能会让您耽误很多时间
我建议你好好利用WebDriverWaits
我经常需要等待某些元素或页面的显示,因此我编写了一些类似以下的方法:
public void waitUntilDisplayed(By elementLocator, int timeoutInSeconds) {
WebDriverWait wait = (WebDriverWait)new WebDriverWait(driver, timeoutInSeconds).ignoring(StaleElementReferenceException.class);
wait.until(new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver driver) {
return elementIsDisplayed(elementLocator);
}
});
}
public boolean elementIsDisplayed(By elementLocator) {
if(elementExists(elementLocator)) {
WebElement element = driver.findElement(elementLocator);
return element.isDisplayed();
}
return false;
}
public boolean elementExists(By elementLocator) {
List<WebElement> elements = driver.findElements(elementLocator);
if (elements.size() < 1) {
return false;
}
return true;
}
public void waitUntilDisplayed(按elementLocator,int timeoutingseconds){
WebDriverWait wait=(WebDriverWait)新建WebDriverWait(驱动程序,timeoutInSeconds)。忽略(StaleElementReferenceException.class);
等待.直到(新的ExpectedCondition(){
公共布尔应用(WebDriver驱动程序){
显示返回元素(元素定位器);
}
});
}
显示公共布尔元素(按元素定位器){
if(elementExists(elementLocator)){
WebElement=driver.findElement(elementLocator);
返回元素.isDisplayed();
}
返回false;
}
公共布尔元素exists(按elementLocator){
列表元素=driver.findElements(elementLocator);
if(elements.size()<1){
返回false;
}
返回true;
}
尽可能避免睡眠
隐式等待也不是可扩展的解决方案。例如,如果您正在检查元素的“不存在”,它们可能会让您耽误很多时间
我建议你好好利用WebDriverWaits
我经常需要等待某些元素或页面的显示,因此我编写了一些类似以下的方法:
public void waitUntilDisplayed(By elementLocator, int timeoutInSeconds) {
WebDriverWait wait = (WebDriverWait)new WebDriverWait(driver, timeoutInSeconds).ignoring(StaleElementReferenceException.class);
wait.until(new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver driver) {
return elementIsDisplayed(elementLocator);
}
});
}
public boolean elementIsDisplayed(By elementLocator) {
if(elementExists(elementLocator)) {
WebElement element = driver.findElement(elementLocator);
return element.isDisplayed();
}
return false;
}
public boolean elementExists(By elementLocator) {
List<WebElement> elements = driver.findElements(elementLocator);
if (elements.size() < 1) {
return false;
}
return true;
}
public void waitUntilDisplayed(按elementLocator,int timeoutingseconds){
WebDriverWait wait=(WebDriverWait)新建WebDriverWait(驱动程序,timeoutInSeconds)。忽略(StaleElementReferenceException.class);
等待.直到(新的ExpectedCondition(){
公共布尔应用(WebDriver驱动程序){
显示返回元素(元素定位器);
}
});
}
显示公共布尔元素(按元素定位器){
if(elementExists(elementLocator)){
WebElement=driver.findElement(elementLocator);
返回元素.isDisplayed();
}
返回false;
}
公共布尔元素exists(按elementLocator){
List elements=driver.findElements(elementL