Monday, July 15, 2019

Internet Explorer XPath using MRI

chropath



chropath supports chrome and Firefox

             chrome://apps/
             Click on Web Store





    Add to Chrome

right click on element --> Inspect -->  ChroPath









Sunday, July 14, 2019

Using app.config file to define a data source, odbc driver, access database engine, data driven testing , Excel



https://docs.microsoft.com/en-us/visualstudio/test/walkthrough-using-a-configuration-file-to-define-a-data-source?view=vs-2019


Install Access Database Engine


Install 32 bit


Add ODBC Data Source:
















    1. Create a  CodedUI Project
    2. Create a Excel sheet data. (Copy always)
   
         





    2. Add App.config file
 
?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <section name="microsoft.visualstudio.testtools" type="Microsoft.VisualStudio.TestTools.UnitTesting.TestConfigurationSection, Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
    </configSections>
    <connectionStrings>
        <add name="MyJetConn" connectionString="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\testdatasource.accdb; Persist Security Info=False;" providerName="System.Data.OleDb" />
        <add name="MyExcelConn" connectionString="Dsn=Excel Files;dbq=data.xlsx;defaultdir=.\; driverid=790;maxbuffersize=2048;pagetimeout=5" providerName="System.Data.Odbc" />
    </connectionStrings>
    <microsoft.visualstudio.testtools>
        <dataSources>
            <add name="MyJetDataSource" connectionString="MyJetConn" dataTableName="MyDataTable" dataAccessMethod="Sequential"/>
            <add name="MyExcelDataSource" connectionString="MyExcelConn" dataTableName="Sheet1$" dataAccessMethod="Sequential"/>
        </dataSources>
    </microsoft.visualstudio.testtools>

</configuration>


Write Test:

  [TestMethod()]
        [DeploymentItem("data.xlsx")]
        [DataSource("MyExcelDataSource")]
        public void MyTestMethod2()
        {
            Console.WriteLine(TestContext.DataRow["Val1"]);
            Console.WriteLine(TestContext.DataRow["Val2"]);           
        }



Troubleshoot:

In App.config, Yellow highlighted is having same version of the visual studio Unit Framework dll.




--EoF--



Xpath and CSS selector , Developer Console XPath Parent : https://www.guru99.com/xpath-selenium.html



Contains Attribute:

//input[contains(@value,"Approve")]


Contains text alternative
https://stackoverflow.com/questions/23543044/how-to-use-xpath-preceding-sibling-correctly

//label[contains(.,"Name")]



contains attributes
//img[contains(@src,"wla")]


element attribute or condition

parent::tr/td/span[text()="Accepted" or text()="Processed"]



https://robotframework.org/SeleniumLibrary/SeleniumLibrary.html#Press%20Keys

Press Keys  ENTER


text contains after line break <br>

//li/a[contains(.,'FREIGHT')]
https://stackoverflow.com/questions/36718817/xpath-for-text-after-br



ancestor with attributes

//span[text()="Update"]/ancestor::div[@class="ng-star-inserted"]



particular cell and text contains
td position

tr/td[2][text()="${From}"]/ancestor::tr/td[3][text()="${To}"]/ancestor::tr/td[4]//span[contains(text(),"${VtsStatus}")]


multiple class

//div[@class="dropdown-menu show"]//a[contains(text(),"User Management")]



href contains

//li/a[contains(@href,"warehouse")]


https://stackoverflow.com/questions/26640746/xpath-syntax-for-and-not-contains/26641239

Class not contains
//div[text()="10" and not(contains(@class,'mute'))]



Xpath 2:

What browsers support Xpath 2.0?



element and child element with conditions

https://stackoverflow.com/questions/10247978/xpath-with-multiple-conditions

//category[@name='Sport' and ./author/text()='James Small']




text case insensitive  & check in lower case


https://stackoverflow.com/questions/8474031/case-insensitive-xpath-contains-possible

equal:
//table/tbody/tr[2]/td[5][translate(., 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')= 'port']

contains:

//td[contains(translate(., 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), 'company113054')]

//table/tbody/tr[2]/td[5][contains(translate(., 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), 'textvaluexyz')]


Not tried yet:
https://stackoverflow.com/questions/2893551/case-insensitive-matching-in-xpath



Select index and Attributes (Property)

//table/tbody/tr[1]/td[1][contains(.,'Permits and Certificates_Daily')]


https://stackoverflow.com/questions/16732508/how-to-find-2nd-td-in-html-using-xpath


contains id:

