我已经为firefox安装了selenium IDE扩展,并记录并创建了一个包含5个测试用例的测试套件,以测试我的应用程序的5种不同功能。现在我该如何将这些测试/测试套件集成到我的azure devops管道中?为此,我应该添加到管道的任务类型吗?这个想法是在将新代码提交到azure存储库时自动运行此测试。保存的测试套件使用.side格式。我还能够将测试套件导出为不同的语言,例如Java + JUnit,JavaScript + Mocha等。现在,如果我要将这些测试集成到我的azure管道中,该如何进行?plz帮助?
导出到javascript moacha后生成的测试代码
// Generated by Selenium IDE
const { Builder, By, Key, until } = require('selenium-webdriver')
const assert = require('assert')
describe('Default Suite', function() {
this.timeout(30000)
let driver
let vars
beforeEach(async function() {
driver = await new Builder().forBrowser('firefox').build()
vars = {}
})
afterEach(async function() {
await driver.quit();
})
it('create new folder', async function() {
await driver.get("http://localhost:3000/")
await driver.manage().window().setRect(1382, 744)
await driver.findElement(By.css(".butt > span")).click()
await driver.findElement(By.css("input:nth-child(2)")).click()
await driver.findElement(By.css("input:nth-child(2)")).sendKeys("haleem")
await driver.findElement(By.css("input:nth-child(2)")).sendKeys(Key.ENTER)
})
it('view creation', async function() {
await driver.get("http://localhost:3000/")
await driver.manage().window().setRect(1382, 744)
await driver.findElement(By.css("#f1df1abf-ce3d-4fb9-b624-8768957d21b0 img")).click()
await driver.findElement(By.css("h6")).click()
{
const dragged = await driver.findElement(By.css(".dragObject:nth-child(8)"))
const dropped = await driver.findElement(By.css(".col-lg-12:nth-child(2) > p:nth-child(1)"))
await driver.actions({ bridge: true }).dragAndDrop(dragged, dropped).perform()
}
{
const dragged = await driver.findElement(By.css(".dragObject:nth-child(9)"))
const dropped = await driver.findElement(By.css(".dropObject"))
await driver.actions({ bridge: true }).dragAndDrop(dragged, dropped).perform()
}
await driver.findElement(By.css(".btn:nth-child(3)")).click()
await driver.findElement(By.css(".saveFormInput")).click()
await driver.findElement(By.css(".saveFormInput")).sendKeys("view sample updated")
await driver.findElement(By.css(".saveFormButton:nth-child(2)")).click()
await driver.findElement(By.css("#f1df1abf-ce3d-4fb9-b624-8768957d21b0 img")).click()
await driver.findElement(By.css("#f1df1abf-ce3d-4fb9-b624-8768957d21b0 > li img")).click()
})
it('search filter', async function() {
await driver.get("http://localhost:3000/")
await driver.manage().window().setRect(550, 692)
await driver.findElement(By.name("q")).click()
await driver.findElement(By.name("q")).sendKeys("vig")
})
it('download functionality', async function() {
await driver.get("http://localhost:3000/")
await driver.manage().window().setRect(1382, 744)
await driver.findElement(By.css("#f1df1abf-ce3d-4fb9-b624-8768957d21b0 img")).click()
await driver.findElement(By.css("#f3b0fb9b-aa2f-4c14-aa79-f85af92f0fa3 img")).click()
await driver.findElement(By.css(".btn:nth-child(2)")).click()
await driver.findElement(By.css(".dropObject")).click()
})
})
导出到Java Junit后生成的测试代码
// Generated by Selenium IDE
import org.junit.Test;
import org.junit.Before;
import org.junit.After;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.core.IsNot.not;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Alert;
import org.openqa.selenium.Keys;
import java.util.*;
import java.net.MalformedURLException;
import java.net.URL;
public class DefaultSuiteTest {
private WebDriver driver;
private Map<String, Object> vars;
JavascriptExecutor js;
@Before
public void setUp() {
driver = new FirefoxDriver();
js = (JavascriptExecutor) driver;
vars = new HashMap<String, Object>();
}
@After
public void tearDown() {
driver.quit();
}
@Test
public void createnewfolder() {
driver.get("http://localhost:3000/");
driver.manage().window().setSize(new Dimension(1382, 744));
driver.findElement(By.cssSelector(".butt > span")).click();
driver.findElement(By.cssSelector("input:nth-child(2)")).click();
driver.findElement(By.cssSelector("input:nth-child(2)")).sendKeys("haleem");
driver.findElement(By.cssSelector("input:nth-child(2)")).sendKeys(Keys.ENTER);
}
@Test
public void viewcreation() {
driver.get("http://localhost:3000/");
driver.manage().window().setSize(new Dimension(1382, 744));
driver.findElement(By.cssSelector("#f1df1abf-ce3d-4fb9-b624-8768957d21b0 img")).click();
driver.findElement(By.cssSelector("h6")).click();
{
WebElement dragged = driver.findElement(By.cssSelector(".dragObject:nth-child(8)"));
WebElement dropped = driver.findElement(By.cssSelector(".col-lg-12:nth-child(2) > p:nth-child(1)"));
Actions builder = new Actions(driver);
builder.dragAndDrop(dragged, dropped).perform();
}
{
WebElement dragged = driver.findElement(By.cssSelector(".dragObject:nth-child(9)"));
WebElement dropped = driver.findElement(By.cssSelector(".dropObject"));
Actions builder = new Actions(driver);
builder.dragAndDrop(dragged, dropped).perform();
}
driver.findElement(By.cssSelector(".btn:nth-child(3)")).click();
driver.findElement(By.cssSelector(".saveFormInput")).click();
driver.findElement(By.cssSelector(".saveFormInput")).sendKeys("view sample updated");
driver.findElement(By.cssSelector(".saveFormButton:nth-child(2)")).click();
driver.findElement(By.cssSelector("#f1df1abf-ce3d-4fb9-b624-8768957d21b0 img")).click();
driver.findElement(By.cssSelector("#f1df1abf-ce3d-4fb9-b624-8768957d21b0 > li img")).click();
}
@Test
public void searchfilter() {
driver.get("http://localhost:3000/");
driver.manage().window().setSize(new Dimension(550, 692));
driver.findElement(By.name("q")).click();
driver.findElement(By.name("q")).sendKeys("vig");
}
@Test
public void downloadfunctionality() {
driver.get("http://localhost:3000/");
driver.manage().window().setSize(new Dimension(1382, 744));
driver.findElement(By.cssSelector("#f1df1abf-ce3d-4fb9-b624-8768957d21b0 img")).click();
driver.findElement(By.cssSelector("#f3b0fb9b-aa2f-4c14-aa79-f85af92f0fa3 img")).click();
driver.findElement(By.cssSelector(".btn:nth-child(2)")).click();
driver.findElement(By.cssSelector(".dropObject")).click();
}
}
答案 0 :(得分:0)
如何将Selenium IDE测试用例集成到天蓝色的devops管道中?
有一个任务Visual Studio Test task,它支持:
单元和功能测试(Selenium,Appium,编码的UI测试等) 使用Visual Studio测试运行程序。除了基于MSTest的测试之外, 具有Visual Studio测试适配器的测试框架,例如xUnit, NUnit Chutzpah 也可以执行。
因此,我们可以使用此任务来执行javascript moacha的测试用例。
但是,导出的文件是单个文件而不是库,因此我们需要创建小型库项目应用程序。我们将使用该项目来编译从Selenium IDE导出的测试文件。创建项目后,我们只需要将导出的.cs文件复制到我们的项目中并编译dll。
如果要将Selenium测试与Azure devop集成在一起,则需要将此库项目推送到存储库,然后使用Visual Studio Test任务进行构建。
希望这会有所帮助。