Blogs

Selenium Open House II CP-SAT was successfully conduted 3rd October 2020..

After looking at enthusiasm towards Selenium Open House I CP-SAT session which was scheduled on 24th September 2020, ATA conducted Selenium Open House II CP-SAT on 3rd October 2020.

Here is the video from the session:

Below is the slide deck for the same

Code base for all the technology is shared below.

LoginLogout.java Code


import org.openqa.selenium.*;
import org.openqa.selenium.chrome.*;
import org.junit.*;


public class LoginLogout {
	
	WebDriver driver;
	
	@Before
	public void setup() throws Exception{
		System.setProperty("webdriver.chrome.driver","drivers\\chromedriver.exe");//set the chrome driver
		driver=new ChromeDriver();
	}
	
	@Test
	public void loginLogout() throws Exception{
		driver.get("http://5elementslearning.dev/demosite"); //open the application
		driver.findElement(By.linkText("My Account")).click();
		driver.findElement(By.name("email_address")).sendKeys("abc@demo.com");
		driver.findElement(By.name("password")).sendKeys("demo@123");
		driver.findElement(By.id("tdb5")).click();
		driver.findElement(By.linkText("Log Off")).click();
		driver.findElement(By.linkText("Continue")).click();
	}
	
	@After
	public void cleanup() throws Exception{
		driver.close();//close the browser
	}
	

}

LoginLogout.py Code

# -*- coding: utf-8 -*-
from selenium import webdriver
import unittest

class Login(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Chrome(executable_path=r'D:\Eclipse\TechnologyAgnosticSelenium\SeleniumWithPython\drivers\chromedriver.exe')
        self.driver.implicitly_wait(30) #Introducing Implict Wait
        self.base_url = "http://5elementslearning.dev/"
        
    def test_login(self):
        driver = self.driver
        driver.get(self.base_url + "/demosite/")
        driver.find_element_by_link_text("My Account").click()
        driver.find_element_by_name("email_address").clear()
        driver.find_element_by_name("email_address").send_keys("abc@demo.com")
        driver.find_element_by_name("password").clear()
        driver.find_element_by_name("password").send_keys("demo@123")
        driver.find_element_by_id("tdb5").click()
        if(driver.page_source.find("My Account Information")!=-1):
            
           
            
                driver.find_element_by_link_text("Log Off").click()
                driver.find_element_by_link_text("Continue").click()
                print("valid user credential")
                self.assertTrue(True,"valid user credential")
        else:
            #print("bad user credential")
            self.assertFalse(True,"bad user credential")
    
    def tearDown(self):
        self.driver.close()
        
if __name__ == "__main__":
    unittest.main()

LoginLogout.rb Code

require "selenium-webdriver"
require "test/unit"

class ExampleTest < Test::Unit::TestCase
    def setup
      Selenium::WebDriver::Chrome::Service.driver_path="D:\\Eclipse\\TechnologyAgnosticSelenium\\SeleniumWithRuby\\drivers\\chromedriver.exe"
      @driver = Selenium::WebDriver.for :chrome
    end
    


  def test_login
    @driver.navigate.to "http://www.5elementslearning.dev/demosite"
    @driver.find_element(:link, "My Account").click()
    @driver.find_element(:name, "email_address").send_keys("abc@demo.com")
    @driver.find_element(:name, "password").send_keys("demo@123")
    @driver.find_element(:id, "tdb5").click()
    puts "Test Passed: Found log off link" if wait.until {
        browser.find_element(:link, "Log Off").displayed?
    }
    @driver.find_element(:link, "Log Off").click()
    @driver.find_element(:link, "Continue").click()
  end

  def teardown
          @driver.quit
      end

end

LoginLogoutWithAssertion.cs Code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;

namespace ProjectSelenium5ElementsLearning.SeleniumPrograms.Day_7
{
    class LoginLogoutWithAssertion
    {
        static void Main(String[] args)
        {
            IWebDriver driver = new ChromeDriver();
            driver.Url = "http://www.5elementslearning.dev/demosite";
            driver.FindElement(By.LinkText("My Account")).Click();
            driver.FindElement(By.Name("email_address")).SendKeys("abc@demo.com");
            driver.FindElement(By.Name("password")).SendKeys("demo@123");
            driver.FindElement(By.Id("tdb5")).Click();
            //Text Assertion
            if (driver.PageSource.Contains("My Account Information"))
            {
                //Object Information
                if (driver.FindElement(By.LinkText("Log Off")).Displayed)
                {
                    driver.FindElement(By.LinkText("Log Off")).Click();
                    driver.FindElement(By.LinkText("Continue")).Click();
                }
            }
            else
            {
                Console.WriteLine("Bad credentials");
            }
            driver.Close();
        }
    }
}

The session ended on time, followed by question/answer session.

Here is the blog for Selenium Open House I CP-SAT:
https://cpsat.agiletestingalliance.org/2020/09/28/selenium-open-house-was-successfully-held-on-24th-of-september-2020/

CP-SAT Java program is happening from 9th of October 2020. Please visit ATAEvents.

Leave a Comment