Skip to content
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

Homework25 #25

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
77 changes: 75 additions & 2 deletions src/test/java/BaseTest.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,84 @@
import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.edge.EdgeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Parameters;

import java.net.MalformedURLException;
import java.net.URL;
import java.time.Duration;
import java.util.HashMap;

public class BaseTest {

public WebDriver driver = null;
public String url = null;
private static final ThreadLocal<WebDriver> threadDriver = new ThreadLocal<>();
protected void navigateToPage() {
driver.get(url);
}
@BeforeSuite
static void setupClass() {
WebDriverManager.chromedriver().setup();
public static WebDriver getDriver() {
return threadDriver.get();
}
@BeforeMethod
@Parameters({"BaseUrl"})
public void setupBrowser(String BaseURL) throws MalformedURLException {
threadDriver.set(pickBrowser(System.getProperty("browser")));
getDriver().manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
url = BaseURL;
navigateToPage();
}
@AfterMethod
public void tearDown() {
threadDriver.get().close();
threadDriver.remove();
}
public WebDriver pickBrowser(String browser) throws MalformedURLException {
DesiredCapabilities caps = new DesiredCapabilities();
String gridURL = "https://10.0.0.206:4444/";
switch (browser) {
case "MicroSoftEdge":
WebDriverManager.edgedriver().setup();
EdgeOptions edgeOptions = new EdgeOptions();
edgeOptions.addArguments("--remote-allow-origins=*");
return driver = new EdgeDriver();
case "cloud":
return LambdaTest();

default:
WebDriverManager.chromedriver().setup();
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--remote-allow-origins=*");
return driver = new ChromeDriver(chromeOptions);
}
}

public RemoteWebDriver LambdaTest() throws MalformedURLException {
String HubURL = "https://hub.lambdatest.com/wd/hub";
DesiredCapabilities capabilities = new DesiredCapabilities();

ChromeOptions browserOptions = new ChromeOptions();
browserOptions.setPlatformName("Windows 10");
browserOptions.setBrowserVersion("122.0");
HashMap<String, Object> ltOptions = new HashMap<String, Object>();
ltOptions.put("username", "sadokha.david");
ltOptions.put("accessKey", "poTHwxG4slaMyczhUE8kIvKa7zJoi2kZtvolIUsU8BlPTOt2wv");
ltOptions.put("build", "TEST1");
ltOptions.put("project", "Untitled");
ltOptions.put("name", "TEST1Lambda");
ltOptions.put("w3c", true);
ltOptions.put("plugin", "java-java");
browserOptions.setCapability("LT:Options", ltOptions);

return new RemoteWebDriver(new URL(HubURL), capabilities);
}
}
}
4 changes: 4 additions & 0 deletions src/test/java/Basepage/BasePage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package Basepage;

public class BasePage {
}
17 changes: 17 additions & 0 deletions src/test/java/Basepage/HomePage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package Basepage;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

public class HomePage extends BasePage {
@FindBy(css = "a.view-profile")
WebElement profileIcon;
public HomePage(WebDriver givenDriver) {
super(givenDriver);
}
public HomePage clickProfileIcon() {
click(profileIcon);
return this;
}
}
23 changes: 23 additions & 0 deletions src/test/java/Basepage/ProfilePage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package Basepage;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

public class ProfilePage extends BasePage {
public ProfilePage(WebDriver givenDriver) {
super(givenDriver);
}
@FindBy(css = "[data-testid='theme-card-violet']")
WebElement violetTheme;
@FindBy(css = "[data-testid='theme-card-violet'][class='theme selected']")
WebElement selectedVioletTheme;
public boolean isVioletThemeSelected() {
findElement(selectedVioletTheme);
return selectedVioletTheme.isDisplayed();
}
public ProfilePage chooseVioletTheme() {
click(violetTheme);
return this;
}
}
53 changes: 44 additions & 9 deletions src/test/java/LoginTests.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,60 @@
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.FindBy;
import org.testng.Assert;
import org.testng.annotations.Test;

import java.net.MalformedURLException;
import java.time.Duration;
import java.util.HashMap;

public class LoginTests extends BaseTest {


@Test
public void loginWithCorrectCredentials1() {

LoginPage loginPage = new LoginPage(getDriver());
HomePage homePage = new HomePage(getDriver());

loginPage.provideEmail();
.providePassword();
.clickSubmit();

Assert.assertTrue(homePage.getUserAvatarIcon().isDisplayed());
}
@Test
public void loginEmptyEmailPassword() {

// Added ChromeOptions argument below to fix websocket error
ChromeOptions options = new ChromeOptions();
options.addArguments("--remote-allow-origins=*");
LoginPage loginPage = new LoginPage(getDriver());

WebDriver driver = new ChromeDriver(options);
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
loginPage.provideEmail();
.providePassword();
.clickSubmit();

String url = "https://qa.koel.app/";
driver.get(url);
Assert.assertEquals(driver.getCurrentUrl(), url);
driver.quit();
homePage.clickProfileIcon();
profilePage.chooseVioletTheme();
Assert.assertTrue(profilePage.isVioletThemeSelected());
}
@FindBy(css = "input[type='email']")
WebElement emailField;
@FindBy(css = "input[type='password']")
WebElement passwordField;
@FindBy("button[type='submit']")
WebDriver submitButton;
public void loginPage(WebDriver givenDriver) {
super(givenDriver);
}
public loginPage provideEmail(String email) {
emailField.sendKeys(email);
return this;
}
public loginPage clickSubmit() {
click(submitButton);
return this;
}

}
6 changes: 3 additions & 3 deletions src/test/resources/TestNG.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >

<suite name="TestNG">

<test name="Example Test" preserve-order="false">
<suite name="TestNG" parallel="methods" thread-count="2">
<parameter name="BaseUrl" value="https://qa.koel.app/"/>
<test name="LoginTests" preserve-order="false">
<classes>
<class name="LoginTests"/>
<class name="BaseTest"/>
Expand Down