C Pop Up Selenium
C Pop Up Selenium
Print Pop-up-:
Character statics-:
We cannot move this popup.
We cannot inspect this popup.
This popup will be having print & cancel button.
Solution-: We handle this popup by using Robot class.
Notification popup-:
Character statics-:
We cannot move this popup.
We cannot inspect this popup.
It will be having two buttons allow & block.
It will be displayed below the address bar in the beginning similar to
alert popup.
Solution-:
To handle this popup we change the setting of the browser, so that
notification popup itself will not be displayed.
To change the setting of the browser we use addArgument method of
chromeOptions class.
ChromeOptions option = new ChromeOptions();
option.addArguments("--disable-notifications");
ChromeDriver driver = new ChromeDriver(option);
driver.manage().window().maximize();
driver.get("https://www.yatra.com/");
Authentication Popup-:
Character statics-:
Parallel execution
To run a test script in parallel across 3 different browsers using Selenium WebDriver and
TestNG, we can use the TestNG parallel execution feature.
Step 1: Create WebDriver Instances for Different Browsers
First, we need to create separate WebDriver instances for the browsers we want to run.
WebDriver driver;
@Parameters("browser")
@Test
driver.manage().window().maximize();
driver.get("http://google.com");
driver.quit();
</suite>
Step 3: Run the Tests
When we run the testng.xml file, TestNG will execute the tests in parallel across Chrome,
Firefox, and Edge.
Each test will run independently in its respective browser, and the thread-count defines the
number of concurrent threads (in this case, 3 for 3 browsers).
driver.findElement(By.id("triggerPopupButton")).click();
// Wait for the popup to appear
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
WebElement popup =
wait.until(ExpectedConditions.visibilityOfElement(By.id("ajaxPopup")));
popup.findElement(By.id("popupButton")).click();
driver.quit();
driver.findElement(By.id("popupButton")).click();
Q. If the class contains multiple test cases in which order they are execute?
Ans-: Alphabetical order.
Q. How to execute the test methods in required order?
Ans-: By using priority [ @Test (priority =1 ) ]
Q. How do you run a test method multiple time ?
Ans-: By using invocation count @Test ( invocationCount =3 )
Q. How do you disable the text method on test case ?
Ans-: By using enable = false [ @Test (enable = false) ]
Q. How do you make a test depends on other test ?
Ans-: By using depends on methods option
@Test (dependsOnMethods = “ Create”)
@Test (dependsOnMethods = { “create” , “update”})
Q. what if two methods are depends on each other.
Ans-: We get TestNGException
Selenium Grid
Selenium Grid is a tool used with Selenium to distribute and run tests
across multiple machines and environments simultaneously.
It allows parallel execution of tests on different browsers, operating
systems, and machines, which significantly reduces the time required for
test execution.
Benefits of Using Selenium Grid
Parallel Testing: Run multiple tests concurrently, speeding up the testing
process.
Cross-Browser Testing: Test on different browsers and versions without
needing separate configurations.
Cross-Platform Testing: Test across different operating systems like
Windows, macOS, and Linux.
Scalability: Easily scale by adding more nodes with different
configurations.
How Selenium Grid Works
Set up the Hub and Nodes: The hub is started on one machine, and the
nodes connect to it. Each node registers itself with the hub, specifying
the browser types, versions, and OS that it supports.
Test Execution: When a test request is sent to the hub, it assigns the test
to an available node based on the required configuration (browser, OS).
Parallel Execution: Multiple tests can be distributed across different
nodes, allowing for parallel execution and faster feedback.