//div[contains(@id,"content-body")]//p
document.evaluate('//*[@id="kwindowVesselCallSp"]/div/div[1]/div[7]/div', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.innerText



preceding-sibling can be indexing it will go relative to the element

${elementLoc}/preceding-sibling::td[1]



Xpath Multiple column data verification:
Verifying two values in the table column

ex:  name = "Pradeep"
       place = ""Mysore

//table/tbody/tr/td[1]/span[contains(text(),"Pradeep")]/../../td[4][contains(text(),"Mysore")]


XPath Ancestor:

//div[text()='building1' and @class='wrap']/ancestor::tr/td/div/div[@class='x-grid-row-checker']


Attributes:
//div[@name="Quantity"]
//*[@name="Quantity"]


Following-Sibling searches for the all the attributes   ::td/div/i

//*[@id="other"]/table//td[contains(@title," Services")]/following-sibling::td/div/i


following-sibling::td[2]


//*[@id="other"]/table//td[contains(@title,"Services")]/following-sibling::td[contains(text(),"VA")]/following-sibling::td[2]


Identify the controls in the developer command prompt or internet console with JavaScript and JQuery

https://stackoverflow.com/questions/22571267/how-to-verify-an-xpath-expression-in-chrome-developers-tool-or-firefoxs-firebug


Click through XPath:

https://stackoverflow.com/questions/5626168/automating-a-javascript-button-click

var xPathRes = document.evaluate ('//div[1]/a[1]', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);

xPathRes.singleNodeValue.click();


Get Inner Text XPath:

${value}=  Execute JavaScript  return document.evaluate('//h5[contains(text(),"abc")]/following-sibling::h4', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.innerHTML




document.getElementsByName("q")[0].value="search"
document.getElementsByName("q")[0].click()
document.getElementById("abcd").click()

$("input[name='q']").value="j"
$("input[name='btnK']").click()

document.getElementsByName("btnK")[1].style.border="5px solid red";
$("input[name='q']").className















Class with multiple atrributes:

(//div[text()="Enter Port"]/../div[@class="ng-value ng-star-inserted"]/span[@class="ng-value-label ng-star-inserted"])[2]

(//div[text()="Enter Terminal"]/../div[@class="ng-value ng-star-inserted"]/span[@class="ng-value-label ng-star-inserted"])[1]



Xpath Ancestor with attributes:
https://stackoverflow.com/questions/10076618/xpath-to-find-ancestor-node-containing-css-class

./ancestor::div[contains(concat(' ', @class, ' '), ' x-grid-view ')][1]

https://www.youtube.com/watch?v=W9_q7tZon2M&list=PLhW3qG5bs-L83gLEZVIDHOvgTTz27po_0

Open web page : F12 -Developer tool bar

//    :relative Xpath
/     :absolute XPath

//tagname[@attribute='value']         //input[@name='q']

Chrome extensions to find XPath:

  • eskry
  • chropath



And Condition:

Syntax:
//tag[@attribute='value1'][@attribute2='value2'] 
Examples:
 //input[@type='text'][@name='txtUsernmae']
//*[@type='text'][@name='txtUsernmae']

Search By Text:
//a[text()='Share This']

Contains:

//a[contains(text(),'Share')]


Starts with:

//*[starts-with(@id,'home')]

//*[starts-with(@id,'home')  or @id='txtUsername' ]


And  Or Condition

//*[@id='txtUsername'  and @name='txtUsername' ]
//*[@id='txtUsername'  or @name='txtUsername' ]



XPath Parent:

//*[title="50"]/parent::store
This XPath will only select the parent node if it is a store.
But you can also use one of these
//*[title="50"]/parent::*
//*[title="50"]/..




todo read
https://stackoverflow.com/questions/22571267/how-to-verify-an-xpath-expression-in-chrome-developers-tool-or-firefoxs-firebug


Xpath finding in Chrome:
https://yizeng.me/2014/03/23/evaluate-and-validate-xpath-css-selectors-in-chrome-developer-tools/

xpath in Developer Tool bar Console Tab
$x("XPATH") 
$x(".//div")       or   $x('.//input')


CSS Path in Developer Tool bar Console Tab
$$("header")
$("#btnNo").css("border-color","red");


http://aksahu.blogspot.in/2014/01/selenium-tricks-for-css-and-xpath-locators.html


(4) Direct Child:
A direct child of an element is denoted as "/" in Xpath and ">" in CSS selector. See the example below for a direct child "li" for a "ul" element:
In Xpath locator 
1
//ul/li
In CSS selector 
1
css=ul > li

(5) Child or Subchild:
A direct child of an element is denoted as "//" in Xpath and a wehite-space(" ") in CSS selector. See the example below for a child/subchild "li" for a "ul" element:
In Xpath locator 
1
//ul//li
In CSS selector 
1
css=ul li
Note that "ul li" and "ul > li" are different. If you are confusing please go through this article.

Firewall


Block IP Packets from Certain region(Country).

Firewall can be software or Dedicated hardware or (Mix of both)

One method firewall uses is Packet filtering.

Firewalls can block ports.

It checks details in the packet header, such as it source and destination, ip address, port number and the protocol its running.

If a request coming from a unknown source or going to an unexpected port. It can block it.
Advance firewall can detect malware in the packets.








Proxy Server


Proxy Server: Server placed in between Client and Internet.

Before forwarding response back to the client, it can filter them to ensure they are safe to receive.

Network Security:
Any request need to be passed through Proxy Server and real IP of the client is not shown. Instead Proxy Server provides its own logical IP address to the Web Server. So any hacker is unable to hack Client as IP is made unavailable.

Network Performance Improvement:
Proxy Server has a cache, so if any client looking for updates then for first time the Proxy will download from internet and saves in the cache. For subsequent client requires the same updates instead of downloading from internet it provides from Cache. Thus, provides congestion free.

Monitor User in the Network:

Block Website: A network admin can block a particular website.

Access Control: Block Facebook and set rule to bypass for particular users.





PhantomJS HTMLUnitDriver Headless -todo-


hi

http://www.automationtestinghub.com/selenium-headless-chrome-firefox/


JMeter Simple Controller

  Simple Controller is just a  container  for user request.