Wednesday, September 5, 2018

How to work with Windows image upload or file browser window on selenium with Jave

There are are several methods to handle this kinds of situation but not all are working ,Because most of them are to use with HTML file browser windows ,
This solution is specially for Windows file browser window AKA Windows file browser dialog box.

User first need to click on the file browser button,The there will be a Windows file browser dialog box where you can browse for a file.

In a nut shell what we are doing is just Copy and Past the file path at the Windows file browser dialog box

try {
    StringSelection s = new StringSelection("C:\\Users\\XXX\\Pictures\\w.png");
    Toolkit.getDefaultToolkit().getSystemClipboard().setContents(s, null);
    Robot robot = new Robot();

    robot.keyPress(java.awt.event.KeyEvent.VK_CONTROL); //Press CTRL KEY
    robot.keyPress(java.awt.event.KeyEvent.VK_V);//Press V KEY
    robot.keyRelease(java.awt.event.KeyEvent.VK_CONTROL); //RELEASE CTRL KEY
    Thread.sleep(3000);
    robot.keyPress(java.awt.event.KeyEvent.VK_ENTER);
} catch (AWTException e) {
    e.printStackTrace();
} catch (InterruptedException e) {
    e.printStackTrace();
}

try {
    Thread.sleep(60000);
} catch (InterruptedException e) {
    e.printStackTrace();
}

Monday, September 3, 2018

java: cannot access java.util.function.Function class file for java.util.function.Function not found - Selenium on JAVA with InteliJ

I have below two lines on my selenium code.

WebDriverWait wait = new WebDriverWait(driver, 100);
wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(DashObj.HeaderText));

When i execute the test method as on the tittle im getting an error saying 
"java.util.function.Function class file for 
java.util.function.Function not found"

Fix:
Go to File ->Project Structure

There will be an window with some configurations.
Go to Modules and locate the Language level at Sources tab,


By default it was set to 7 , So click on the drop down and set it to 8.


Tuesday, July 24, 2018

Configuring Jenkins with MSSQL server.


  • Need to install SQL server.
  • Install Java.
  • SQL server is with SQL authentication method.

Below is the sonar config looks like ,But im getting an error.


sonar.jdbc.url=jdbc:sqlserver://localhost;databaseName=SonarQube;instanceName=SQLEXPRESS
sonar.jdbc.username=sonarqube
sonar.jdbc.password=mypassword

java.lang.IllegalStateException: Can not connect to database. Please check connectivity and settings (see the properties prefixed by 'sonar.jdbc.').


Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of class 'com.microsoft.sqlserver.jdbc.SQLServerDriver' for connect URL 'jdbc:sqlserver:localhostSQLEXPRESS;databaseName=SonarQube;instanceName=SQLEXPRESS;selectMethod=cursor;'

Full post:
http://blog.majcica.com/2016/04/28/sonarqube-on-windows-and-ms-sql/

Wednesday, July 11, 2018

Show MSTest coverage on a .net project - Sonar

C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Team Tools\Dynami
c Code Coverage Tools>CodeCoverage.exe 
collect /output:VisualStudio.coverage "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe" "C:\Program Files (x86)\Jenkins\workspace\dash_\dash\ReportShare\bin\ReportShare.dll"



  1. You have to find the CodeCoverage.exe installation location.

In my PC its inside "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Team Tools\Dynami
c Code Coverage Tools>"

  2.Execute your MSTest dll file by pointing it to CodeCoverage.exe

     3. Then VisualStudio.coverage file will be generate on your CodeCoverage.exe's file location.



C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Team Tools\Dynami
c Code Coverage Tools>CodeCoverage.exe analyze /output:VisualStudio.coveragexml VisualStudio.coverage

  
  4.By pointing to the same CodeCoverage.exe generate the coveragexml file.

     5. Then VisualStudio.coveragexml file will be generate on your CodeCoverage.exe's file           location.




sonar.cs.vscoveragexml.reportsPaths=C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Team Tools/Dynamic Code Coverage Tools/VisualStudio.coveragexml

   6.Then add sonar.cs.vscoveragexml.reportsPaths parameter to your sonar analysis properties and point the newly generated  VisualStudio.coveragexml  file to that property.




DONE!

Tuesday, April 3, 2018

Easy way to switch between windows on appium or selenium

ReadOnlyCollection<string> windowHandles = driver.WindowHandles;
            driver.SwitchTo().Window(windowHandles[1]);

Thursday, March 22, 2018

Sonar EXECUTION FAILURE- "Start pointer should be before end pointer."

10:58:34.592 INFO: EXECUTION FAILURE
10:58:34.592 INFO: ------------------------------------------------------------------------
10:58:34.592 INFO: Total time: 1:00.563s
10:58:34.650 INFO: Final Memory: 41M/105M
10:58:34.650 INFO: ------------------------------------------------------------------------
10:58:34.651 ERROR: Error during SonarQube Scanner execution
java.lang.IllegalArgumentException: Start pointer [line=10, lineOffset=0] should be before end pointer [line=10, lineOffset=0]
 at org.sonar.api.internal.google.common.base.Preconditions.checkArgument(Preconditions.java:145)
 at org.sonar.api.batch.fs.internal.DefaultInputFile.newRangeValidPointers(DefaultInputFile.java:265)
 at org.sonar.api.batch.fs.internal.DefaultInputFile.newRange(DefaultInputFile.java:203)
 at org.sonarsource.dotnet.shared.plugins.SensorContextUtils.toTextRange(SensorContextUtils.java:41)
 at org.sonarsource.dotnet.shared.plugins.protobuf.IssuesImporter.importMessage(IssuesImporter.java:54)

Above is the sample output of my sonar execution failure output.
Above out put is for a C# project.
I was looking for a fix to resolve this issue.
Some have mention to disable some of the c# rules on the sonar profile.
But it didnt work for me.

So i update the sonar c# plugin from the sonar update center.
But still NO LUCK.

Then I manually download an older version of sonar-csharp-plugin and try to execute the sonar scanner.
But still NO LUCK.

Then i tried with more older versions and finally sonar-csharp-plugin-5.1-RC3.jar and it works well.

URL for older versions of sonar c sharp plugin
https://github.com/SonarSource/sonar-csharp/releases?after=5.2

Wednesday, November 22, 2017

Error while reading an excel file as a sql table-'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine

Im having a xlsx  file which contain some data as on the below image and i need to read them and store as a SQL data table or as an string array.

So any how my ultimate goal is to read the data from a excel file.

But i got this stupid error.

'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine'



string path = @"C:\temp\GOSTestDetails.xlsx";
            string connStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=Excel 12.0;";

            string[] DashboardName = new string[100];
            int i = 0;
            int j = 0;
using (OleDbConnection connection = new OleDbConnection(connStr))
            {
                connection.Open();
                OleDbCommand command = new OleDbCommand("select * from [TestDetails$]", connection);
using (OleDbDataReader dr = command.ExecuteReader())
                {
                    dr.NextResult();
                    for ( j = 0; j < dr.FieldCount; j++)
                    {
                        
                        var row1Col0 = dr[j];
                           
                            DashboardName[i++] =                    row1Col0.ToString();
                    }

                }
            }
        }

So the solution is to download and install 

Microsoft Access Database Engine 2010 Redistributable.