Friday, December 7, 2018

Selenium from a different perspective - Google News reading bot


  1. From the below code user will navigate to the news.google.com.
  2. Extract everything under span tag.
  3. Save the extracted text to a string array.
  4. Data cleansing on the array.
  5. Transfer the array text to speech engine. 



public static void Main(string[] args)
        {

            IWebDriver driver;
            driver = new ChromeDriver(@"C:\Driver\2.41.0\");
            driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(30);
            driver.Navigate().GoToUrl("https://news.google.com");

            IList<IWebElement> elm = driver.FindElements(By.TagName("span"));

            string[] a = new string[2000];
            int i = 0;
            foreach (var item in elm)
            {
                a[i++] = item.Text.ToString();
            }
            a = a.Where(x => !string.IsNullOrEmpty(x)).ToArray();

            int j = 0;
            foreach (var item in a)
            {
                if (a[j].Length < 30)
                {
                    a[j] = "";
                }
                j++;
            }
            a = a.Where(x => !string.IsNullOrEmpty(x)).ToArray();

            SpeechSynthesizer synthesizer = new SpeechSynthesizer();
            synthesizer.SelectVoiceByHints(VoiceGender.Female, VoiceAge.Senior);
            synthesizer.Volume = 100;
            synthesizer.Rate = -1;
            int k = 1;
            foreach (var item in a)
            {
                synthesizer.Speak(a[k]);
                k++;
            }
        }

Wednesday, October 24, 2018

Troubleshooting sonar server error -SQL Database collation must be case-sensitive and accent-sensitive

I got this error while trying to configure a sonar server.
sonarqube-7.3

I when true the log files and this is what i found at the end of the web.log file.

2018.10.25 09:23:32 INFO  web[][o.s.p.ProcessEntryPoint] Starting web
2018.10.25 09:23:33 INFO  web[][o.a.t.u.n.NioSelectorPool] Using a shared selector for servlet write/read
2018.10.25 09:23:36 INFO  web[][o.s.c.e.CoreExtensionsLoader] Loaded core extensions: 
2018.10.25 09:23:38 INFO  web[][o.e.p.PluginsService] no modules loaded
2018.10.25 09:23:38 INFO  web[][o.e.p.PluginsService] loaded plugin [org.elasticsearch.join.ParentJoinPlugin]
2018.10.25 09:23:38 INFO  web[][o.e.p.PluginsService] loaded plugin [org.elasticsearch.percolator.PercolatorPlugin]
2018.10.25 09:23:38 INFO  web[][o.e.p.PluginsService] loaded plugin [org.elasticsearch.transport.Netty4Plugin]
2018.10.25 09:23:41 INFO  web[][o.s.s.e.EsClientProvider] Connected to local Elasticsearch: [127.0.0.1:9001]
2018.10.25 09:23:41 INFO  web[][o.s.s.p.LogServerVersion] SonarQube Server / 7.3.0.15553 / 7f72262e02808e9431d97735ece621a22a1d8208
2018.10.25 09:23:41 INFO  web[][o.sonar.db.Database] Create JDBC data source for jdbc:sqlserver://localhost;databaseName=SONAR;selectMethod=cursor;Connect Timeout=200; pooling='true'; Max Pool Size=200
2018.10.25 09:23:46 INFO  web[][o.s.s.p.ServerFileSystemImpl] SonarQube home: C:\sonarqube-7.3\sonarqube-7.3
2018.10.25 09:23:46 INFO  web[][o.s.s.u.SystemPasscodeImpl] System authentication by passcode is disabled
2018.10.25 09:23:48 INFO  web[][o.s.s.p.ServerPluginRepository] Deploy plugin Git / 1.4.1.1128 / e051f5aeb379541b13956447b5dc8b4e0b23b098
2018.10.25 09:23:48 INFO  web[][o.s.s.p.ServerPluginRepository] Deploy plugin LDAP / 2.2.0.608 / 79dc3fa4393a29667673c70182f3016288b548b7
2018.10.25 09:23:48 INFO  web[][o.s.s.p.ServerPluginRepository] Deploy plugin SonarC# / 7.3.2.6129 / e7a731061a7fa928c4e1c11b830f22db97a61f83
2018.10.25 09:23:48 INFO  web[][o.s.s.p.ServerPluginRepository] Deploy plugin SonarCSS / 1.0.1.508 / 2eb799e363666ae65036ad61a6e6adc1a1283097
2018.10.25 09:23:48 INFO  web[][o.s.s.p.ServerPluginRepository] Deploy plugin SonarFlex / 2.4.0.1222 / 68d9cb3b7daccbc4869c4f2b89d09218d26a0829
2018.10.25 09:23:48 INFO  web[][o.s.s.p.ServerPluginRepository] Deploy plugin SonarGo / 1.1.0.1612 / 1809c7be6d88396c0a1b8d597b1e9e0ed8d29730
2018.10.25 09:23:48 INFO  web[][o.s.s.p.ServerPluginRepository] Deploy plugin SonarJS / 4.2.0.6476 / a21b56462f3375b5d51d90f1819862878476d817
2018.10.25 09:23:48 INFO  web[][o.s.s.p.ServerPluginRepository] Deploy plugin SonarJava / 5.6.1.15064 / dd4545a04af6f7d0cb0486926cfa8cfc5cae5ee1
2018.10.25 09:23:48 INFO  web[][o.s.s.p.ServerPluginRepository] Deploy plugin SonarKotlin / 1.0.1.965 / b5872affdfeda52e0a71494e2df9a3524b80d3bc
2018.10.25 09:23:48 INFO  web[][o.s.s.p.ServerPluginRepository] Deploy plugin SonarPHP / 2.14.0.3569 / 59a202b8d1c5276ce32da2a0bc63c94cae4cdeb2
2018.10.25 09:23:48 INFO  web[][o.s.s.p.ServerPluginRepository] Deploy plugin SonarPython / 1.10.0.2131 / a00e0ddc83bbeb01a9ee7475fab9eafe3f4096ac
2018.10.25 09:23:48 INFO  web[][o.s.s.p.ServerPluginRepository] Deploy plugin SonarTS / 1.7.0.2893 / 0d296cae94240b183a0b3ae6e1a409a60fe9f865
2018.10.25 09:23:48 INFO  web[][o.s.s.p.ServerPluginRepository] Deploy plugin SonarXML / 1.5.1.1452 / eadc1dcd0e24a3c77068e3c1d41af0327d6b16ea
2018.10.25 09:23:48 INFO  web[][o.s.s.p.ServerPluginRepository] Deploy plugin Svn / 1.8.0.1168 / 4143f2d119022a758f6bf40aed4294e4c31706cf
2018.10.25 09:23:49 INFO  web[][o.s.s.p.d.m.c.MssqlCharsetHandler] Verify that database collation is case-sensitive and accent-sensitive

2018.10.25 09:23:49 ERROR web[][o.s.s.p.Platform] Web server startup failed: Database collation must be case-sensitive and accent-sensitive. It is SQL_Latin1_General_CP1_CI_AS but should be SQL_Latin1_General_CP1_CS_AS.


At the end you might notice that its saying It is SQL_Latin1_General_CP1_CI_AS but should be SQL_Latin1_General_CP1_CS_AS.
So this means we need to change the collection type of our MS SQL database.
To do that go to properties of your data base and select options.
Then change the collection type to SQL_Latin1_General_CP1_CS_AS.


Tuesday, October 2, 2018

Increase the response time out on SoapUI for a individual test case

testRunner.testCase.settings.setString("HttpSettings@socket_timeout","200000")

Just at above line to the setup script section of your test case.


Monday, September 17, 2018

Write response to a txt file groovy script on SoapUI


import net.sf.*; import net.sf.json.*; import net.sf.json.groovy.*; import net.sf.json.groovy.JsonSlurper; def Res = context.expand( '${GetAllSchoolsForAustralia#Response}' ) def slurper = new JsonSlurper() def json = slurper.parseText Res def countryList = json.result._source.city log.info countryList def file = new File('D:/XXX/CityListAU.txt'); file << countryList

Friday, September 7, 2018

Count child nodes of a JSON response using groovy in soapui



import net.sf.*;
import net.sf.json.*;
import net.sf.json.groovy.*;
import net.sf.json.groovy.JsonSlurper
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)

//Getting response from methods
def response = context.expand( '${Request 1#Response}' ).toString()

def slurper = new JsonSlurper()
def json = slurper.parseText response
def countryList = json.result.size()
def ActualResultNodeCount=countryList - 1
log.info ActualResultNodeCount


This is also very useful when accessing  test case data.
import java.net.*
def ts = context.testCase.getTestStepByName("RequestMaori-culture")
def endpoint =ts.getPropertyValue('Endpoint')
log.info endpoint

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