11 тестов, посмотрите нормально теперь выглядит ожидание, так можно оставить?

This commit is contained in:
Lisyra 2018-09-26 22:16:47 +04:00
parent eb549dabf4
commit 375b49eeae
7 changed files with 175 additions and 89 deletions

View File

@ -25,35 +25,15 @@ public class DownloadTests
MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class); MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class);
GamePage page1 = PageFactory.initElements(context.getDriver(), GamePage.class); GamePage page1 = PageFactory.initElements(context.getDriver(), GamePage.class);
try { context.wait(10);
TimeUnit.SECONDS.sleep(10); // Same as Thread.sleep(5000);
// The "main" thread will sleep
} catch (InterruptedException e) {
}
page.clickPreviewLink(); page.clickPreviewLink();
try { context.wait(5);
TimeUnit.SECONDS.sleep(5); // Same as Thread.sleep(5000);
// The "main" thread will sleep
} catch (InterruptedException e) {
}
page1.clickDownloadLink(); page1.clickDownloadLink();
context.switchTab(1); context.switchTab(1);
try { context.wait(10);
TimeUnit.SECONDS.sleep(8); // Same as Thread.sleep(5000);
// The "main" thread will sleep
} catch (InterruptedException e) {
}
page1.clickDownloadTorrentLink(); page1.clickDownloadTorrentLink();
context.wait(15);
try {
TimeUnit.SECONDS.sleep(15); // Same as Thread.sleep(5000);
// The "main" thread will sleep
} catch (InterruptedException e) {
}
Assertions.assertTrue(GamePage.isDownloadPagePresent()); Assertions.assertTrue(GamePage.isDownloadPagePresent());
context.switchTab(0); context.switchTab(0);

View File

@ -0,0 +1,79 @@
import org.openqa.selenium.support.PageFactory;
import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import context.ChromeContext;
import context.Context;
import page.MainPage;
import page.GamePage;
public class FilterTests
{
private final static String APP_URL = "http://gmt-max.net/";
private static Context context;
@Test
public void searchWordOnSite()
{
Context.getDriver().get(APP_URL);
MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class);
context.wait(10);
page.search("Skyrim");
context.wait(5);
Assertions.assertTrue(MainPage.isSearchResultsPresent());
}
@Test
public void searchNothingOnSite()
{
Context.getDriver().get(APP_URL);
MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class);
context.wait(10);
page.search("");
context.wait(5);
Assertions.assertTrue(MainPage.isSearchResultsPresent());
}
@Test
public void sortByMMORPGLink()
{
Context.getDriver().get(APP_URL);
MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class);
context.wait(10);
page.clickSideMenuLink();
context.wait(5);
page.clickSideMenuSubLink();
context.wait(5);
Assertions.assertTrue(MainPage.isSideMenuLinkPresent());
}
@BeforeAll
public static void setup() {
context = new ChromeContext();
context.start();
//context.getDriver().manage().window().setSize(new Dimension(1366, 768));
}
@AfterAll
public static void quit() {
context.close();
}
}

View File

@ -0,0 +1,46 @@
import org.openqa.selenium.support.PageFactory;
import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import context.ChromeContext;
import context.Context;
import page.MainPage;
import page.GamePage;
public class MultimediaTests
{
private final static String APP_URL = "http://gmt-max.net/";
private static Context context;
@Test
public void checkPictures()
{
Context.getDriver().get(APP_URL);
MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class);
GamePage page1 = PageFactory.initElements(context.getDriver(), GamePage.class);
context.wait(10);
page.clickPreviewLink();
context.wait(5);
Assertions.assertTrue(GamePage.isPicturePresent());
}
@BeforeAll
public static void setup() {
context = new ChromeContext();
context.start();
//context.getDriver().manage().window().setSize(new Dimension(1366, 768));
}
@AfterAll
public static void quit() {
context.close();
}
}

View File

