-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
331 additions
and
328 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,74 @@ | ||
// Licensed to the Software Freedom Conservancy (SFC) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The SFC licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
|
||
using System; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using OpenQA.Selenium; | ||
using OpenQA.Selenium.Chrome; | ||
using System.Collections.Generic; | ||
|
||
namespace SeleniumDocs.Interactions | ||
{ | ||
[TestClass] | ||
public class FramesTest : BaseTest | ||
[TestClass] | ||
public class FramesTest | ||
{ | ||
[TestMethod] | ||
public void TestFrames() | ||
{ | ||
WebDriver driver = new ChromeDriver(); | ||
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromMilliseconds(500); | ||
|
||
// Navigate to Url | ||
driver.Url= "https://www.selenium.dev/selenium/web/iframes.html"; | ||
//switch To IFrame using Web Element | ||
IWebElement iframe = driver.FindElement(By.Id("iframe1")); | ||
//Switch to the frame | ||
driver.SwitchTo().Frame(iframe); | ||
Assert.AreEqual(true, driver.PageSource.Contains("We Leave From Here")); | ||
//Now we can type text into email field | ||
IWebElement emailE = driver.FindElement(By.Id("email")); | ||
emailE.SendKeys("[email protected]"); | ||
emailE.Clear(); | ||
driver.SwitchTo().DefaultContent(); | ||
|
||
|
||
//switch To IFrame using name or id | ||
driver.FindElement(By.Name("iframe1-name")); | ||
//Switch to the frame | ||
driver.SwitchTo().Frame(iframe); | ||
Assert.AreEqual(true, driver.PageSource.Contains("We Leave From Here")); | ||
IWebElement email = driver.FindElement(By.Id("email")); | ||
//Now we can type text into email field | ||
email.SendKeys("[email protected]"); | ||
email.Clear(); | ||
driver.SwitchTo().DefaultContent(); | ||
|
||
|
||
//switch To IFrame using index | ||
driver.SwitchTo().Frame(0); | ||
Assert.AreEqual(true, driver.PageSource.Contains("We Leave From Here")); | ||
|
||
//leave frame | ||
driver.SwitchTo().DefaultContent(); | ||
Assert.AreEqual(true, driver.PageSource.Contains("This page has iframes")); | ||
|
||
//quit the browser | ||
driver.Quit(); | ||
} | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
examples/dotnet/SeleniumDocs/Interactions/InteractionsTest.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Licensed to the Software Freedom Conservancy (SFC) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The SFC licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
|
||
using System; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using OpenQA.Selenium; | ||
using OpenQA.Selenium.Chrome; | ||
namespace SeleniumDocumentation.SeleniumInteractions | ||
{ | ||
[TestClass] | ||
public class InteractionsTest | ||
{ | ||
[TestMethod] | ||
public void TestInteractions() | ||
{ | ||
WebDriver driver = new ChromeDriver(); | ||
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromMilliseconds(500); | ||
|
||
// Navigate to Url | ||
driver.Url="https://www.selenium.dev/"; | ||
//GetTitle | ||
String title = driver.Title; | ||
Assert.AreEqual(title, "Selenium"); | ||
|
||
//GetCurrentURL | ||
String url = driver.Url; | ||
Assert.AreEqual(url, "https://www.selenium.dev/"); | ||
|
||
//quitting driver | ||
driver.Quit(); //close all windows | ||
} | ||
} | ||
} |
This file contains 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
93 changes: 89 additions & 4 deletions
93
examples/java/src/test/java/dev/selenium/interactions/AlertsTest.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,92 @@ | ||
package dev.selenium.interactions; | ||
// Licensed to the Software Freedom Conservancy (SFC) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The SFC licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
import dev.selenium.BaseTest; | ||
import org.junit.jupiter.api.Test; | ||
import org.openqa.selenium.*; | ||
import org.openqa.selenium.chrome.ChromeDriver; | ||
import org.openqa.selenium.chrome.ChromeOptions; | ||
import org.openqa.selenium.support.ui.ExpectedConditions; | ||
import org.openqa.selenium.support.ui.WebDriverWait; | ||
|
||
public class AlertsTest extends BaseTest { | ||
import java.time.Duration; | ||
|
||
} | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class AlertsTest { | ||
|
||
@Test | ||
public void testForAlerts() throws Exception { | ||
|
||
ChromeOptions chromeOptions = new ChromeOptions(); | ||
chromeOptions.addArguments("disable-search-engine-choice-screen"); | ||
WebDriver driver = new ChromeDriver(chromeOptions); | ||
|
||
driver.manage().timeouts().implicitlyWait(Duration.ofMillis(500)); | ||
driver.manage().window().maximize(); | ||
//Navigate to Url | ||
driver.get("https://www.selenium.dev/documentation/webdriver/interactions/alerts/"); | ||
|
||
//Simple Alert | ||
//Click the link to activate the alert | ||
JavascriptExecutor js = (JavascriptExecutor) driver; | ||
//execute js for alert | ||
js.executeScript("alert('Sample Alert');"); | ||
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(30)); | ||
//Wait for the alert to be displayed and store it in a variable | ||
wait.until(ExpectedConditions.alertIsPresent()); | ||
|
||
Alert alert = driver.switchTo().alert(); | ||
//Store the alert text in a variable and verify it | ||
String text = alert.getText(); | ||
assertEquals(text, "Sample Alert"); | ||
//Press the OK button | ||
alert.accept(); | ||
|
||
//Confirm | ||
//execute js for confirm | ||
js.executeScript("confirm('Are you sure?');"); | ||
//Wait for the alert to be displayed | ||
wait = new WebDriverWait(driver, Duration.ofSeconds(30)); | ||
wait.until(ExpectedConditions.alertIsPresent()); | ||
|
||
|
||
alert = driver.switchTo().alert(); | ||
//Store the alert text in a variable and verify it | ||
text = alert.getText(); | ||
assertEquals(text, "Are you sure?"); | ||
//Press the Cancel button | ||
alert.dismiss(); | ||
|
||
//Prompt | ||
//execute js for prompt | ||
js.executeScript("prompt('What is your name?');"); | ||
//Wait for the alert to be displayed and store it in a variable | ||
wait = new WebDriverWait(driver, Duration.ofSeconds(30)); | ||
wait.until(ExpectedConditions.alertIsPresent()); | ||
|
||
alert = driver.switchTo().alert(); | ||
//Store the alert text in a variable and verify it | ||
text = alert.getText(); | ||
assertEquals(text, "What is your name?"); | ||
//Type your message | ||
alert.sendKeys("Selenium"); | ||
//Press the OK button | ||
alert.accept(); | ||
//quit the browser | ||
driver.quit(); | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.