lundi 23 décembre 2019

How to write this LOGIN test case in selenium [JAVA]

The flow is as follows.

if success login --> go to main page --> next user login in array(e-mail datas) if fail login --> open error-pop-up ---> clear input ---> next user in array(e-mail datas)

JavaAndExcelRead is good working. This class has excel data. There are current and invalid users in excel file. Element is pop-up ok. PROBLEM -----> TASK= If element not be have do this if element be have do this. I can't do this task.

ERROR

Exception in thread "main" org.openqa.selenium.TimeoutException: Expected condition failed: waiting for element to be clickable: By.xpath: //body[@class='app-body swal2-shown swal2-height-auto']//div[@class='swal2-container swal2-center swal2-fade swal2-shown'][@style='overflow-y: auto;']//button[@type='button'][@class='swal2-confirm swal2-styled'][@aria-label=''][@style='border-left-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0);'] (tried for 10 second(s) with 500 MILLISECONDS interval)
    at org.openqa.selenium.support.ui.WebDriverWait.timeoutException(WebDriverWait.java:82)
    at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:231)
    at sampleTEST.PRP_Action_YEDEK.sirayla_login_en(PRP_Action_YEDEK.java:52)
    at sampleTEST.prp2passo.main(prp2passo.java:17)
Caused by: org.openqa.selenium.NoSuchElementException: Cannot locate an element using By.xpath: //body[@class='app-body swal2-shown swal2-height-auto']//div[@class='swal2-container swal2-center swal2-fade swal2-shown'][@style='overflow-y: auto;']//button[@type='button'][@class='swal2-confirm swal2-styled'][@aria-label=''][@style='border-left-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0);']
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '3.9.0', revision: '698b3178f0', time: '2018-02-05T14:56:13.134Z'
System info: host: 'STJ8CG445050D', ip: '10.134.12.149', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_231'
Driver info: driver.version: unknown
    at org.openqa.selenium.support.ui.ExpectedConditions.lambda$findElement$0(ExpectedConditions.java:896)
    at java.util.Optional.orElseThrow(Optional.java:290)
    at org.openqa.selenium.support.ui.ExpectedConditions.findElement(ExpectedConditions.java:895)
    at org.openqa.selenium.support.ui.ExpectedConditions.access$000(ExpectedConditions.java:44)
    at org.openqa.selenium.support.ui.ExpectedConditions$7.apply(ExpectedConditions.java:206)
    at org.openqa.selenium.support.ui.ExpectedConditions$7.apply(ExpectedConditions.java:202)
    at org.openqa.selenium.support.ui.ExpectedConditions$22.apply(ExpectedConditions.java:657)
    at org.openqa.selenium.support.ui.ExpectedConditions$22.apply(ExpectedConditions.java:654)
    at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:208)
    ... 2 more

CODE

void login_en() throws Exception
    {               
        JavaAndExcelRead obj2 = new JavaAndExcelRead();
        String[] mail = obj2.read_column(4);

        for(int i=0;i<10;i++) {

        Thread.sleep(3000);

        wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("a[href*='login']")));
        WebElement temp01 = driver.findElement(By.cssSelector("a[href*='/en/login']"));
        temp01.click();

        wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//input[@placeholder='E-Mail Address']")));
        WebElement temp02 = driver.findElement(By.xpath("//input[@placeholder='E-Mail Address']"));
        temp02.sendKeys(mail[i]);

        wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//input[@placeholder='Password']")));
        WebElement temp03 = driver.findElement(By.xpath("//input[@placeholder='Password']"));
        temp03.sendKeys("123456");

        wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//button[@class='black-btn']")));  //giriş yapıldı
        WebElement temp04 = driver.findElement(By.xpath("//button[@class='black-btn']"));
        temp04.click();

        //driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);     


        if(wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//body[@class='app-body swal2-shown swal2-height-auto']//div[@class='swal2-container swal2-center swal2-fade swal2-shown'][@style='overflow-y: auto;']//button[@type='button'][@class='swal2-confirm swal2-styled'][@aria-label=''][@style='border-left-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0);']")))==null) 
        {           
            Thread.sleep(1000);

            WebElement x = driver.findElement(By.xpath("//div[@_ngcontent-c3=''][@class='image-nav']//nav[@_ngcontent-c3=''][@class='navbar  layout-wrapper navbar-expand-lg  navbar-light']//div[@_ngcontent-c3='']['@class='collapse navbar-collapse flex-lg-wrap font-weight-bold text-primary text-nowrap text-uppercase'][@id='navbar-content']//div[@_ngcontent-c3='']//div[@_ngcontent-c3=''][@class='float-lg-right']//ul[@_ngcontent-c3=''][@class='navbar-nav mr-auto d-inline d-lg-flex ']//li[@_ngcontent-c3=''][@class='nav-item py-1  float-left float-lg-none']//a[@_ngcontent-c3=''][@class='nav-link ml-2 ml-lg-0 text-white']//u[@_ngcontent-c3=''][text()='Logout']"));
            x.click();

        }
        else {
            Thread.sleep(2000);

            WebElement temp444 = driver.findElement(By.xpath("//body[@class='app-body swal2-shown swal2-height-auto']//div[@class='swal2-container swal2-center swal2-fade swal2-shown'][@style='overflow-y: auto;']//button[@type='button'][@class='styled'][@aria-label=''][@style='border-left-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0);']"));
            temp444.click();    

            Thread.sleep(2000);

            wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//input[@placeholder='E-Mail Address']")));
            WebElement tempx = driver.findElement(By.xpath("//input[@placeholder='E-Mail Address']"));  
            tempx.clear();

            Thread.sleep(2000);

            wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//input[@placeholder='Password']"))); 

            WebElement tempy = driver.findElement(By.xpath("//input[@placeholder='Password']"));
            tempy.clear();

        Thread.sleep(2000);
        }




        }

    }

Aucun commentaire:

Enregistrer un commentaire