@ -28,17 +28,9 @@ public class NavigationTests
Context.getDriver().get(APP_URL); Context.getDriver().get(APP_URL);
MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class); MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class);
try { context.wait(10);
TimeUnit.SECONDS.sleep(10); // Same as Thread.sleep(5000);
// The "main" thread will sleep
} catch (InterruptedException e) {
}
page.clickRulesLink(); page.clickRulesLink();
try { context.wait(5);
TimeUnit.SECONDS.sleep(5); // Same as Thread.sleep(5000);
// The "main" thread will sleep
} catch (InterruptedException e) {
}
Assertions.assertTrue(MainPage.isRulesPresent()); Assertions.assertTrue(MainPage.isRulesPresent());
@ -50,17 +42,9 @@ public class NavigationTests
Context.getDriver().get(APP_URL); Context.getDriver().get(APP_URL);
MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class); MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class);
try { context.wait(10);
TimeUnit.SECONDS.sleep(10); // Same as Thread.sleep(5000);
// The "main" thread will sleep
} catch (InterruptedException e) {
}
page.clickPreviewLink(); page.clickPreviewLink();
try { context.wait(5);
TimeUnit.SECONDS.sleep(5); // Same as Thread.sleep(5000);
// The "main" thread will sleep
} catch (InterruptedException e) {
}
Assertions.assertTrue(MainPage.isPreviewPresent()); Assertions.assertTrue(MainPage.isPreviewPresent());
@ -72,17 +56,9 @@ public class NavigationTests
Context.getDriver().get(APP_URL); Context.getDriver().get(APP_URL);
MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class); MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class);
try { context.wait(10);
TimeUnit.SECONDS.sleep(10); // Same as Thread.sleep(5000);
// The "main" thread will sleep
} catch (InterruptedException e) {
}
page.clickpopularGiveup(); page.clickpopularGiveup();
try { context.wait(5);
TimeUnit.SECONDS.sleep(5); // Same as Thread.sleep(5000);
// The "main" thread will sleep
} catch (InterruptedException e) {
}
Assertions.assertTrue(MainPage.isPopularGiveupPresent()); Assertions.assertTrue(MainPage.isPopularGiveupPresent());
@ -94,17 +70,9 @@ public class NavigationTests
Context.getDriver().get(APP_URL); Context.getDriver().get(APP_URL);
MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class); MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class);
try { context.wait(10);
TimeUnit.SECONDS.sleep(10); // Same as Thread.sleep(5000);
// The "main" thread will sleep
} catch (InterruptedException e) {
}
page.clickexternalLink(); page.clickexternalLink();
try { context.wait(5);
TimeUnit.SECONDS.sleep(5); // Same as Thread.sleep(5000);
// The "main" thread will sleep
} catch (InterruptedException e) {
}
Assertions.assertTrue(MainPage.isExternalLinkPresent()); Assertions.assertTrue(MainPage.isExternalLinkPresent());
@ -116,17 +84,9 @@ public class NavigationTests
Context.getDriver().get(APP_URL); Context.getDriver().get(APP_URL);
MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class); MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class);
try { context.wait(10);
TimeUnit.SECONDS.sleep(10); // Same as Thread.sleep(5000);
// The "main" thread will sleep
} catch (InterruptedException e) {
}
page.clicklastMessageLink(); page.clicklastMessageLink();
try { context.wait(5);
TimeUnit.SECONDS.sleep(5); // Same as Thread.sleep(5000);
// The "main" thread will sleep
} catch (InterruptedException e) {
}
Assertions.assertTrue(MainPage.islastMessageLinkPresent()); Assertions.assertTrue(MainPage.islastMessageLinkPresent());
@ -138,23 +98,11 @@ public class NavigationTests
Context.getDriver().get(APP_URL); Context.getDriver().get(APP_URL);
MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class); MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class);
try { context.wait(10);
TimeUnit.SECONDS.sleep(10); // Same as Thread.sleep(5000);
// The "main" thread will sleep
} catch (InterruptedException e) {
}
page.clickSideMenuLink(); page.clickSideMenuLink();
try { context.wait(5);
TimeUnit.SECONDS.sleep(5); // Same as Thread.sleep(5000);
// The "main" thread will sleep
} catch (InterruptedException e) {
}
page.clickSideMenuSubLink(); page.clickSideMenuSubLink();
try { context.wait(5);
TimeUnit.SECONDS.sleep(5); // Same as Thread.sleep(5000);
// The "main" thread will sleep
} catch (InterruptedException e) {
}
Assertions.assertTrue(MainPage.isSideMenuLinkPresent()); Assertions.assertTrue(MainPage.isSideMenuLinkPresent());

View File

@ -34,6 +34,13 @@ public abstract class Context {
driver.quit(); driver.quit();
} }
public void wait(int sec) {
try {
TimeUnit.SECONDS.sleep(sec);
} catch (InterruptedException e) {
}
}
public void switchTab(int tabNum) { driver.switchTo().window(new ArrayList<String>(driver.getWindowHandles()).get(tabNum).toString()); } public void switchTab(int tabNum) { driver.switchTo().window(new ArrayList<String>(driver.getWindowHandles()).get(tabNum).toString()); }
protected abstract void createDriver(); protected abstract void createDriver();

View File

@ -42,6 +42,16 @@ public class GamePage
} }
} }
public static boolean isPicturePresent() {
try {
return driver.findElement(By.xpath("//html/body/div[@class='content_main']/div[@class='main_center_col blocks']")).getAttribute("innerHTML").indexOf("<img src=\"http://paypic.kz/allimage/") >= 0;
}
catch (Exception e)
{
return false;
}
}
} }

View File

@ -33,6 +33,9 @@ public class MainPage {
@FindBy(xpath = "//html/body/div[@class='content_main']/div[@class='main_left_col blocks']/div[@id='firstpane'][2]/div[@class='menu_body'][3]/a[2]") @FindBy(xpath = "//html/body/div[@class='content_main']/div[@class='main_left_col blocks']/div[@id='firstpane'][2]/div[@class='menu_body'][3]/a[2]")
private WebElement sideMenuSubLink; private WebElement sideMenuSubLink;
@FindBy(id = "story")
private WebElement searchField;
public MainPage(WebDriver driver) { public MainPage(WebDriver driver) {
this.driver = driver; this.driver = driver;
} }
@ -49,6 +52,7 @@ public class MainPage {
public void clicklastMessageLink() { lastMessageLink.click(); } public void clicklastMessageLink() { lastMessageLink.click(); }
public void clickSideMenuLink() { sideMenuLink.click(); } public void clickSideMenuLink() { sideMenuLink.click(); }
public void clickSideMenuSubLink() { sideMenuSubLink.click(); } public void clickSideMenuSubLink() { sideMenuSubLink.click(); }
public void search(String word) {searchField.sendKeys(word + "\n");}
public static boolean isRulesPresent() { public static boolean isRulesPresent() {
try { try {
@ -116,4 +120,16 @@ public class MainPage {
} }
} }
public static boolean isSearchResultsPresent() {
try {
return driver.findElement(By.xpath("//html/body/div[@class='content_main']/div[@class='main_center_col blocks']/div[@id='dle-content']/div[@class='dpad radial infoblock']")).getAttribute("innerHTML").indexOf("value=\"Начать поиск\"") >= 0;
}
catch (Exception e)
{
return false;
}
}
} }