Created
December 15, 2021 16:07
-
-
Save muditlambda/ca43d1d603046aab6439a9a3e9b9bd5a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package MyTests; | |
| import org.openqa.Selenium.By; | |
| import org.openqa.Selenium.WebElement; | |
| import org.openqa.Selenium.remote.DesiredCapabilities; | |
| import org.openqa.Selenium.remote.RemoteWebDriver; | |
| import org.testng.annotations.AfterTest; | |
| import org.testng.annotations.BeforeTest; | |
| import org.testng.annotations.Parameters; | |
| import org.testng.annotations.Test; | |
| import java.net.MalformedURLException; | |
| import java.net.URL; | |
| import java.util.concurrent.TimeUnit; | |
| public class Demo { | |
| String username = "user-name"; //Enter your username | |
| String accesskey = "access-key"; //Enter your accesskey | |
| static RemoteWebDriver driver; | |
| String gridURL = "@hub.lambdatest.com/wd/hub"; | |
| String urlToTest = "https://www.rediff.com/"; | |
| @BeforeTest | |
| @Parameters("browser") | |
| public void setup(String browser) { | |
| System.out.println("Setting up the drivers and browsers"); | |
| DesiredCapabilities capabilities = new DesiredCapabilities(); | |
| if(browser.equals("Chrome")) { | |
| capabilities.setCapability("platform", "Windows 10");// To specify the OS | |
| capabilities.setCapability("browserName", "Chrome"); //To specify the browser | |
| capabilities.setCapability("version","94.0"); //To specify the browser | |
| capabilities.setCapability("build", "ChromeTests"); //To identify the test | |
| capabilities.setCapability("name", "Handle_iframes"); | |
| } | |
| else if (browser.equals("Firefox")){ | |
| capabilities.setCapability("browserName", "Firefox"); //To specify the browser | |
| capabilities.setCapability("version", "93.0"); //To specify the browser version | |
| capabilities.setCapability("platform", "Windows 10"); // To specify the OS | |
| capabilities.setCapability("build", "FirefoxTests"); //To identify the test | |
| capabilities.setCapability("name", "Handle_iframes"); | |
| } | |
| else if (browser.equals("Edge")){ | |
| capabilities.setCapability("browserName", "MicrosoftEdge"); | |
| capabilities.setCapability("platform", "Windows 10"); | |
| capabilities.setCapability("version","94.0"); // To specify the OS | |
| capabilities.setCapability("build", "EdgeTests"); //To identify the test | |
| capabilities.setCapability("name", "Handle_iframes"); | |
| } | |
| capabilities.setCapability("network", true); // To enable network logs | |
| capabilities.setCapability("visual", true); // To enable step by step screenshot | |
| capabilities.setCapability("video", true); // To enable video recording | |
| capabilities.setCapability("console", true); // To capture console logs | |
| try { | |
| driver = new RemoteWebDriver(new URL("https://" + username + ":" + accesskey + gridURL), capabilities); | |
| } catch (MalformedURLException e) { | |
| System.out.println("Invalid grid URL"); | |
| } catch (Exception e) { | |
| System.out.println(e.getMessage()); | |
| } | |
| } | |
| @Test | |
| public void test1_switchUsingId(){ | |
| System.out.println("Switching iFrame using id has started"); | |
| driver.get(urlToTest); | |
| driver.manage().window().maximize(); | |
| driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS); | |
| driver.switchTo().frame("moneyiframe"); //moneyiframe is the id of the iframe | |
| WebElement option = driver.findElement(By.id("nseindex")); | |
| String nse_Value = option.getText(); | |
| System.out.println("The NSE value is " +nse_Value); | |
| System.out.println("Switching iFrame using id has ended"); | |
| driver.switchTo().defaultContent(); | |
| WebElement signIn_element = driver.findElement(By.className("signin")); | |
| signIn_element.click(); | |
| WebElement username = driver.findElement(By.id("login1")); | |
| WebElement password = driver.findElement(By.id("password")); | |
| username.sendKeys("test12345"); | |
| password.sendKeys("abcd@12344"); | |
| } | |
| @AfterTest | |
| public void tearDown(){ | |
| driver.close(); | |
| System.out.println("Tests ended successfully"); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment