Skip to content

Initializing seleniumJavaExperiment #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions seleniumJavaExperiment/src/test/java/SeleniumTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,19 @@
import org.testng.annotations.Test;
import pageObjects.ABtestPage;
import pageObjects.CheckboxesPage;
import pageObjects.DropDownPage;
import pageObjects.HomePage;

import java.io.PrintStream;

public class SeleniumTests {

WebDriver driver;

HomePage homePage;
ABtestPage abTestPage;
CheckboxesPage checkboxesPage;
DropDownPage dropdownpage;

@BeforeClass
public void beforeClass () {
Expand All @@ -28,6 +32,7 @@ public void beforeClass () {
homePage = PageFactory.initElements(driver, HomePage.class);
abTestPage = PageFactory.initElements(driver, ABtestPage.class);
checkboxesPage = PageFactory.initElements(driver, CheckboxesPage.class);
dropdownpage = PageFactory.initElements(driver, DropDownPage.class);
}
public void navigateBackHome(){
driver.get("http://the-internet.herokuapp.com/");
Expand Down Expand Up @@ -61,7 +66,18 @@ public void unclickCheckbox2(){
checkboxesPage.unclickSecondCheckbox();
Assert.assertFalse(checkboxesPage.getCheckboxState2());
}
@Test(priority = 4)
public void testNavigationToDropdownPage () {
navigateBackHome();
homePage.clickOption("Dropdown");
Assert.assertEquals("Dropdown List", dropdownpage.getTitleText());
dropdownpage.openDropDown();
dropdownpage.selectOptions("Option 2");
dropdownpage.openDropDown();
System.out.println(dropdownpage.returnDropdownValue());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid logs if possible.

Assert.assertEquals("Option 2", dropdownpage.returnDropdownValue());

}

@AfterClass
public void afterClass () {
Expand Down
32 changes: 32 additions & 0 deletions seleniumJavaExperiment/src/test/java/pageObjects/DropDownPage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package pageObjects;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.ui.Select;

public class DropDownPage {
@FindBy(css = ".example h3")
WebElement pageTitle;

@FindBy(id = "dropdown")
WebElement dropdown;

public String getTitleText () {
return pageTitle.getText();
}

public void openDropDown(){dropdown.click();}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When using select, you do not need to open the dropdown. You can directly use select.


public void selectOptions(String option){
Select opt= new Select(dropdown);
opt.selectByVisibleText(option);

}

public String returnDropdownValue(){

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accept the web Element as a parameter.

Select opt= new Select(dropdown);
WebElement dropdownx= opt.getFirstSelectedOption();
String value= dropdownx.getText();
return value;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix the indentations.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kenil-fadia I'll connect with you to help me out with this.

}
}