Cucumber Java Selenium – Super Brief sum up
I am trying to sum up the whole thing using few Bullet points.
You need to create 3 files in Eclipse.
- Feature file
- CreateAccount.feature
- Login.Feature
Feature: Login
Description: This feature is to test the login functionalityScenario: Successful Login with Valid Credentials
Given User is on Home Page
When User enters Username and Password
And Clicks Go button
Then A message is displayed
- Step Definition File:
@Given("^User is on Home Page$") public void user_is_on_Home_Page() { System.setProperty("webdriver.gecko.driver", "H:\\somePath\\geckodriver.exe"); WebDriver driver = new FirefoxDriver(); URL = "http://www.somesite.com/"; driver.get(URL); } @When("^User enters Username and Password$") public void user_enters_UserName_and_Password() { WebElement loginLink = driver.findElement(By.id("login")); loginLink.click(); WebElement emailField = driver.findElement(By.xpath("//div[@id='email']//input")); emailField.sendKeys("test@test.com"); WebElement passwordField = driver.findElement(By.xpath("//div[@id='password']//input")); passwordField.sendKeys("abcabc"); } @When("^Clicks Go button$") public void clicks_Go_button() { WebElement goButton = driver.findElement(By.id("goButton")); goButton.click(); } @Then("^A message is displayed$") public void a_message_is_displayed() throws Throwable { WebElement practicePage = driver.findElement(By.id("DrpDwn")); practicePage.click(); System.out.println("Login Successful"); } }public class TestingSteps { static WebDriver driver; static String URL;
- JUnit Runner
-
package tests; import org.junit.runner.RunWith; import cucumber.api.CucumberOptions; import cucumber.api.junit.Cucumber; @RunWith(Cucumber.class) @CucumberOptions( features="src/feature", glue={"stepdefinition"} ) public class TestRun { }
4. Right click on the TestRunner file and click on Run as Java Application.
-
Really Microsoft…
Just wanted to rave.
So, I was looking for some information on transaction time. Google brought me to the following screen:
https://msdn.microsoft.com/en-us/library/ms182547.aspx
So, I clicked on the link. Which did NOT take me to “What is a transaction”. It took me here:
https://msdn.microsoft.com/en-us/library/ms182539.aspx#recordingrunningwebtest_qa_transaction
So, again, click on the next icon. After all, third times a charm, correct? WRONG!
https://www.visualstudio.com/docs/test/performance-tests/run-performance-tests-app-before-release
Nice looking URL. But, the information is nowhere to be found.
Regular Expression
This is a good site to test regex to use with QTP:
If our word is:
Ctrl
Regex=Ctrl
Or, ^Ctrl
Or, ^Ctrl$
Or, ^C…$
Or, C…
Or, ^C(?=trl)
Now, if the next word is:
Ctrl11
Regex= C.....
Or, ^C(?=trl)..*
(works in http://tools.netshiftmedia.com/regexlibrary/# site, but does not work with the site mentioned at top).
Or, ^C*
(does not work always)
Now, text: ctl11$sometext
Regex=
^ctl\d\d\$sometext
Or, ^c[a-z]{2}\d\d[a-z]+$
Now, [a-z]{2} is to get the letter ‘t’ and ‘l’. I need to be specific to QTP does not go and recognize anything else.
The other part, [a-z]+$
The + means, the letters must occur one or more time. So, it would fail if the text is “ctl11”
FOR DECIMAL:
Regex=^\d*[0-9](\.\d*[0-9])?$
If the number is 123.123
Regex=
^\d*\.\d*
What to check first if your QTP cannot connect with Quality Center?
Posted by niazzaman in qtp, Quality Center on June 10, 2013
Log in to Quality center server and make sure the SQL server service is running. It happened quite a few times. So, instead of going through the pinging the server, checking Quality center connections, just check the service first.
How to set up hudson and continuous testing – part 1
My plan was simple. It was almost the same plan as Selenium implementation using Maven. This time, the goal was to use QTP instead of Selenium, since most (well, almost all) of my teammates are more familiar with QTP that they are with the other tool.
Anyway, installing Hudson was simple enough.
Download hudson from here:
Then, follow the text from this link:
http://solitarygeek.com/java/hudson-ci-server-a-step-by-step-guide-part-i.
Here the text:
Installing Hudson is super easy. Just download the war file, open your terminal/command-prompt and issue the command “java -jar hudson.war”. Now point your browser to http://localhost:8080. That was easy, right?
Well, turned out, if I save the war file in some random places, i.e. C:/this is one folder/and this is another/hudson.war, the war file gives error when you issue the command.
Easy solution, save your war file in C:/hudson. It will finish installation.
Running Hudson would look like this:
Here is how Hudson looks after loading first:
Now, to run QTP, we can just google to find out the necessary VB code. I used this site:
http://madhuscribblings.wordpress.com/2010/09/23/hello-world/
Dim qtApp 'As QuickTest.Application 'Declare the Application object variable
Dim qtTest 'As QuickTest.Test 'Declare a Test object variable
Set qtApp = CreateObject("QuickTest.Application") 'Create the Application object
qtApp.Launch 'Start QuickTest
qtApp.Visible = False 'Make the QuickTest application visible
qtApp.Options.Run.ImageCaptureForTestResults = "OnError"
qtApp.Options.Run.RunMode = "Normal"
qtApp.Options.Run.ViewResults = True
qtApp.Open "E:\QTP_scripts\Admin_user_search", True 'Open the test in read-only mode
'set run settings for the test
Set qtTest = qtApp.Test
qtTest.Settings.Run.OnError = "NextStep" 'Instruct QuickTest to display dialog box
qtTest.Settings.Run.ObjectSyncTimeOut = 30000 'Instruct QuickTest to wait for 30 seconds for response
Set qtResultsOpt = CreateObject("QuickTest.RunResultsOptions") 'Create the Run Results Options object
qtResultsOpt.ResultsLocation = "E:\hudson\workspace\QTP-Hudson\General_results" 'Set the results location
qtTest.Run qtResultsOpt 'Run the test
' Save the Run-time Data
qtApp.Test.LastRunResults.DataTable.Export "E:\hudson\workspace\QTP-Hudson\Runtime.xls" ' Save the run-time Data Table to a file
WScript.StdOut.Write "Status is:" & qtTest.LastRunResults.Status & vbCr & vbLf ' Check the results of the test run
WScript.StdOut.Write "Error is:" & qtTest.LastRunResults.LastError & vbCr & vbLf ' Check the most recent error
WScript.StdOut.Write "Result path is:" & qtTest.LastRunResults.path & vbCr & vbLf
sRespath = qtTest.LastRunResults.path
sResultsXML = "" & sRespath & "\Report\Results.xml"
sDetailedXSL = "C:\Program Files\HP\QuickTest Professional\dat\PDetails.xsl"
sShortXSL = "C:\Program Files\HP\QuickTest Professional\dat\PShort.xsl"
ApplyXSL sResultsXML, sDetailedXSL, "E:\hudson\workspace\QTP-Hudson\Results_Detailed.html"
ApplyXSL sResultsXML, sShortXSL, "E:\hudson\workspace\QTP-Hudson\Results_Short.html"
Public Function ApplyXSL(ByVal inputXML, ByVal inputXSL, ByVal outputFile)
sXMLLib = "MSXML.DOMDocument"
Set xmlDoc = CreateObject(sXMLLib)
Set xslDoc = CreateObject(sXMLLib)
xmlDoc.async = False
xslDoc.async = False
xslDoc.load inputXSL
xmlDoc.load inputXML
outputText = xmlDoc.transformNode(xslDoc.documentElement)
Set FSO = CreateObject("Scripting.FileSystemObject")
Set outFile = FSO.CreateTextFile(outputFile,True)
outFile.Write outputText
outFile.Close
Set outFile = Nothing
Set FSO = Nothing
Set xmlDoc = Nothing
Set xslDoc = Nothing
Set xmlResults = Nothing
End Function
qtTest.Close ' Close the test
qtApp.Quit ' Exit QuickTest
Set qtResultsOpt = Nothing ' Release the Run Results Options object
Set qtTest = Nothing ' Release the Test object
Set qtApp = Nothing ' Release the Application object
To be continued …
How to store and call QTP random function.
This is from google. I cannot find the original link at this time. however, the main purpose is how to call the function, not about the function itself.
————————-
So, here is the function which is saved in Resources of Quality Center as nzrandom.qfl.
'===============================================
'Function to Create a Random Number of Any Length
'===============================================
Function nzrandom(LengthOfRandomNumber)
Dim sMaxVal : sMaxVal = ""
Dim iLength : iLength = LengthOfRandomNumber
'Find the maximum value for the given number of digits
For iL = 1 to iLength
sMaxVal = sMaxVal & "9"
Next
sMaxVal = Int(sMaxVal)
'Find Random Value
Randomize
iTmp = Int((sMaxVal * Rnd) + 1)
'Add Trailing Zeros if required
iLen = Len(iTmp)
nzrandom = iTmp * (10 ^(iLength - iLen))
End Function
'================== End Function =================
So now, if we want to call this function from another script, we need to write it the following way:
LoadFunctionLibrary ("[QualityCenter\Resources] Resources\nzrandom.qfl")
msgbox nzrandom (3)
How to use Selenium 2 webdriver with new IE Driver
Even though the following information is present in the web, I had to wed through multiple sites in order to get them in one place. Also, it’s not helpful to see that the current version of IE driver would be deprecated until you finish coding and ran your test. So, here it is:
import static org.junit.Assert.*;
import java.io.File;//We need to put the IE Driver path
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
//import org.openqa.selenium.chrome.ChromeDriver;
//import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class myfirstTest {
@Test
public void startWebDriver(){
//WebDriver driver = new FirefoxDriver();
File file = new File("C:/My Box Files/IEDriverServer_Win32_2.30.2/IEDriverServer.exe");
System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
WebDriver driver1 = new InternetExplorerDriver();
//WebDriver driver2 = new ChromeDriver();
driver1.navigate().to("http://url.com/");
driver1.findElement(By.id("UserName")).clear();
driver1.findElement(By.id("UserName")).sendKeys("test@test.com");
driver1.findElement(By.id("Password")).clear();
driver1.findElement(By.id("Password")).sendKeys("testpass");
driver1.findElement(By.id("LogOn")).click();
//assertEquals("Title", driver1.getTitle());
driver1.findElement(By.linkText("Search")).click();
}
}
If you are running Selenium from Eclipse using Maven
Never ever forgot to have the word “Test” in the name of the class file.
source:
http://stackoverflow.com/questions/6178583/maven-does-not-find-junit-tests-to-run
QTP database connectivity and integer comparison
Here’s a quick summary of what happened in last few weeks. Looks like this days I am spending more and more time with QTP and LoadRunner. Looks like, it would be a while before I can write back on the SOA testing. So, here goes.
The scenario was simple. There is a dynamic value in screen which needs to be compared with database. Simple, right. Well, for some reason, things didn’t go exactly as planned.
First, capture the value from database and then capture the value from UI. That didn’t go as planned, because, the value in database only gets generated when user perform some specific tasks in UI. So, first capture the value from UI and then capture the value from DB.
So, here is a pretty straight forward to capture an output from UI.
1.
Browser(“Browser”).Page(“Somesite”).WebEdit(“ssousername”).Set “something”
Browser(“Browser”).Page(“Somesite”).WebEdit(“password”).Set “seomthing”
Browser(“Browser”).Page(“Somesite”).WebButton(“Login”).Click
Browser(“Browser_2”).Window(“somewindow”).Page(“Save Comments”).Output CheckPoint(“adj_out_text “)
Here, comes the first problem. The screen itself is dynamic, and no way we could capture the specific value using text output by defining the text before and text after. It’s all or none. So, instead of capturing ‘1’, we are capturing ‘Value 1 is created’.
Well, nothing that can’t be solved with a bit of string manipulation. So, we did the following like in excel, by using MID.
2. c2=datatable.Value(“adj_out_text”,1)
C1=mid(c2,12,3)
Now, after we get our value, we need the get the value from database and compare.
3.
Dim strConn
strConn = “Driver= {Microsoft ODBC for Oracle}; ” &_
“ConnectString=(DESCRIPTION=” &_
“(ADDRESS=(PROTOCOL=TCP)” &_
“(HOST=something) (PORT=1521))” &_
“(CONNECT_DATA=(SERVICE_NAME=something)));uid=something; pwd=something;”
Dim obConnect
Dim obRecset
Set obConnect =CreateObject(“ADODB.Connection”)
Set obRecset = CreateObject(“ADODB.Recordset”)
sql=”select * from something”
obRecset.Open sql,strConn
datatable.GetSheet(1).AddParameter “DB_Adj_no”, “”
c7=datatable.Value(“DB_Adj_no”)
i=1
Do while Not obRecset.EOF
DataTable.GlobalSheet.SetCurrentRow(i)
datatable.Value(“DB_Adj_no”)=obRecset.Fields.Item(0)
i=i+1
obRecset.MoveNext
Loop
We get the value from dB and stored it in runtime. Though it’s not necessary, just to see in the results table. Now. Go ahead with Micpass.
4.
If c7=c1 Then
Reporter.ReportEvent micPass,”Values matched”,”Calculated Correctly ” & c1 & ” = ” & c7
Else
Reporter.ReportEvent micFail,”Values Did not match”,”Did not calculate correctly ” & c1 & ” != ” & c7
End If
Not a good result. Out report is showing Micfail, with 1 !=1. That’s weird.
After some head scratching, we thought we found out the reason. The string manipulation is giving us a string in return. We should convert that to a number and that should give us MicPass.
5.
c2=datatable.Value(“adj_out_text”,1)
c3=mid(c2,12,3)
c1=CInt(c4)
We already checked that the value in DB is number. But, still we are getting Fail. So, we go ahead and converted the DB output into number (integer, to be precise; same as the previous one).
6.
datatable.Value(“DB_Adj_no”)=obRecset.Fields.Item(0)
c5=datatable.Value(“DB_Adj_no”)
c6=trim(c5)
c7=CInt(c6)
Voila, now it’s all working good. At last, we are getting 1=1.
How to enable Alt + Tab in citrix remote desktop
It’s been a year since the last post. Time does fly, now I see. Here is quick tidbit that I am using now a days.
http://support.citrix.com/article/CTX118974
HKEY_LOCAL_MACHINE \SOFTWARE\Citrix\ICAClient\Engine\Lockdown Profiles\All Regions\Lockdown\Virtual Channels\Keyboard\
Value Name: TransparentKeyPassthrough
Type: REG_SZ
Value: FullScreenOnly, Remote, or Local
Remote applies the Windows hotkeys to the window in focus.
Local never applies the Windows hotkeys to the session.
I am using ‘Remote”. Life seems easy.
Edit: 04/14/2011 – Looks like the settings are different for windows 7 64 bit. I will post on that soon.