Integration testing is the phase in software testing. The purpose of it is to verify functional, performance, and reliability requirements placed on major design items through their interfaces.
This tutorial will show you how to create and run a simple integration test with Selenium IDE.
Install
At first , we need to install essential things: A. Firefox Browser (32 bit)https://www.mozilla.org/download
B. Selenium IDE for Firefox
https://addons.mozilla.org/en-US/firefox/addon/selenium-ide/
Record the test
After installing them, we can now use the Selenium. Let’s create a simple test record to get started. Its screnario is:• Load Google
• Search "Dolphin"
• Go to the first page of search results
• Assert that the heading in that page is "Dolphin"
In the Firefox’s Toolbar > Click on the Selenium icon
The IDE is open. Base URL now is http://www.google.com.vn. You can change it to any address you want the test record start from.
Ok now click the red circle to start recording
In the Search Box, type "Dolphin" then click on the Search button
*NOTE* : Don't press Enter to start searching insteads because the Selenium can not capture that action. A moment later, Google returns the page results:
We gonna go to the first page. So, just click on the link. But for safety, we should make sure that the link is visible at the time we click on. So right click on the first link > waitForElementPresent
We can now click on the link to enter the first page. After that, let’s verify the page heading !
Right click on the Heading > waitForElementPresent
Right click on the Heading again > verifyText
Everything is done ! Click the red circle again to stop recording.
Ok now let’s try to run it ! In the browser, open a new tab, then click on the play button.
On the new tab, the Selenium repeats actions that we have recorded before
Export test case
The most exciting feature of Selenium is that it can export the test case to a variety of formats: C#, Java, Python , Ruby. For example, if we want to export it as C#,On the menu, Choose File > Export Test Case As… > C#/Nunit/WebDriver
Name it DolphinSearch.cs. And the result would be like this:
DolphinSearch.cs
Run exported test case
We have recorded a simple test case and then exported it to the C# format with NUnit functions. Now, let’s try to run it in Visual Studio.Open Visual Studio, choose File > New > Project:
Right click on the project > Add > Existing Item…
Select exported test case
Next, before we can do the test, we must install necessary packages. Right click to project > choose Manage NuGet Packages….
In the search box in the upper right corner, type "selenium". Select and install Selenium WebDriver, Selenium Support Classes
Do the same for NUnit TestAdapter
Ok now let’s run the test. Open DolphinSearch file. Right click on the code area > Runs Test
The test start running…
And after it finished, the result would be like this:
Change to XUnit
If you prefer to test in XUnit, let’s make a little change ! Right click on the Solution > Add > New Project… > OKRight click on the project > choose Manage NuGet Packages… and install these following packages :
xUnit.net and xUnit.net Runner:
Ok now let’s create a new class called TestFixture.cs and copy the code below
TestFixture.cs
namespace SeleniumXUnit { public class TestFixture : IDisposable { public IWebDriver driver; public StringBuilder verificationErrors; public TestFixture() { driver = new FirefoxDriver(); verificationErrors = new StringBuilder(); } public void Dispose() { try { driver.Quit(); } catch (Exception) { // Ignore errors if unable to close the browser } Assert.Equal("", verificationErrors.ToString()); } } }Next, add existing file DolphinSearch.cs again to the project. Because the code in this file are being written in NUnit grammar so we must convert them to XUnit syntax. Here it goes :
namespace SeleniumTests { public class DolphinSearch : IClassFixture<TestFixture> { private IWebDriver driver; private StringBuilder verificationErrors; private string baseURL; private bool acceptNextAlert = true; public DolphinSearch(TestFixture fixture) { driver = fixture.driver; verificationErrors = fixture.verificationErrors; baseURL = "https://www.google.com.vn/"; } [Fact] public void TheDolphinSearchTest() { driver.Navigate().GoToUrl(baseURL + "/?gws_rd=ssl"); driver.FindElement(By.Id("lst-ib")).Clear(); driver.FindElement(By.Id("lst-ib")).SendKeys("dolphin"); driver.FindElement(By.Name("btnG")).Click(); for (int second = 0;; second++) { if (second >= 60) Assert.True(false,"timeout"); try { if (IsElementPresent(By.LinkText("Dolphin - Wikipedia, the free encyclopedia"))) break; } catch (Exception) {} Thread.Sleep(1000); } driver.FindElement(By.LinkText("Dolphin - Wikipedia, the free encyclopedia")).Click(); for (int second = 0;; second++) { if (second >= 60) Assert.True(false,"timeout"); try { if (IsElementPresent(By.Id("firstHeading"))) break; } catch (Exception) {} Thread.Sleep(1000); } try { Assert.Equal("Dolphin", driver.FindElement(By.Id("firstHeading")).Text); } catch (Exception e) { verificationErrors.Append(e.Message); } } private functions (no change) ... } }Ok ! Now right click on the code area and run the test, we got :
That's it. Explore it by yourself !
Harrah's Atlantic City Hotel & Casino - MapyRO
ReplyDeleteThe following 10 hotels are within a 15-minute drive 여수 출장샵 (1 km) of Harrah's Atlantic 안동 출장마사지 City Casino and 1.5 million square 전라남도 출장마사지 feet of casino 의왕 출장샵 gaming 양주 출장안마 space.