Web Application And Mobile Apps Testing: Selenium Automation
Showing posts with label Selenium Automation. Show all posts
Showing posts with label Selenium Automation. Show all posts

Tuesday, April 1, 2025

 

𝐒𝐞𝐥𝐞𝐧𝐢𝐮𝐦 𝐉𝐚𝐯𝐚 𝐏𝐫𝐨𝐣𝐞𝐜𝐭 𝐒𝐞𝐭𝐮𝐩 - 𝐉𝐚𝐯𝐚, 𝐌𝐚𝐯𝐞𝐧, 𝐈𝐧𝐭𝐞𝐥𝐥𝐢𝐉

1. Install & Configure Java
- Check Java installation using `java -version`.
- If not installed, download and install Java from the official Oracle website.
- Set `JAVA_HOME` and add `JAVA_HOME/bin` to the system `Path`.

2. Install IntelliJ IDEA & Maven
- Download and install IntelliJ IDEA (Community Edition).
- Check Maven installation using `mvn -version`.
- If missing, download Maven and set `MAVEN_HOME`.

3. Create a Maven Project
- Open IntelliJ IDEA, create a new Maven project.
- Set Group ID: `com.selenium.framework` | Artifact ID: `selenium-automation`.
- Click Finish and run `mvn clean install` to verify setup.

4. Add Dependencies in pom.xml
- Add Selenium WebDriver, Selenium Manager, and TestNG dependencies.
- Update the project using `mvn clean install`.

5. Create & Run First Selenium Test
- Create a new class `FirstTest` in `src/main/java`.
- Write a basic Selenium script to launch a browser, open a website, and print the page title.
- Run the test to verify setup.


 

𝐗𝐏𝐚𝐭𝐡 & 𝐂𝐒𝐒 𝐒𝐞𝐥𝐞𝐜𝐭𝐨𝐫 𝐓𝐞𝐜𝐡𝐧𝐢𝐪𝐮𝐞𝐬 𝐟𝐨𝐫 𝐀𝐮𝐭𝐨𝐦𝐚𝐭𝐢𝐨𝐧 𝐓𝐞𝐬𝐭𝐢𝐧𝐠

❇️ XPath Functions & Axes

- `text()`– Matches elements based on exact text.
`//div[text()='login_id']`

- `normalize-space()`– Trims extra spaces before matching text.
`//div[normalize-space()='login test']`

- `contains()`– Finds elements containing a substring.
`//input[contains(@id, 'username')]`

- `starts-with()`– Selects elements whose attribute starts with a string.
`//button[starts-with(@class, 'btn')]`

- `position()`– Retrieves elements based on their position in a set.
`(//ul[@class='menu']/li)[position()=2]`

- `last()`– Selects the last element in a node set.
`(//table//tr)[last()]`

- `count()`– Counts the number of matching elements.
`count(//input[@type='checkbox'])`

- `ancestor::`– Finds all ancestors of an element.
`//a[text()='Logout']/ancestor::div`

- `following-sibling::`– Selects all following siblings.
`//label[text()='Email']/following-sibling::input`

- `parent::`– Selects the immediate parent element.
`//span[text()='Username']/parent::div`

- `descendant::`– Finds all descendants of an element.
`//div[@class='container']/descendant::input`

- `translate()`– Normalizes text by replacing or removing characters.
`//input[contains(translate(@id, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'),'username')]`

❇️ CSS Selector Techniques

- Tag & Attribute Selector– Matches an element with a specific attribute.
`input[id='username']`

- Class Selector– Matches elements with a specific class.
`.btn-primary`

- ID Selector– Selects an element with a unique ID.
`hashtaglogin-button`

- Attribute Contains (`*=`)– Finds elements where an attribute contains a substring.
`input[id*='user']`

- Attribute Starts With (`^=`)– Matches elements where an attribute starts with a string.
`button[class^='btn']`

- Attribute Ends With (`$=`)– Matches elements where an attribute ends with a string.
`img[src$='.png']`

- Direct Child Selector (`>`)– Selects a direct child of an element.
`div > input`

- General Sibling Selector (`~`)– Selects all siblings after a specific element.
`label ~ input`

- Adjacent Sibling Selector (`+`)– Selects the immediate next sibling.
`label + input`

- Nth-Child Selector (`nth-child(n)`)– Selects the nth child of an element.
`ul.menu li:nth-child(2)`

- First & Last Child Selector– Selects the first or last child of a parent element.
`ul.menu li:first-child`
`ul.menu li:last-child`

- Not Selector (`:not()`)– Excludes elements that match a certain condition.
`input:not([type='submit'])`



Translate

Popular Posts

Total Pageviews